wwctl profile args and completions
Signed-off-by: Jonathon Anderson <janderson@ciq.com>
This commit is contained in:
@@ -1,14 +1,10 @@
|
||||
package add
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/warewulf/warewulf/internal/app/wwctl/completions"
|
||||
"github.com/warewulf/warewulf/internal/app/wwctl/flags"
|
||||
"github.com/warewulf/warewulf/internal/pkg/image"
|
||||
"github.com/warewulf/warewulf/internal/pkg/node"
|
||||
"github.com/warewulf/warewulf/internal/pkg/overlay"
|
||||
)
|
||||
|
||||
type variables struct {
|
||||
@@ -27,32 +23,23 @@ func GetCommand() *cobra.Command {
|
||||
Long: "This command adds a new named PROFILE.",
|
||||
Aliases: []string{"new", "create"},
|
||||
RunE: CobraRunE(&vars),
|
||||
Args: cobra.ExactArgs(1),
|
||||
ValidArgsFunction: completions.None,
|
||||
}
|
||||
vars.profileConf.CreateFlags(baseCmd)
|
||||
vars.profileAdd.CreateAddFlags(baseCmd)
|
||||
flags.AddContainer(baseCmd, &(vars.profileConf.ImageName))
|
||||
// register the command line completions
|
||||
if err := baseCmd.RegisterFlagCompletionFunc("image", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
list, _ := image.ListSources()
|
||||
return list, cobra.ShellCompDirectiveNoFileComp
|
||||
}); err != nil {
|
||||
log.Println(err)
|
||||
if err := baseCmd.RegisterFlagCompletionFunc("image", completions.Images(0)); err != nil { // no limit
|
||||
panic(err)
|
||||
}
|
||||
if err := baseCmd.RegisterFlagCompletionFunc("kernelversion", completions.ProfileKernelVersion); err != nil {
|
||||
log.Println(err)
|
||||
panic(err)
|
||||
}
|
||||
if err := baseCmd.RegisterFlagCompletionFunc("runtime", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
list := overlay.FindOverlays()
|
||||
return list, cobra.ShellCompDirectiveNoFileComp
|
||||
}); err != nil {
|
||||
log.Println(err)
|
||||
if err := baseCmd.RegisterFlagCompletionFunc("runtime", completions.Overlays); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := baseCmd.RegisterFlagCompletionFunc("wwinit", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
list := overlay.FindOverlays()
|
||||
return list, cobra.ShellCompDirectiveNoFileComp
|
||||
}); err != nil {
|
||||
log.Println(err)
|
||||
if err := baseCmd.RegisterFlagCompletionFunc("wwinit", completions.Overlays); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return baseCmd
|
||||
}
|
||||
|
||||
@@ -37,9 +37,6 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
if np == r {
|
||||
wwlog.Verbose("Removing profile from node %s: %s", n.Id(), r)
|
||||
n.Profiles = append(n.Profiles[:i], n.Profiles[i+1:]...)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to update node: %w", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ var (
|
||||
Aliases: []string{"remove", "rm", "del"},
|
||||
RunE: CobraRunE,
|
||||
Args: cobra.MinimumNArgs(1),
|
||||
ValidArgsFunction: completions.Profiles,
|
||||
ValidArgsFunction: completions.Profiles(0), // no limit
|
||||
}
|
||||
SetYes bool
|
||||
)
|
||||
|
||||
@@ -2,7 +2,7 @@ package edit
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/warewulf/warewulf/internal/pkg/node"
|
||||
"github.com/warewulf/warewulf/internal/app/wwctl/completions"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -12,18 +12,7 @@ var (
|
||||
Short: "Edit node(s) with editor",
|
||||
Long: "This command opens an editor for the given profiles.",
|
||||
RunE: CobraRunE,
|
||||
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
if len(args) != 0 {
|
||||
return nil, cobra.ShellCompDirectiveNoFileComp
|
||||
}
|
||||
nodeDB, _ := node.New()
|
||||
profiles, _ := nodeDB.FindAllProfiles()
|
||||
var p_names []string
|
||||
for _, profile := range profiles {
|
||||
p_names = append(p_names, profile.Id())
|
||||
}
|
||||
return p_names, cobra.ShellCompDirectiveNoFileComp
|
||||
},
|
||||
ValidArgsFunction: completions.Profiles(0),
|
||||
}
|
||||
NoHeader bool
|
||||
)
|
||||
|
||||
@@ -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,
|
||||
ValidArgsFunction: completions.Profiles(0), // no limit
|
||||
}
|
||||
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")
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
package set
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/warewulf/warewulf/internal/app/wwctl/completions"
|
||||
"github.com/warewulf/warewulf/internal/app/wwctl/flags"
|
||||
"github.com/warewulf/warewulf/internal/pkg/image"
|
||||
"github.com/warewulf/warewulf/internal/pkg/node"
|
||||
"github.com/warewulf/warewulf/internal/pkg/overlay"
|
||||
)
|
||||
|
||||
type variables struct {
|
||||
@@ -37,9 +33,8 @@ func GetCommand() *cobra.Command {
|
||||
Long: "This command sets configuration properties for the node PROFILE(s).\n\n" +
|
||||
"Note: use the string 'UNSET' to remove a configuration",
|
||||
Aliases: []string{"modify"},
|
||||
Args: cobra.MinimumNArgs(0),
|
||||
RunE: CobraRunE(&vars),
|
||||
ValidArgsFunction: completions.Profiles,
|
||||
ValidArgsFunction: completions.Profiles(0), // no limit
|
||||
}
|
||||
vars.profileConf.CreateFlags(baseCmd)
|
||||
vars.profileDel.CreateDelFlags(baseCmd)
|
||||
@@ -47,26 +42,17 @@ 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", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
list, _ := image.ListSources()
|
||||
return list, cobra.ShellCompDirectiveNoFileComp
|
||||
}); err != nil {
|
||||
log.Println(err)
|
||||
if err := baseCmd.RegisterFlagCompletionFunc("image", completions.Images(0)); err != nil { // no limit
|
||||
panic(err)
|
||||
}
|
||||
if err := baseCmd.RegisterFlagCompletionFunc("kernelversion", completions.ProfileKernelVersion); err != nil {
|
||||
log.Println(err)
|
||||
panic(err)
|
||||
}
|
||||
if err := baseCmd.RegisterFlagCompletionFunc("runtime", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
list := overlay.FindOverlays()
|
||||
return list, cobra.ShellCompDirectiveNoFileComp
|
||||
}); err != nil {
|
||||
log.Println(err)
|
||||
if err := baseCmd.RegisterFlagCompletionFunc("runtime", completions.Overlays); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := baseCmd.RegisterFlagCompletionFunc("wwinit", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
list := overlay.FindOverlays()
|
||||
return list, cobra.ShellCompDirectiveNoFileComp
|
||||
}); err != nil {
|
||||
log.Println(err)
|
||||
if err := baseCmd.RegisterFlagCompletionFunc("wwinit", completions.Overlays); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return baseCmd
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user