-
Notifications
You must be signed in to change notification settings - Fork 11
/
config_get.go
46 lines (35 loc) · 1008 Bytes
/
config_get.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package config
import (
"fmt"
"github.com/MakeNowJust/heredoc"
"github.com/spf13/cobra"
"github.com/axiomhq/cli/internal/cmdutil"
)
func newGetCmd(f *cmdutil.Factory) *cobra.Command {
cmd := &cobra.Command{
Use: "get <key>",
Short: "Get a configuration value",
Long: `Get a configuration value by specifying its key.`,
DisableFlagsInUseLine: true,
Args: cobra.ExactArgs(1),
ValidArgsFunction: keyCompletionFunc(f.Config),
Example: heredoc.Doc(`
# Get the url of a configured deployment:
$ axiom config get "deployments.axiom-eu-west-1
# Get the url of a deployment configured in the given configuration
# file:
$ axiom config get "deployments.axiom-eu-west-1 -C /etc/axiom/cli.toml
`),
RunE: func(_ *cobra.Command, args []string) error {
val, err := f.Config.Get(args[0])
if err != nil {
return err
} else if val != "" {
_, err = fmt.Fprintf(f.IO.Out(), "%s\n", val)
return err
}
return nil
},
}
return cmd
}