@@ -25,7 +25,8 @@ class BaseCommand extends Command {
25
25
async init ( err ) {
26
26
const projectRoot = findRoot ( process . cwd ( ) )
27
27
// Grab netlify API token
28
- const authViaFlag = argv . auth || argv . a
28
+ const authViaFlag = getAuthArg ( argv )
29
+
29
30
const [ token ] = this . getConfigToken ( authViaFlag )
30
31
// Get site config from netlify.toml
31
32
const configPath = getConfigPath ( projectRoot )
@@ -68,22 +69,25 @@ class BaseCommand extends Command {
68
69
}
69
70
70
71
logJson ( message = '' , ...args ) {
72
+ /* Only run json logger when --json flag present */
71
73
if ( ! argv . json ) {
72
74
return
73
75
}
74
76
process . stdout . write ( JSON . stringify ( message , null , 2 ) )
75
77
}
76
78
77
79
log ( message = '' , ...args ) {
78
- if ( this . argv && this . argv . includes ( '--silent' ) || argv . silent || argv . json ) {
80
+ /* If --silent or --json flag passed disable logger */
81
+ if ( argv . silent || argv . json ) {
79
82
return
80
83
}
81
84
message = typeof message === 'string' ? message : inspect ( message )
82
85
process . stdout . write ( format ( message , ...args ) + '\n' )
83
86
}
84
87
88
+ /* Modified flag parser to support global --auth, --json, & --silent flags */
85
89
parse ( opts , argv = this . argv ) {
86
- // Set flags object for commands without flags
90
+ /* Set flags object for commands without flags */
87
91
if ( ! opts . flags ) {
88
92
opts . flags = { }
89
93
}
@@ -218,4 +222,12 @@ class BaseCommand extends Command {
218
222
}
219
223
}
220
224
225
+ function getAuthArg ( cliArgs ) {
226
+ // If deploy command. Support shorthand 'a' flag
227
+ if ( cliArgs && cliArgs . _ && cliArgs . _ [ 0 ] === 'deploy' ) {
228
+ return cliArgs . auth || cliArgs . a
229
+ }
230
+ return cliArgs . auth
231
+ }
232
+
221
233
module . exports = BaseCommand
0 commit comments