Skip to content

Commit

Permalink
feat: have --json global flag disabled by default (#252)
Browse files Browse the repository at this point in the history
  • Loading branch information
RasPhilCo committed Sep 15, 2021
1 parent b89c94b commit c2a7799
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/command.ts
Expand Up @@ -90,7 +90,7 @@ export default abstract class Command {

static parserOptions = {}

static disableJsonFlag: boolean | undefined
static enableJsonFlag = false

// eslint-disable-next-line valid-jsdoc
/**
Expand Down Expand Up @@ -127,7 +127,7 @@ export default abstract class Command {
}

static set flags(flags: Interfaces.FlagInput<any>) {
this._flags = this.disableJsonFlag || settings.disableJsonFlag ? flags : Object.assign({}, Command.globalFlags, flags)
this._flags = this.enableJsonFlag || settings.enableJsonFlag ? Object.assign({}, Command.globalFlags, flags) : flags
}

id: string | undefined
Expand Down Expand Up @@ -193,7 +193,7 @@ export default abstract class Command {
}

public jsonEnabled(): boolean {
return !this.ctor.disableJsonFlag && this.argv.includes('--json')
return this.ctor.enableJsonFlag && this.argv.includes('--json')
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/settings.ts
Expand Up @@ -31,9 +31,9 @@ export type Settings = {
*/
tsnodeEnabled?: boolean;
/**
* Disable the --json flag for all commands
* Enable the --json flag for all commands
*/
disableJsonFlag?: boolean;
enableJsonFlag?: boolean;
};

// Set global.oclif to the new object if it wasn't set before
Expand Down
8 changes: 8 additions & 0 deletions test/help/format-command.test.ts
Expand Up @@ -45,6 +45,8 @@ describe('formatCommand', () => {
static description = `first line
multiline help`

static enableJsonFlag = true

static args = [{name: 'app_name', description: 'app to use'}]

static flags = {
Expand Down Expand Up @@ -97,6 +99,8 @@ ALIASES

static aliases = ['app:init', 'create']

static enableJsonFlag = true

static args = [{name: 'app_name', description: 'app to use'.repeat(35)}]

static flags = {
Expand Down Expand Up @@ -149,6 +153,8 @@ ALIASES

static aliases = ['app:init', 'create']

static enableJsonFlag = true

static args = [{name: 'app_name', description: 'app to use'.repeat(35)}]

static flags = {
Expand Down Expand Up @@ -238,6 +244,8 @@ DESCRIPTION

static aliases = ['app:init', 'create']

static enableJsonFlag = true

static args = [{name: 'app_name', description: 'app to use'}]

static flags = {
Expand Down

0 comments on commit c2a7799

Please sign in to comment.