added basic error handling for flag nouns

This commit is contained in:
Christian Goll
2021-09-28 12:14:46 +02:00
parent bf7bf27c21
commit edf1329246
3 changed files with 47 additions and 20 deletions

View File

@@ -1,6 +1,8 @@
package imprt
import (
"log"
"github.com/hpcng/warewulf/internal/pkg/container"
"github.com/spf13/cobra"
)
@@ -27,10 +29,13 @@ func init() {
baseCmd.PersistentFlags().BoolVar(&SetDefault, "setdefault", false, "Set this kernel for the default profile")
baseCmd.PersistentFlags().StringVarP(&OptRoot, "root", "r", "/", "Import kernel from root (chroot) directory")
baseCmd.PersistentFlags().StringVarP(&OptContainer, "container", "C", "", "Import kernel from container")
baseCmd.RegisterFlagCompletionFunc("container", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
err := baseCmd.RegisterFlagCompletionFunc("container", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
list, _ := container.ListSources()
return list, cobra.ShellCompDirectiveNoFileComp
})
if err != nil {
log.Println(err)
}
}
// GetRootCommand returns the root cobra.Command for the application.