diff --git a/internal/app/wwctl/completions/completions.go b/internal/app/wwctl/completions/completions.go index dc27e81b..5ebb3ca7 100644 --- a/internal/app/wwctl/completions/completions.go +++ b/internal/app/wwctl/completions/completions.go @@ -51,37 +51,25 @@ func ProfileKernelVersion(cmd *cobra.Command, args []string, toComplete string) return kernelVersions, cobra.ShellCompDirectiveNoFileComp } -func Images(num int) func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - if num <= 0 || len(args) < num { - if sources, err := image.ListSources(); err != nil { - return sources, cobra.ShellCompDirectiveNoFileComp - } - } - return nil, cobra.ShellCompDirectiveNoFileComp +func Images(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + if sources, err := image.ListSources(); err != nil { + return sources, cobra.ShellCompDirectiveNoFileComp } + return nil, cobra.ShellCompDirectiveNoFileComp } -func Nodes(num int) func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - if num <= 0 || len(args) < num { - if registry, err := node.New(); err == nil { - return registry.ListAllNodes(), cobra.ShellCompDirectiveNoFileComp - } - } - return nil, cobra.ShellCompDirectiveNoFileComp +func Nodes(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + if registry, err := node.New(); err == nil { + return registry.ListAllNodes(), cobra.ShellCompDirectiveNoFileComp } + return nil, cobra.ShellCompDirectiveNoFileComp } -func Profiles(num int) func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - if num <= 0 || len(args) < num { - if registry, err := node.New(); err == nil { - return registry.ListAllProfiles(), cobra.ShellCompDirectiveNoFileComp - } - } - return nil, cobra.ShellCompDirectiveNoFileComp +func Profiles(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + if registry, err := node.New(); err == nil { + return registry.ListAllProfiles(), cobra.ShellCompDirectiveNoFileComp } + return nil, cobra.ShellCompDirectiveNoFileComp } func Overlays(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { diff --git a/internal/app/wwctl/image/kernels/root.go b/internal/app/wwctl/image/kernels/root.go index 9d191918..834c66a3 100644 --- a/internal/app/wwctl/image/kernels/root.go +++ b/internal/app/wwctl/image/kernels/root.go @@ -14,7 +14,7 @@ var ( Long: "This command lists the kernels that are available in the imported images.", RunE: CobraRunE, Aliases: []string{"kernel"}, - ValidArgsFunction: completions.Images(0), // no limit + ValidArgsFunction: completions.Images, } ) diff --git a/internal/app/wwctl/image/list/root.go b/internal/app/wwctl/image/list/root.go index 615f140d..6e5c5aea 100644 --- a/internal/app/wwctl/image/list/root.go +++ b/internal/app/wwctl/image/list/root.go @@ -23,7 +23,7 @@ func GetCommand() *cobra.Command { Long: "This command will show you the images that are imported into Warewulf.", RunE: CobraRunE(&vars), Aliases: []string{"ls"}, - ValidArgsFunction: completions.Images(0), // no limit + ValidArgsFunction: completions.Images, } baseCmd.PersistentFlags().BoolVarP(&vars.full, "long", "l", false, "show all") baseCmd.PersistentFlags().BoolVarP(&vars.kernel, "kernel", "k", false, "show kernel version") diff --git a/internal/app/wwctl/image/rename/root.go b/internal/app/wwctl/image/rename/root.go index 1a09aba7..5364be13 100644 --- a/internal/app/wwctl/image/rename/root.go +++ b/internal/app/wwctl/image/rename/root.go @@ -13,7 +13,12 @@ var baseCmd = &cobra.Command{ Long: "This command will rename an existing image.", RunE: CobraRunE, Args: cobra.ExactArgs(2), - ValidArgsFunction: completions.Images(1), + ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + if len(args) == 0 { + return completions.Images(cmd, args, toComplete) + } + return completions.None(cmd, args, toComplete) + }, } var SetBuild bool diff --git a/internal/app/wwctl/image/show/root.go b/internal/app/wwctl/image/show/root.go index 26dfc2f0..f0fad077 100644 --- a/internal/app/wwctl/image/show/root.go +++ b/internal/app/wwctl/image/show/root.go @@ -12,9 +12,14 @@ var ( Short: "Show root fs dir for image", Long: `Shows the base directory for the chroot of the given image. More information about the image can be shown with the '-a' option.`, - RunE: CobraRunE, - ValidArgsFunction: completions.Images(0), // no limit - Args: cobra.ExactArgs(1), + RunE: CobraRunE, + Args: cobra.ExactArgs(1), + ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + if len(args) == 0 { + return completions.Images(cmd, args, toComplete) + } + return completions.None(cmd, args, toComplete) + }, } ShowAll bool ) diff --git a/internal/app/wwctl/node/add/root.go b/internal/app/wwctl/node/add/root.go index 850362a4..681ee1ab 100644 --- a/internal/app/wwctl/node/add/root.go +++ b/internal/app/wwctl/node/add/root.go @@ -31,7 +31,7 @@ func GetCommand() *cobra.Command { vars.nodeAdd.CreateAddFlags(baseCmd) flags.AddContainer(baseCmd, &(vars.nodeConf.Profile.ImageName)) // register the command line completions - if err := baseCmd.RegisterFlagCompletionFunc("image", completions.Images(0)); err != nil { // no limit + if err := baseCmd.RegisterFlagCompletionFunc("image", completions.Images); err != nil { // no limit panic(err) } if err := baseCmd.RegisterFlagCompletionFunc("kernelversion", completions.NodeKernelVersion); err != nil { @@ -43,7 +43,7 @@ func GetCommand() *cobra.Command { if err := baseCmd.RegisterFlagCompletionFunc("wwinit", completions.OverlayList); err != nil { panic(err) } - if err := baseCmd.RegisterFlagCompletionFunc("profile", completions.Profiles(0)); err != nil { // no limit + if err := baseCmd.RegisterFlagCompletionFunc("profile", completions.Profiles); err != nil { // no limit panic(err) } diff --git a/internal/app/wwctl/node/console/root.go b/internal/app/wwctl/node/console/root.go index b107864c..87a69144 100644 --- a/internal/app/wwctl/node/console/root.go +++ b/internal/app/wwctl/node/console/root.go @@ -13,7 +13,7 @@ var ( Long: "Start a new IPMI console for NODENAME.", Args: cobra.MinimumNArgs(1), RunE: CobraRunE, - ValidArgsFunction: completions.Nodes(0), // no limit + ValidArgsFunction: completions.Nodes, } ) diff --git a/internal/app/wwctl/node/delete/root.go b/internal/app/wwctl/node/delete/root.go index 0890e626..b30b5d24 100644 --- a/internal/app/wwctl/node/delete/root.go +++ b/internal/app/wwctl/node/delete/root.go @@ -14,7 +14,7 @@ var ( Args: cobra.MinimumNArgs(1), RunE: CobraRunE, Aliases: []string{"rm", "del", "remove"}, - ValidArgsFunction: completions.Nodes(0), // no limit + ValidArgsFunction: completions.Nodes, } SetYes bool SetForce bool // no hash checking, so always using force diff --git a/internal/app/wwctl/node/edit/root.go b/internal/app/wwctl/node/edit/root.go index 6147a274..c095b6b7 100644 --- a/internal/app/wwctl/node/edit/root.go +++ b/internal/app/wwctl/node/edit/root.go @@ -12,7 +12,7 @@ var ( Short: "Edit node(s) with editor", Long: "This command opens an editor for the given nodes.", RunE: CobraRunE, - ValidArgsFunction: completions.Nodes(0), // no limit + ValidArgsFunction: completions.Nodes, } NoHeader bool ) diff --git a/internal/app/wwctl/node/export/root.go b/internal/app/wwctl/node/export/root.go index 97865eb0..c3cccd35 100644 --- a/internal/app/wwctl/node/export/root.go +++ b/internal/app/wwctl/node/export/root.go @@ -12,7 +12,7 @@ var ( Short: "Export nodes as yaml to stdout", Long: "This command exports the given nodes as yaml to stdout.", RunE: CobraRunE, - ValidArgsFunction: completions.Nodes(0), // no limit + ValidArgsFunction: completions.Nodes, } NoHeader bool ) diff --git a/internal/app/wwctl/node/list/root.go b/internal/app/wwctl/node/list/root.go index 9015ea1c..bf8805c4 100644 --- a/internal/app/wwctl/node/list/root.go +++ b/internal/app/wwctl/node/list/root.go @@ -24,7 +24,7 @@ func GetCommand() *cobra.Command { "nodes matching a PATTERN.", RunE: CobraRunE(&vars), Aliases: []string{"ls"}, - ValidArgsFunction: completions.Nodes(0), // no limit + ValidArgsFunction: completions.Nodes, } baseCmd.PersistentFlags().BoolVarP(&vars.showNet, "net", "n", false, "Show node network configurations") baseCmd.PersistentFlags().BoolVarP(&vars.showIpmi, "ipmi", "i", false, "Show node IPMI configurations") diff --git a/internal/app/wwctl/node/sensors/root.go b/internal/app/wwctl/node/sensors/root.go index 9da16769..a75a5aa1 100644 --- a/internal/app/wwctl/node/sensors/root.go +++ b/internal/app/wwctl/node/sensors/root.go @@ -21,7 +21,7 @@ func GetCommand() *cobra.Command { Long: "Show IPMI sensor information for nodes matching PATTERN.", Args: cobra.MinimumNArgs(1), RunE: CobraRunE(&vars), - ValidArgsFunction: completions.Nodes(0), // no limit + ValidArgsFunction: completions.Nodes, } powerCmd.PersistentFlags().BoolVarP(&vars.Full, "full", "F", false, "show detailed output.") powerCmd.PersistentFlags().BoolVarP(&vars.Showcmd, "show", "s", false, "only show command which will be executed") diff --git a/internal/app/wwctl/node/set/root.go b/internal/app/wwctl/node/set/root.go index 68c482d2..b5c3ab14 100644 --- a/internal/app/wwctl/node/set/root.go +++ b/internal/app/wwctl/node/set/root.go @@ -27,7 +27,7 @@ func GetCommand() *cobra.Command { Aliases: []string{"modify"}, Args: cobra.MinimumNArgs(1), // require pattern as a mandatory arg RunE: CobraRunE(&vars), - ValidArgsFunction: completions.Nodes(0), // no limit + ValidArgsFunction: completions.Nodes, } vars.nodeConf.CreateFlags(baseCmd) @@ -38,7 +38,7 @@ func GetCommand() *cobra.Command { baseCmd.PersistentFlags().BoolVarP(&vars.setYes, "yes", "y", false, "Set 'yes' to all questions asked") baseCmd.PersistentFlags().BoolVarP(&vars.setForce, "force", "f", false, "Force configuration (even on error)") // register the command line completions - if err := baseCmd.RegisterFlagCompletionFunc("image", completions.Images(0)); err != nil { // no limit + if err := baseCmd.RegisterFlagCompletionFunc("image", completions.Images); err != nil { // no limit panic(err) } if err := baseCmd.RegisterFlagCompletionFunc("kernelversion", completions.NodeKernelVersion); err != nil { @@ -50,7 +50,7 @@ func GetCommand() *cobra.Command { if err := baseCmd.RegisterFlagCompletionFunc("wwinit", completions.OverlayList); err != nil { panic(err) } - if err := baseCmd.RegisterFlagCompletionFunc("profile", completions.Profiles(0)); err != nil { // no limit + if err := baseCmd.RegisterFlagCompletionFunc("profile", completions.Profiles); err != nil { // no limit panic(err) } diff --git a/internal/app/wwctl/node/status/root.go b/internal/app/wwctl/node/status/root.go index 36ffeb54..d6cfd4d1 100644 --- a/internal/app/wwctl/node/status/root.go +++ b/internal/app/wwctl/node/status/root.go @@ -12,7 +12,7 @@ var ( Short: "View the provisioning status of nodes", Long: "View and monitor the status of nodes as they are provisioned and check in.", RunE: CobraRunE, - ValidArgsFunction: completions.Nodes(0), // no limit + ValidArgsFunction: completions.Nodes, } SetWatch bool SetUpdate int diff --git a/internal/app/wwctl/overlay/build/root.go b/internal/app/wwctl/overlay/build/root.go index 3b82632c..ba1fe163 100644 --- a/internal/app/wwctl/overlay/build/root.go +++ b/internal/app/wwctl/overlay/build/root.go @@ -14,7 +14,7 @@ var ( Short: "(Re)build node overlays", Long: "This command builds overlays for given nodes.", RunE: CobraRunE, - ValidArgsFunction: completions.Nodes(0), // no limit + ValidArgsFunction: completions.Nodes, } OverlayNames []string OverlayDir string diff --git a/internal/app/wwctl/power/cycle/root.go b/internal/app/wwctl/power/cycle/root.go index 45b07340..77fa0461 100644 --- a/internal/app/wwctl/power/cycle/root.go +++ b/internal/app/wwctl/power/cycle/root.go @@ -20,7 +20,7 @@ func GetCommand() *cobra.Command { Long: "This command cycles power for a set of nodes specified by PATTERN.", RunE: CobraRunE(&vars), Args: cobra.MinimumNArgs(1), - ValidArgsFunction: completions.Nodes(0), // no limit + ValidArgsFunction: completions.Nodes, } 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 eba9fdcd..ee647342 100644 --- a/internal/app/wwctl/power/off/root.go +++ b/internal/app/wwctl/power/off/root.go @@ -20,7 +20,7 @@ func GetCommand() *cobra.Command { Long: "This command will shutdown power to a set of nodes specified by PATTERN.", RunE: CobraRunE(&vars), Args: cobra.MinimumNArgs(1), - ValidArgsFunction: completions.Nodes(0), // no limit, + ValidArgsFunction: completions.Nodes, } 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 0be289be..1111f160 100644 --- a/internal/app/wwctl/power/on/root.go +++ b/internal/app/wwctl/power/on/root.go @@ -19,7 +19,7 @@ func GetCommand() *cobra.Command { 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, + ValidArgsFunction: completions.Nodes, } 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 a2ef35b0..d7dd5506 100644 --- a/internal/app/wwctl/power/reset/root.go +++ b/internal/app/wwctl/power/reset/root.go @@ -20,7 +20,7 @@ func GetCommand() *cobra.Command { Long: "This command will issue a reset to a set of nodes specified by PATTERN.", RunE: CobraRunE(&vars), Args: cobra.MinimumNArgs(1), - ValidArgsFunction: completions.Nodes(0), // no limit, + ValidArgsFunction: completions.Nodes, } 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 30f21a05..faea9c02 100644 --- a/internal/app/wwctl/power/soft/root.go +++ b/internal/app/wwctl/power/soft/root.go @@ -20,7 +20,7 @@ func GetCommand() *cobra.Command { Long: "This command uses the operating system to shut down the set of nodes specified by PATTERN.", RunE: CobraRunE(&vars), Args: cobra.MinimumNArgs(1), - ValidArgsFunction: completions.Nodes(0), // no limit, + ValidArgsFunction: completions.Nodes, } 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 84b7d765..6b0c6a37 100644 --- a/internal/app/wwctl/power/status/root.go +++ b/internal/app/wwctl/power/status/root.go @@ -20,7 +20,7 @@ func GetCommand() *cobra.Command { Long: "This command displays the power status of a set of nodes specified by PATTERN.", RunE: CobraRunE(&vars), Args: cobra.MinimumNArgs(1), - ValidArgsFunction: completions.Nodes(0), // no limit, + ValidArgsFunction: completions.Nodes, } 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/profile/add/root.go b/internal/app/wwctl/profile/add/root.go index ee1aab4f..45399ec9 100644 --- a/internal/app/wwctl/profile/add/root.go +++ b/internal/app/wwctl/profile/add/root.go @@ -29,7 +29,7 @@ func GetCommand() *cobra.Command { vars.profileAdd.CreateAddFlags(baseCmd) flags.AddContainer(baseCmd, &(vars.profileConf.ImageName)) // register the command line completions - if err := baseCmd.RegisterFlagCompletionFunc("image", completions.Images(0)); err != nil { // no limit + if err := baseCmd.RegisterFlagCompletionFunc("image", completions.Images); err != nil { // no limit panic(err) } if err := baseCmd.RegisterFlagCompletionFunc("kernelversion", completions.ProfileKernelVersion); err != nil { diff --git a/internal/app/wwctl/profile/delete/root.go b/internal/app/wwctl/profile/delete/root.go index 62bf58f1..6c6e0df4 100644 --- a/internal/app/wwctl/profile/delete/root.go +++ b/internal/app/wwctl/profile/delete/root.go @@ -14,7 +14,7 @@ var ( Aliases: []string{"remove", "rm", "del"}, RunE: CobraRunE, Args: cobra.MinimumNArgs(1), - ValidArgsFunction: completions.Profiles(0), // no limit + ValidArgsFunction: completions.Profiles, } SetYes bool ) diff --git a/internal/app/wwctl/profile/edit/root.go b/internal/app/wwctl/profile/edit/root.go index e676ff8e..078c9cc1 100644 --- a/internal/app/wwctl/profile/edit/root.go +++ b/internal/app/wwctl/profile/edit/root.go @@ -12,7 +12,7 @@ var ( Short: "Edit node(s) with editor", Long: "This command opens an editor for the given profiles.", RunE: CobraRunE, - ValidArgsFunction: completions.Profiles(0), + ValidArgsFunction: completions.Profiles, } NoHeader bool ) diff --git a/internal/app/wwctl/profile/list/root.go b/internal/app/wwctl/profile/list/root.go index 05fe629b..86468943 100644 --- a/internal/app/wwctl/profile/list/root.go +++ b/internal/app/wwctl/profile/list/root.go @@ -21,7 +21,7 @@ func GetCommand() *cobra.Command { Long: "This command will display configurations for PROFILE.", RunE: CobraRunE(&vars), Aliases: []string{"ls"}, - ValidArgsFunction: completions.Profiles(0), // no limit + ValidArgsFunction: completions.Profiles, } baseCmd.PersistentFlags().BoolVarP(&vars.showAll, "all", "a", false, "Show all profile configurations") baseCmd.PersistentFlags().BoolVarP(&vars.showYaml, "yaml", "y", false, "Show profile configurations via yaml format") diff --git a/internal/app/wwctl/profile/set/root.go b/internal/app/wwctl/profile/set/root.go index 699c1c9d..8fd8c262 100644 --- a/internal/app/wwctl/profile/set/root.go +++ b/internal/app/wwctl/profile/set/root.go @@ -34,7 +34,7 @@ func GetCommand() *cobra.Command { "Note: use the string 'UNSET' to remove a configuration", Aliases: []string{"modify"}, RunE: CobraRunE(&vars), - ValidArgsFunction: completions.Profiles(0), // no limit + ValidArgsFunction: completions.Profiles, } vars.profileConf.CreateFlags(baseCmd) vars.profileDel.CreateDelFlags(baseCmd) @@ -42,7 +42,7 @@ func GetCommand() *cobra.Command { flags.AddContainer(baseCmd, &(vars.profileConf.ImageName)) baseCmd.PersistentFlags().BoolVarP(&vars.setYes, "yes", "y", false, "Set 'yes' to all questions asked") // register the command line completions - if err := baseCmd.RegisterFlagCompletionFunc("image", completions.Images(0)); err != nil { // no limit + if err := baseCmd.RegisterFlagCompletionFunc("image", completions.Images); err != nil { // no limit panic(err) } if err := baseCmd.RegisterFlagCompletionFunc("kernelversion", completions.ProfileKernelVersion); err != nil { diff --git a/internal/app/wwctl/ssh/root.go b/internal/app/wwctl/ssh/root.go index ef7c1f32..b7c5bc5b 100644 --- a/internal/app/wwctl/ssh/root.go +++ b/internal/app/wwctl/ssh/root.go @@ -15,7 +15,7 @@ var ( Args: cobra.MinimumNArgs(2), ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { if len(args) == 0 { - return completions.Nodes(1)(cmd, args, toComplete) + return completions.Nodes(cmd, args, toComplete) } return completions.None(cmd, args, toComplete) },