forked from parse-community/parse-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefault.go
48 lines (40 loc) · 1.11 KB
/
default.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
47
48
package main
import (
"github.com/ParsePlatform/parse-cli/parsecli"
"github.com/facebookgo/stackerr"
"github.com/spf13/cobra"
)
type defaultCmd struct{}
func (d *defaultCmd) run(e *parsecli.Env, args []string) error {
var newDefault string
if len(args) > 1 {
return stackerr.Newf("unexpected arguments, only an optional app name is expected: %v", args)
}
if len(args) == 1 {
newDefault = args[0]
}
config, err := parsecli.ConfigFromDir(e.Root)
if err != nil {
return err
}
if config.GetNumApps() == 0 {
return stackerr.New("No apps are associated with this project. You can add some with parse add")
}
defaultApp := config.GetDefaultApp()
switch newDefault {
case "":
return parsecli.PrintDefault(e, defaultApp)
default:
return parsecli.SetDefault(e, newDefault, defaultApp, config)
}
}
func NewDefaultCmd(e *parsecli.Env) *cobra.Command {
d := defaultCmd{}
return &cobra.Command{
Use: "default [app]",
Short: "Sets or gets the default Parse App",
Long: `Gets the default Parse App. If an argument is given, sets the ` +
`default Parse App.`,
Run: parsecli.RunWithArgs(e, d.run),
}
}