@@ -36,21 +36,9 @@ func (c *configureCmd) accountKey(e *env) error {
3636 l .tokenReader = c .tokenReader
3737 }
3838 foundEmail , creds , err := l .getTokenCredentials (e , email )
39+ firstEverConfigure := false
3940 if stackerr .HasUnderlying (err , stackerr .MatcherFunc (os .IsNotExist )) && ! c .isDefault {
40- fmt .Fprintln (
41- e .Out ,
42- `
43-
44- Looks like you have not configured the default account key yet.
45- Note that "parse new" and "parse list" can automatically pick up a default key if present.
46- Otherwise, you'll have to explicitly set the PARSER_EMAIL environment variable
47- for it to know which account key to use.
48- Further, if the command line tool cannot find an account key for a configured email it will try to
49- use the default account key
50-
51- To configure the default account key use:
52- "parse configure accountkey -d"` ,
53- )
41+ firstEverConfigure = true
5442 }
5543
5644 if creds != nil {
@@ -80,7 +68,37 @@ for email: %q
8068 fmt .Fprintf (e .Out , "Successfully stored account key for: %q.\n " , email )
8169 }
8270 }
83- return stackerr .Wrap (err )
71+ if err != nil {
72+ fmt .Fprintln (e .Err , "Could not save account key." )
73+ return stackerr .Wrap (err )
74+ }
75+
76+ if firstEverConfigure {
77+ fmt .Fprintln (
78+ e .Out ,
79+ `
80+ Looks like this is the first time you have configured an account key.
81+ Note that "parse new" and "parse list" can automatically pick up a default key if present.
82+ Otherwise, you'll have to explicitly set the PARSER_EMAIL environment variable
83+ for them to pick the correct account key.
84+ Further, if the command line tool cannot find an account key for a configured email it will try to
85+ use the default account key.
86+ Hence, we are automatically configuring the default account key to be the same as current account key.
87+ ` ,
88+ )
89+ err = c .login .storeCredentials (e , "" , & credentials {token : token })
90+ if err != nil {
91+ fmt .Fprintln (e .Err , "Could not save account key." )
92+ return stackerr .Wrap (err )
93+ }
94+ fmt .Fprintln (e .Out , `Successfully configured the default account key.
95+ To change the default account key in future use:
96+
97+ "parse configure accountkey -d"
98+ ` )
99+ }
100+
101+ return nil
84102}
85103
86104func (c * configureCmd ) parserEmail (e * env , args []string ) error {
0 commit comments