diff --git a/src/command.ts b/src/command.ts index b0d0c3ef5..1e72c5166 100644 --- a/src/command.ts +++ b/src/command.ts @@ -21,6 +21,13 @@ process.stdout.on('error', (err: any) => { throw err }) +const jsonFlag = { + json: Flags.boolean({ + description: 'Format output as json.', + helpGroup: 'GLOBAL', + }), +} + /** * An abstract class which acts as the base for each command * in your project. @@ -112,22 +119,28 @@ export default abstract class Command { return cmd._run(argv) } - private static globalFlags = { - json: Flags.boolean({ - description: 'Format output as json.', - helpGroup: 'GLOBAL', - }), + protected static _globalFlags: Interfaces.FlagInput + + static get globalFlags(): Interfaces.FlagInput { + return this._globalFlags + } + + static set globalFlags(flags: Interfaces.FlagInput) { + this._globalFlags = this.enableJsonFlag ? + Object.assign({}, jsonFlag, this.globalFlags, flags) : + Object.assign({}, this.globalFlags, flags) } /** A hash of flags for the command */ - private static _flags: Interfaces.FlagInput + protected static _flags: Interfaces.FlagInput static get flags(): Interfaces.FlagInput { return this._flags } static set flags(flags: Interfaces.FlagInput) { - this._flags = this.enableJsonFlag ? Object.assign({}, Command.globalFlags, flags) : flags + this.globalFlags = {} + this._flags = Object.assign({}, this.globalFlags, flags) } id: string | undefined