fix error hooks and add listing everything
ci/woodpecker/push/go-lint Pipeline failed
ci/woodpecker/push/publish-docs Pipeline failed

This commit is contained in:
2026-08-15 00:16:05 -05:00
parent 62ac2934dc
commit e789924547
16 changed files with 211 additions and 137 deletions
+42 -28
View File
@@ -5,8 +5,10 @@
package cmd
import (
"fmt"
"os"
"git.andrewnw.xyz/CyberShell/backy/pkg/backy"
"git.andrewnw.xyz/CyberShell/backy/pkg/logging"
"github.com/spf13/cobra"
)
@@ -15,28 +17,26 @@ var (
listCmd = &cobra.Command{
Use: "list [command]",
Short: "List commands, lists, or hosts defined in config file.",
Long: "List commands, lists, or hosts defined in config file",
Long: "List commands, lists, or hosts defined in config file. The subcommands take zero or more arguments to print specific commands or lists",
}
listCmds = &cobra.Command{
Use: "cmds [cmd1 cmd2 cmd3...]",
Short: "List commands defined in config file.",
Long: "List commands defined in config file",
Short: "Prints commands defined in config file.",
Long: "Prints commands defined in config file. Pass no arguments to print all commands",
Run: ListCommands,
}
listCmdLists = &cobra.Command{
Use: "lists [list1 list2 ...]",
Short: "List lists defined in config file.",
Long: "List lists defined in config file",
Short: "Prints lists defined in config file.",
Long: "Prints lists defined in config file. Pass no arguments to print all lists",
Run: ListCommandLists,
}
)
var listsToList []string
var cmdsToList []string
func init() {
listCmd.AddCommand(listCmds, listCmdLists)
parseS3Config()
}
@@ -46,13 +46,6 @@ func ListCommands(cmd *cobra.Command, args []string) {
// - cmds
// - lists
// - if none, list all commands
if len(args) > 0 {
cmdsToList = args
} else {
logging.ExitWithMSG("Error: list cmds subcommand needs commands to list", 1, nil)
}
parseS3Config()
opts := backy.NewConfigOptions(configFile,
backy.SetLogFile(logFile),
@@ -61,21 +54,28 @@ func ListCommands(cmd *cobra.Command, args []string) {
opts.InitConfig()
opts.ParseConfigurationFile()
for _, v := range cmdsToList {
opts.ListCommand(v)
if len(args) > 0 {
for _, v := range args {
opts.ListCommand(v)
}
os.Exit(0)
}
if len(opts.Cmds) == 0 {
fmt.Println("No commands defined in config file")
os.Exit(1)
}
for c := range opts.Cmds {
println()
println()
println("---------------------------------------------------------------------------------")
opts.ListCommand(c)
}
}
func ListCommandLists(cmd *cobra.Command, args []string) {
parseS3Config()
if len(args) > 0 {
listsToList = args
} else {
logging.ExitWithMSG("Error: lists subcommand needs lists", 1, nil)
}
opts := backy.NewConfigOptions(configFile,
backy.SetLogFile(logFile),
backy.SetHostsConfigFile(hostsConfigFile))
@@ -83,8 +83,22 @@ func ListCommandLists(cmd *cobra.Command, args []string) {
opts.InitConfig()
opts.ParseConfigurationFile()
for _, v := range listsToList {
opts.ListCommandList(v)
if len(args) > 0 {
for _, v := range args {
opts.ListCommandList(v)
}
os.Exit(0)
}
if len(opts.CmdConfigLists) == 0 {
fmt.Println("No command lists defined in config file")
os.Exit(1)
}
for c := range opts.CmdConfigLists {
println()
println()
println("---------------------------------------------------------------------------------")
opts.ListCommandList(c)
}
}