diff --git a/internal/app/wwctl/power/cycle/root.go b/internal/app/wwctl/power/cycle/root.go index 8b450b8c..45b07340 100644 --- a/internal/app/wwctl/power/cycle/root.go +++ b/internal/app/wwctl/power/cycle/root.go @@ -2,7 +2,7 @@ package cycle import ( "github.com/spf13/cobra" - "github.com/warewulf/warewulf/internal/pkg/node" + "github.com/warewulf/warewulf/internal/app/wwctl/completions" ) type variables struct { @@ -19,19 +19,8 @@ func GetCommand() *cobra.Command { Short: "Power cycle the given node(s)", Long: "This command cycles power for a set of nodes specified by PATTERN.", RunE: CobraRunE(&vars), - ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - if len(args) != 0 { - return nil, cobra.ShellCompDirectiveNoFileComp - } - - nodeDB, _ := node.New() - nodes, _ := nodeDB.FindAllNodes() - var node_names []string - for _, node := range nodes { - node_names = append(node_names, node.Id()) - } - return node_names, cobra.ShellCompDirectiveNoFileComp - }, + Args: cobra.MinimumNArgs(1), + ValidArgsFunction: completions.Nodes(0), // no limit } powerCmd.PersistentFlags().BoolVarP(&vars.Showcmd, "show", "s", false, "only show command which will be executed") powerCmd.PersistentFlags().IntVar(&vars.Fanout, "fanout", 50, "how many command should be executed in parallel") diff --git a/internal/app/wwctl/power/off/root.go b/internal/app/wwctl/power/off/root.go index 43670e29..eba9fdcd 100644 --- a/internal/app/wwctl/power/off/root.go +++ b/internal/app/wwctl/power/off/root.go @@ -2,7 +2,7 @@ package off import ( "github.com/spf13/cobra" - "github.com/warewulf/warewulf/internal/pkg/node" + "github.com/warewulf/warewulf/internal/app/wwctl/completions" ) type variables struct { @@ -19,19 +19,8 @@ func GetCommand() *cobra.Command { Short: "Power off the given node(s)", Long: "This command will shutdown power to a set of nodes specified by PATTERN.", RunE: CobraRunE(&vars), - ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - if len(args) != 0 { - return nil, cobra.ShellCompDirectiveNoFileComp - } - - nodeDB, _ := node.New() - nodes, _ := nodeDB.FindAllNodes() - var node_names []string - for _, node := range nodes { - node_names = append(node_names, node.Id()) - } - return node_names, cobra.ShellCompDirectiveNoFileComp - }, + Args: cobra.MinimumNArgs(1), + ValidArgsFunction: completions.Nodes(0), // no limit, } powerCmd.PersistentFlags().BoolVarP(&vars.Showcmd, "show", "s", false, "only show command which will be executed") powerCmd.PersistentFlags().IntVar(&vars.Fanout, "fanout", 50, "how many command should be executed in parallel") diff --git a/internal/app/wwctl/power/on/root.go b/internal/app/wwctl/power/on/root.go index f5841222..0be289be 100644 --- a/internal/app/wwctl/power/on/root.go +++ b/internal/app/wwctl/power/on/root.go @@ -2,7 +2,7 @@ package on import ( "github.com/spf13/cobra" - "github.com/warewulf/warewulf/internal/pkg/node" + "github.com/warewulf/warewulf/internal/app/wwctl/completions" ) type variables struct { @@ -14,23 +14,12 @@ type variables struct { func GetCommand() *cobra.Command { vars := variables{} powerCmd := &cobra.Command{ - Use: "on [OPTIONS] [PATTERN ...]", - Short: "Power on the given node(s)", - Long: "This command will power on a set of nodes specified by PATTERN.", - RunE: CobraRunE(&vars), - ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - if len(args) != 0 { - return nil, cobra.ShellCompDirectiveNoFileComp - } - - nodeDB, _ := node.New() - nodes, _ := nodeDB.FindAllNodes() - var node_names []string - for _, node := range nodes { - node_names = append(node_names, node.Id()) - } - return node_names, cobra.ShellCompDirectiveNoFileComp - }, + Use: "on [OPTIONS] [PATTERN ...]", + Short: "Power on the given node(s)", + Long: "This command will power on a set of nodes specified by PATTERN.", + RunE: CobraRunE(&vars), + Args: cobra.MinimumNArgs(1), + ValidArgsFunction: completions.Nodes(0), // no limit, } powerCmd.PersistentFlags().BoolVarP(&vars.Showcmd, "show", "s", false, "only show command which will be executed") powerCmd.PersistentFlags().IntVar(&vars.Fanout, "fanout", 50, "how many command should be executed in parallel") diff --git a/internal/app/wwctl/power/reset/root.go b/internal/app/wwctl/power/reset/root.go index c7346135..a2ef35b0 100644 --- a/internal/app/wwctl/power/reset/root.go +++ b/internal/app/wwctl/power/reset/root.go @@ -2,7 +2,7 @@ package reset import ( "github.com/spf13/cobra" - "github.com/warewulf/warewulf/internal/pkg/node" + "github.com/warewulf/warewulf/internal/app/wwctl/completions" ) type variables struct { @@ -19,19 +19,8 @@ func GetCommand() *cobra.Command { Short: "Issue a reset to node(s)", Long: "This command will issue a reset to a set of nodes specified by PATTERN.", RunE: CobraRunE(&vars), - ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - if len(args) != 0 { - return nil, cobra.ShellCompDirectiveNoFileComp - } - - nodeDB, _ := node.New() - nodes, _ := nodeDB.FindAllNodes() - var node_names []string - for _, node := range nodes { - node_names = append(node_names, node.Id()) - } - return node_names, cobra.ShellCompDirectiveNoFileComp - }, + Args: cobra.MinimumNArgs(1), + ValidArgsFunction: completions.Nodes(0), // no limit, } powerCmd.PersistentFlags().BoolVarP(&vars.Showcmd, "show", "s", false, "only show command which will be executed") powerCmd.PersistentFlags().IntVar(&vars.Fanout, "fanout", 50, "how many command should be executed in parallel") diff --git a/internal/app/wwctl/power/soft/root.go b/internal/app/wwctl/power/soft/root.go index 10093211..30f21a05 100644 --- a/internal/app/wwctl/power/soft/root.go +++ b/internal/app/wwctl/power/soft/root.go @@ -2,7 +2,7 @@ package soft import ( "github.com/spf13/cobra" - "github.com/warewulf/warewulf/internal/pkg/node" + "github.com/warewulf/warewulf/internal/app/wwctl/completions" ) type variables struct { @@ -19,19 +19,8 @@ func GetCommand() *cobra.Command { Short: "Gracefully shuts down the given node(s)", Long: "This command uses the operating system to shut down the set of nodes specified by PATTERN.", RunE: CobraRunE(&vars), - ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - if len(args) != 0 { - return nil, cobra.ShellCompDirectiveNoFileComp - } - - nodeDB, _ := node.New() - nodes, _ := nodeDB.FindAllNodes() - var node_names []string - for _, node := range nodes { - node_names = append(node_names, node.Id()) - } - return node_names, cobra.ShellCompDirectiveNoFileComp - }, + Args: cobra.MinimumNArgs(1), + ValidArgsFunction: completions.Nodes(0), // no limit, } powerCmd.PersistentFlags().BoolVarP(&vars.Showcmd, "show", "s", false, "only show command which will be executed") powerCmd.PersistentFlags().IntVar(&vars.Fanout, "fanout", 50, "how many command should be executed in parallel") diff --git a/internal/app/wwctl/power/status/root.go b/internal/app/wwctl/power/status/root.go index 1176792d..84b7d765 100644 --- a/internal/app/wwctl/power/status/root.go +++ b/internal/app/wwctl/power/status/root.go @@ -2,7 +2,7 @@ package status import ( "github.com/spf13/cobra" - "github.com/warewulf/warewulf/internal/pkg/node" + "github.com/warewulf/warewulf/internal/app/wwctl/completions" ) type variables struct { @@ -19,19 +19,8 @@ func GetCommand() *cobra.Command { Short: "Show power status for the given node(s)", Long: "This command displays the power status of a set of nodes specified by PATTERN.", RunE: CobraRunE(&vars), - ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - if len(args) != 0 { - return nil, cobra.ShellCompDirectiveNoFileComp - } - - nodeDB, _ := node.New() - nodes, _ := nodeDB.FindAllNodes() - var node_names []string - for _, node := range nodes { - node_names = append(node_names, node.Id()) - } - return node_names, cobra.ShellCompDirectiveNoFileComp - }, + Args: cobra.MinimumNArgs(1), + ValidArgsFunction: completions.Nodes(0), // no limit, } powerCmd.PersistentFlags().BoolVarP(&vars.Showcmd, "show", "s", false, "only show command which will be executed") powerCmd.PersistentFlags().IntVar(&vars.Fanout, "fanout", 50, "how many command should be executed in parallel")