github.com/Azure/draft-classic@v0.16.0/cmd/draft/config_get.go (about) 1 package main 2 3 import ( 4 "errors" 5 "fmt" 6 "io" 7 8 "github.com/spf13/cobra" 9 ) 10 11 type configGetCmd struct { 12 out io.Writer 13 args []string 14 key string 15 } 16 17 func newConfigGetCmd(out io.Writer) *cobra.Command { 18 ccmd := &configGetCmd{ 19 out: out, 20 args: []string{"key"}, 21 } 22 cmd := &cobra.Command{ 23 Use: "get", 24 Short: "get global Draft configuration stored in $DRAFT_HOME/config.toml", 25 PreRunE: func(cmd *cobra.Command, args []string) error { 26 return ccmd.complete(args) 27 }, 28 RunE: func(cmd *cobra.Command, args []string) error { 29 return ccmd.run() 30 }, 31 } 32 return cmd 33 } 34 35 func (ccmd *configGetCmd) complete(args []string) error { 36 if err := validateArgs(args, ccmd.args); err != nil { 37 return err 38 } 39 ccmd.key = args[0] 40 return nil 41 } 42 43 func (ccmd *configGetCmd) run() error { 44 v, ok := globalConfig[ccmd.key] 45 if !ok { 46 return errors.New("specified key could not be found in config") 47 } 48 49 fmt.Fprintln(ccmd.out, v) 50 return nil 51 }