2023-09-16 15:25:25 +00:00
|
|
|
//
|
|
|
|
// Copyright ⓒ 2023 Chakib Ben Ziane <contact@blob42.xyz> and [`GoSuki` contributors]
|
|
|
|
// (https://github.com/blob42/gosuki/graphs/contributors).
|
|
|
|
//
|
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
//
|
|
|
|
// This file is part of GoSuki.
|
|
|
|
//
|
|
|
|
// GoSuki is free software: you can redistribute it and/or modify it under the terms of
|
|
|
|
// the GNU Affero General Public License as published by the Free Software Foundation,
|
|
|
|
// either version 3 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// GoSuki is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
// PURPOSE. See the GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License along with
|
|
|
|
// gosuki. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2023-09-05 19:35:04 +00:00
|
|
|
// commands related to modules
|
2022-10-23 13:08:06 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2023-09-05 19:35:04 +00:00
|
|
|
"fmt"
|
|
|
|
|
2022-10-23 13:08:06 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
2023-09-05 19:35:04 +00:00
|
|
|
|
2023-09-16 19:41:33 +00:00
|
|
|
"git.blob42.xyz/gosuki/gosuki/pkg/modules"
|
2022-10-23 13:08:06 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// map cmd Name to *cli.Command
|
|
|
|
type modCmds map[string]*cli.Command
|
|
|
|
|
|
|
|
var (
|
2023-09-05 19:35:04 +00:00
|
|
|
// Map registered browser module IDs to their modCmds map
|
2022-10-23 13:08:06 +00:00
|
|
|
modCommands = map[string]modCmds{}
|
|
|
|
)
|
|
|
|
|
|
|
|
// TODO: use same logic with browser mod registering
|
2023-09-05 19:35:04 +00:00
|
|
|
func RegisterModCommand(modID string, cmd *cli.Command) {
|
2022-10-23 13:08:06 +00:00
|
|
|
if cmd == nil {
|
2023-09-05 19:35:04 +00:00
|
|
|
log.Panicf("cannot register nil cmd for <%s>", modID)
|
2022-10-23 13:08:06 +00:00
|
|
|
}
|
|
|
|
|
2023-09-05 19:35:04 +00:00
|
|
|
if _, ok := modCommands[modID]; !ok {
|
|
|
|
modCommands[modID] = make(modCmds)
|
2022-10-23 13:08:06 +00:00
|
|
|
}
|
2023-09-05 19:35:04 +00:00
|
|
|
modCommands[modID][cmd.Name] = cmd
|
2022-10-23 13:08:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// return list of registered commands for browser module
|
2023-09-05 19:35:04 +00:00
|
|
|
func RegisteredModCommands(modID string) modCmds {
|
|
|
|
return modCommands[modID]
|
|
|
|
}
|
|
|
|
|
|
|
|
var ModuleCmds = &cli.Command {
|
|
|
|
Name: "modules",
|
|
|
|
Aliases: []string{"m"},
|
|
|
|
Usage: "module commands",
|
|
|
|
Subcommands: []*cli.Command{
|
|
|
|
listModulesCmd,
|
|
|
|
},
|
2022-10-23 13:08:06 +00:00
|
|
|
}
|
2023-09-05 19:35:04 +00:00
|
|
|
|
|
|
|
var listModulesCmd = &cli.Command{
|
|
|
|
Name: "list",
|
2023-09-25 20:03:31 +00:00
|
|
|
Aliases: []string{"l"},
|
2023-09-05 19:35:04 +00:00
|
|
|
Usage: "list available browsers and modules",
|
|
|
|
Action: func(_ *cli.Context) error {
|
|
|
|
|
|
|
|
fmt.Printf("\n%s\n", "Modules:")
|
|
|
|
mods := modules.GetModules()
|
|
|
|
for _, mod := range mods {
|
|
|
|
_, isBrowser := mod.(modules.BrowserModule)
|
|
|
|
if isBrowser {
|
|
|
|
fmt.Printf("-%-10s \t %s\n", mod.ModInfo().ID, "<browser>")
|
|
|
|
} else {
|
|
|
|
fmt.Printf("-%-10s \t %s\n", mod.ModInfo().ID, "<module>")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|