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

Commit 480590f

Browse files
committed
Add logJson and ignore logs if —json passed
1 parent 1af482a commit 480590f

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/index.js

Lines changed: 17 additions & 5 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 [ token ] = this.getConfigToken(argv.auth)
28+
const authViaFlag = argv.auth || argv.a
29+
const [ token ] = this.getConfigToken(authViaFlag)
2930
// Get site config from netlify.toml
3031
const configPath = getConfigPath(projectRoot)
3132
// TODO: https://github.com/request/caseless to handle key casing issues
@@ -66,34 +67,45 @@ class BaseCommand extends Command {
6667
}
6768
}
6869

70+
logJson(message = '', ...args) {
71+
if (!argv.json) {
72+
return
73+
}
74+
process.stdout.write(JSON.stringify(message, null, 2))
75+
}
76+
6977
log(message = '', ...args) {
70-
if (this.argv && this.argv.includes('--silent')) {
78+
if (this.argv && this.argv.includes('--silent') || argv.silent || argv.json) {
7179
return
7280
}
7381
message = typeof message === 'string' ? message : inspect(message)
7482
process.stdout.write(format(message, ...args) + '\n')
7583
}
7684

7785
parse(opts, argv = this.argv) {
86+
// Set flags object for commands without flags
87+
if (!opts.flags) {
88+
opts.flags = {}
89+
}
7890
/* enrich parse with global flags */
7991
const globalFlags = {}
80-
if (opts.flags && !opts.flags.silent) {
92+
if (!opts.flags.silent) {
8193
globalFlags['silent'] = {
8294
parse: (b, _) => b,
8395
description: 'Silence CLI output',
8496
allowNo: false,
8597
type: 'boolean'
8698
}
8799
}
88-
if (opts.flags && !opts.flags.json) {
100+
if (!opts.flags.json) {
89101
globalFlags['json'] = {
90102
parse: (b, _) => b,
91103
description: 'Output return values as JSON',
92104
allowNo: false,
93105
type: 'boolean'
94106
}
95107
}
96-
if (opts.flags && !opts.flags.auth) {
108+
if (!opts.flags.auth) {
97109
globalFlags['auth'] = {
98110
parse: (b, _) => b,
99111
description: 'Netlify auth token',

0 commit comments

Comments
 (0)