@@ -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 [ token ] = this . getConfigToken ( argv . auth )
28
+ const authViaFlag = argv . auth || argv . a
29
+ const [ token ] = this . getConfigToken ( authViaFlag )
29
30
// Get site config from netlify.toml
30
31
const configPath = getConfigPath ( projectRoot )
31
32
// TODO: https://github.com/request/caseless to handle key casing issues
@@ -66,34 +67,45 @@ class BaseCommand extends Command {
66
67
}
67
68
}
68
69
70
+ logJson ( message = '' , ...args ) {
71
+ if ( ! argv . json ) {
72
+ return
73
+ }
74
+ process . stdout . write ( JSON . stringify ( message , null , 2 ) )
75
+ }
76
+
69
77
log ( message = '' , ...args ) {
70
- if ( this . argv && this . argv . includes ( '--silent' ) ) {
78
+ if ( this . argv && this . argv . includes ( '--silent' ) || argv . silent || argv . json ) {
71
79
return
72
80
}
73
81
message = typeof message === 'string' ? message : inspect ( message )
74
82
process . stdout . write ( format ( message , ...args ) + '\n' )
75
83
}
76
84
77
85
parse ( opts , argv = this . argv ) {
86
+ // Set flags object for commands without flags
87
+ if ( ! opts . flags ) {
88
+ opts . flags = { }
89
+ }
78
90
/* enrich parse with global flags */
79
91
const globalFlags = { }
80
- if ( opts . flags && ! opts . flags . silent ) {
92
+ if ( ! opts . flags . silent ) {
81
93
globalFlags [ 'silent' ] = {
82
94
parse : ( b , _ ) => b ,
83
95
description : 'Silence CLI output' ,
84
96
allowNo : false ,
85
97
type : 'boolean'
86
98
}
87
99
}
88
- if ( opts . flags && ! opts . flags . json ) {
100
+ if ( ! opts . flags . json ) {
89
101
globalFlags [ 'json' ] = {
90
102
parse : ( b , _ ) => b ,
91
103
description : 'Output return values as JSON' ,
92
104
allowNo : false ,
93
105
type : 'boolean'
94
106
}
95
107
}
96
- if ( opts . flags && ! opts . flags . auth ) {
108
+ if ( ! opts . flags . auth ) {
97
109
globalFlags [ 'auth' ] = {
98
110
parse : ( b , _ ) => b ,
99
111
description : 'Netlify auth token' ,
0 commit comments