backy/cmd/list.go

87 lines
1.7 KiB
Go
Raw Normal View History

2023-09-08 23:42:13 -05:00
// backup.go
// Copyright (C) Andrew Woodlee 2023
// License: Apache-2.0
package cmd
import (
"git.andrewnw.xyz/CyberShell/backy/pkg/backy"
2025-02-20 14:53:44 -06:00
"git.andrewnw.xyz/CyberShell/backy/pkg/logging"
2023-09-08 23:42:13 -05:00
"github.com/spf13/cobra"
)
var (
listCmd = &cobra.Command{
2025-02-20 14:53:44 -06:00
Use: "list [command]",
2025-02-23 15:33:17 -06:00
Short: "List commands, lists, or hosts defined in config file.",
Long: "List commands, lists, or hosts defined in config file",
2025-02-20 14:53:44 -06:00
}
listCmds = &cobra.Command{
Use: "cmds [cmd1 cmd2 cmd3...]",
2025-02-23 15:33:17 -06:00
Short: "List commands defined in config file.",
Long: "List commands defined in config file",
2025-02-20 14:53:44 -06:00
Run: ListCmds,
}
listCmdLists = &cobra.Command{
Use: "lists [list1 list2 ...]",
2025-02-23 15:33:17 -06:00
Short: "List lists defined in config file.",
Long: "List lists defined in config file",
2025-02-20 14:53:44 -06:00
Run: ListCmdLists,
2023-09-08 23:42:13 -05:00
}
)
var listsToList []string
var cmdsToList []string
2023-09-08 23:42:13 -05:00
func init() {
2025-02-20 14:53:44 -06:00
listCmd.AddCommand(listCmds, listCmdLists)
2023-09-08 23:42:13 -05:00
}
2025-02-20 14:53:44 -06:00
func ListCmds(cmd *cobra.Command, args []string) {
2023-09-08 23:42:13 -05:00
2025-01-14 09:42:43 -06:00
// setup based on whats passed in:
// - cmds
// - lists
// - if none, list all commands
2025-02-20 14:53:44 -06:00
if len(args) > 0 {
cmdsToList = args
} else {
logging.ExitWithMSG("Error: list cmds subcommand needs commands to list", 1, nil)
}
parseS3Config()
2025-02-20 14:53:44 -06:00
opts := backy.NewOpts(cfgFile, backy.SetLogFile(logFile))
opts.InitConfig()
opts.ReadConfig()
for _, v := range cmdsToList {
opts.ListCommand(v)
}
2025-02-20 14:53:44 -06:00
}
func ListCmdLists(cmd *cobra.Command, args []string) {
2025-02-08 15:17:34 -06:00
parseS3Config()
2025-02-20 14:53:44 -06:00
if len(args) > 0 {
listsToList = args
} else {
logging.ExitWithMSG("Error: lists subcommand needs lists", 1, nil)
}
opts := backy.NewOpts(cfgFile, backy.SetLogFile(logFile))
2023-09-08 23:42:13 -05:00
opts.InitConfig()
2025-01-14 09:42:43 -06:00
opts.ReadConfig()
2023-09-08 23:42:13 -05:00
2025-02-20 14:53:44 -06:00
for _, v := range listsToList {
opts.ListCommandList(v)
}
2023-09-08 23:42:13 -05:00
}