fix error hooks and add listing everything
This commit is contained in:
+1
-1
@@ -9,7 +9,7 @@ import (
|
||||
var (
|
||||
hostExecCommand = &cobra.Command{
|
||||
Use: "host [--command=command1 --command=command2 ... | -c command1 -c command2 ...] [--hosts=host1 --hosts=hosts2 ... | -m host1 -m host2 ...] ",
|
||||
Short: "Runs command defined in config file on the hosts in order specified.",
|
||||
Short: "Specify command(s) defined in config file on the host in order specified.",
|
||||
Long: "Host executes specified commands on the hosts defined in config file.\nUse the --commands or -c flag to choose the commands.",
|
||||
Run: Host,
|
||||
}
|
||||
|
||||
+42
-28
@@ -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)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user