/
configure.go
37 lines (32 loc) · 897 Bytes
/
configure.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
package cmd
import (
"github.com/spf13/cobra"
"github.com/Shopify/themekit/src/cmdutil"
"github.com/Shopify/themekit/src/env"
)
var configureCmd = &cobra.Command{
Use: "configure",
Short: "Create a configuration file",
Long: `Configure will create a new configuration file to
access shopify using the theme kit.
For more documentation please see http://shopify.github.io/themekit/commands/#configure
`,
RunE: func(cmd *cobra.Command, args []string) error {
return cmdutil.ForDefaultClient(flags, args, createConfig)
},
}
func createConfig(ctx cmdutil.Ctx) error {
flagEnvs := ctx.Flags.Environments.Value()
if len(flagEnvs) == 0 {
if _, err := ctx.Conf.Set(env.Default.Name, *ctx.Env); err != nil {
return err
}
} else {
for _, name := range flagEnvs {
if _, err := ctx.Conf.Set(name, *ctx.Env); err != nil {
return err
}
}
}
return ctx.Conf.Save()
}