Skip to content
This repository was archived by the owner on Aug 10, 2020. It is now read-only.

Commit e77acca

Browse files
committed
use global argv for logger
1 parent 480590f commit e77acca

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/index.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ class BaseCommand extends Command {
2525
async init(err) {
2626
const projectRoot = findRoot(process.cwd())
2727
// Grab netlify API token
28-
const authViaFlag = argv.auth || argv.a
28+
const authViaFlag = getAuthArg(argv)
29+
2930
const [ token ] = this.getConfigToken(authViaFlag)
3031
// Get site config from netlify.toml
3132
const configPath = getConfigPath(projectRoot)
@@ -68,22 +69,25 @@ class BaseCommand extends Command {
6869
}
6970

7071
logJson(message = '', ...args) {
72+
/* Only run json logger when --json flag present */
7173
if (!argv.json) {
7274
return
7375
}
7476
process.stdout.write(JSON.stringify(message, null, 2))
7577
}
7678

7779
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) {
7982
return
8083
}
8184
message = typeof message === 'string' ? message : inspect(message)
8285
process.stdout.write(format(message, ...args) + '\n')
8386
}
8487

88+
/* Modified flag parser to support global --auth, --json, & --silent flags */
8589
parse(opts, argv = this.argv) {
86-
// Set flags object for commands without flags
90+
/* Set flags object for commands without flags */
8791
if (!opts.flags) {
8892
opts.flags = {}
8993
}
@@ -218,4 +222,12 @@ class BaseCommand extends Command {
218222
}
219223
}
220224

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+
221233
module.exports = BaseCommand

0 commit comments

Comments
 (0)