github.com/Azure/draft-classic@v0.16.0/cmd/draft/config_unset.go (about) 1 package main 2 3 import ( 4 "io" 5 6 "github.com/spf13/cobra" 7 ) 8 9 type configUnsetCmd struct { 10 out io.Writer 11 args []string 12 key string 13 } 14 15 func newConfigUnsetCmd(out io.Writer) *cobra.Command { 16 ccmd := &configUnsetCmd{ 17 out: out, 18 args: []string{"key"}, 19 } 20 cmd := &cobra.Command{ 21 Use: "unset", 22 Short: "unset global Draft configuration stored in $DRAFT_HOME/config.toml", 23 PreRunE: func(cmd *cobra.Command, args []string) error { 24 return ccmd.complete(args) 25 }, 26 RunE: func(cmd *cobra.Command, args []string) error { 27 return ccmd.run() 28 }, 29 } 30 return cmd 31 } 32 33 func (ccmd *configUnsetCmd) complete(args []string) error { 34 if err := validateArgs(args, ccmd.args); err != nil { 35 return err 36 } 37 ccmd.key = args[0] 38 return nil 39 } 40 41 func (ccmd *configUnsetCmd) run() error { 42 delete(globalConfig, ccmd.key) 43 return SaveConfig(globalConfig) 44 }