Recursive handling for command line flags
Every struct in a NodeConf with `lopt:"foo" set is now added as a command-line flag with the RecursiveCreateFlags call. For maps a struct with the key UNDEF is added so that it can be parsed out. As the flags for the command-line need variables which hold the values, for every map an element map[UNDEF] is added. When now calling the internal add, these map element can be filtered out and replace by the given name. (e.g., --netname) * rewrote node/profile add for recursive functions * rewrote node/profile set for recursive functions * rewrote node/profile list for recursive functions Signed-off-by: Christian Goll <cgoll@suse.com>
This commit is contained in:
committed by
Jonathon Anderson
parent
c55c5a2ac4
commit
45539a0d1f
@@ -11,19 +11,18 @@ import (
|
||||
)
|
||||
|
||||
type variables struct {
|
||||
netName string
|
||||
profileConf node.NodeConf
|
||||
}
|
||||
|
||||
var (
|
||||
netName string
|
||||
profileConf node.NodeConf
|
||||
SetNetDevDel string
|
||||
SetNodeAll bool
|
||||
SetYes bool
|
||||
SetForce bool
|
||||
NetName string
|
||||
fsName string
|
||||
partName string
|
||||
diskName string
|
||||
ProfileConf node.NodeConf
|
||||
Converters []func() error
|
||||
)
|
||||
}
|
||||
|
||||
// GetRootCommand returns the root cobra.Command for the application.
|
||||
func GetCommand() *cobra.Command {
|
||||
@@ -37,9 +36,12 @@ func GetCommand() *cobra.Command {
|
||||
RunE: CobraRunE(&vars),
|
||||
Args: cobra.ExactArgs(1),
|
||||
}
|
||||
Converters = vars.profileConf.CreateFlags(baseCmd,
|
||||
vars.Converters = vars.profileConf.CreateFlags(baseCmd,
|
||||
[]string{"ipaddr", "ipaddr6", "ipmiaddr", "profile"})
|
||||
baseCmd.PersistentFlags().StringVar(&vars.netName, "netname", "", "Set network name for network options")
|
||||
baseCmd.PersistentFlags().StringVar(&vars.fsName, "fsname", "", "set the file system name which must match a partition name")
|
||||
baseCmd.PersistentFlags().StringVar(&vars.partName, "partname", "", "set the partition name so it can be used by a file system")
|
||||
baseCmd.PersistentFlags().StringVar(&vars.diskName, "diskname", "", "set disk device name for the partition")
|
||||
// register the command line completions
|
||||
if err := baseCmd.RegisterFlagCompletionFunc("container", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
list, _ := container.ListSources()
|
||||
@@ -65,7 +67,6 @@ func GetCommand() *cobra.Command {
|
||||
}); err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
baseCmd.PersistentFlags().BoolVarP(&SetYes, "yes", "y", false, "Set 'yes' to all questions asked")
|
||||
|
||||
baseCmd.PersistentFlags().BoolVarP(&vars.SetYes, "yes", "y", false, "Set 'yes' to all questions asked")
|
||||
return baseCmd
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user