forked from parse-community/parse-cli
/
configure_cmd.go
68 lines (57 loc) · 1.64 KB
/
configure_cmd.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"fmt"
"github.com/facebookgo/stackerr"
"github.com/spf13/cobra"
)
type configureCmd struct {
login login
}
func (c *configureCmd) accessToken(e *env) error {
fmt.Fprintf(e.Out,
`Please enter an access token if you already generated it.
If you do not have an access token or would like to generate a new one,
please type: "y" to open the browser or "n" to continue: `,
)
c.login.helpCreateToken(e)
var credentials credentials
fmt.Fprintf(e.Out, "Access Token: ")
fmt.Fscanf(e.In, "%s\n", &credentials.token)
_, err := (&apps{login: login{credentials: credentials}}).restFetchApps(e)
if err != nil {
if err == errAuth {
fmt.Fprintf(e.Err,
`Sorry, the access token you provided is not valid.
Please follow instructions at %s to generate a new access token.
`,
keysURL,
)
} else {
fmt.Fprintf(e.Err, "Unable to validate token with error:\n%s\n", err)
}
return stackerr.New("Could not store credentials. Please try again.")
}
err = c.login.storeCredentials(e, &credentials)
if err == nil {
fmt.Fprintln(e.Out, "Successfully stored credentials.")
}
return stackerr.Wrap(err)
}
func newConfigureCmd(e *env) *cobra.Command {
var c configureCmd
cmd := &cobra.Command{
Use: "configure",
Short: "Configure various Parse settings.",
Long: "Configure various Parse settings like access tokens, project type, and more.",
Run: func(c *cobra.Command, args []string) {
c.Help()
},
}
cmd.AddCommand(&cobra.Command{
Use: "token",
Short: "Store Parse access token on machine",
Long: "Stores Parse access token in ~/.parse/netrc.",
Run: runNoArgs(e, c.accessToken),
})
return cmd
}