-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathconfig.go
More file actions
51 lines (47 loc) · 1.2 KB
/
config.go
File metadata and controls
51 lines (47 loc) · 1.2 KB
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
47
48
49
50
51
package main
import (
"encoding/json"
"fmt"
"github.com/spf13/cobra"
"github.com/stuartleeks/devcontainer-cli/internal/pkg/config"
)
func createConfigCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "config",
}
cmd.AddCommand(createConfigShowCommand())
cmd.AddCommand(createConfigWriteCommand())
return cmd
}
func createConfigShowCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "show",
Short: "show the current config",
Long: "load the current config and print it out",
RunE: func(cmd *cobra.Command, args []string) error {
c := config.GetAll()
jsonConfig, err := json.MarshalIndent(c, "", " ")
if err != nil {
return fmt.Errorf("error converting to JSON: %s", err)
}
fmt.Println(string(jsonConfig))
return nil
},
}
return cmd
}
func createConfigWriteCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "write",
Short: "write config",
Long: "Write out the config file to ~/.devcontainer-cli/devcontainer-cli.json",
RunE: func(cmd *cobra.Command, args []string) error {
if err := config.SaveConfig(); err != nil {
return fmt.Errorf("error saving config: %s", err)
}
fmt.Println("Config saved")
return nil
},
}
return cmd
}