diff --git a/internal/app/wwctl/node/set/root.go b/internal/app/wwctl/node/set/root.go index 0174d55e..976f28d9 100644 --- a/internal/app/wwctl/node/set/root.go +++ b/internal/app/wwctl/node/set/root.go @@ -2,6 +2,7 @@ package set import ( "log" + "reflect" "github.com/hpcng/warewulf/internal/pkg/container" "github.com/hpcng/warewulf/internal/pkg/kernel" @@ -74,10 +75,38 @@ var ( SetAssetKey string SetNetTags []string SetNetDelTags []string + OptionStrMap map[string]*string ) func init() { - baseCmd.PersistentFlags().StringVar(&SetComment, "comment", "", "Set a comment for this node") + OptionStrMap = make(map[string]*string) + var emptyNodeConf node.NodeConf + nodeStruct := reflect.ValueOf(emptyNodeConf) + nodeType := nodeStruct.Type() + for i := 0; i < nodeStruct.NumField(); i++ { + field := nodeType.Field(i) + if field.Tag.Get("comment") != "" { + kind := field.Type.Kind() + if kind == reflect.String { + var optionVal string + OptionStrMap[field.Name] = &optionVal + if field.Tag.Get("sopt") != "" { + baseCmd.PersistentFlags().StringVarP(&optionVal, + field.Tag.Get("lopt"), + field.Tag.Get("sopt"), + field.Tag.Get("default"), + field.Tag.Get("comment")) + } else { + baseCmd.PersistentFlags().StringVar(&optionVal, + field.Tag.Get("lopt"), + field.Tag.Get("default"), + field.Tag.Get("comment")) + + } + } + } + } + //baseCmd.PersistentFlags().StringVar(&SetComment, "comment", "", "Set a comment for this node") baseCmd.PersistentFlags().StringVarP(&SetContainer, "container", "C", "", "Set the container (VNFS) for this node") if err := baseCmd.RegisterFlagCompletionFunc("container", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { list, _ := container.ListSources() diff --git a/internal/pkg/node/datastructure.go b/internal/pkg/node/datastructure.go index 4e818b8f..91818c1e 100644 --- a/internal/pkg/node/datastructure.go +++ b/internal/pkg/node/datastructure.go @@ -19,7 +19,7 @@ type NodeYaml struct { NodeConf is the datastructure which is stored on disk. */ type NodeConf struct { - Comment string `yaml:"comment,omitempty"` + Comment string `yaml:"comment,omitempty" lopt:"comment" comment:"Set Comment"` ClusterName string `yaml:"cluster name,omitempty"` ContainerName string `yaml:"container name,omitempty"` Ipxe string `yaml:"ipxe template,omitempty"`