Skip to content

Commit c2a7799

Browse files
authored
feat: have --json global flag disabled by default (#252)
1 parent b89c94b commit c2a7799

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

src/command.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export default abstract class Command {
9090

9191
static parserOptions = {}
9292

93-
static disableJsonFlag: boolean | undefined
93+
static enableJsonFlag = false
9494

9595
// eslint-disable-next-line valid-jsdoc
9696
/**
@@ -127,7 +127,7 @@ export default abstract class Command {
127127
}
128128

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

133133
id: string | undefined
@@ -193,7 +193,7 @@ export default abstract class Command {
193193
}
194194

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

199199
/**

src/settings.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ export type Settings = {
3131
*/
3232
tsnodeEnabled?: boolean;
3333
/**
34-
* Disable the --json flag for all commands
34+
* Enable the --json flag for all commands
3535
*/
36-
disableJsonFlag?: boolean;
36+
enableJsonFlag?: boolean;
3737
};
3838

3939
// Set global.oclif to the new object if it wasn't set before

test/help/format-command.test.ts

+8
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ describe('formatCommand', () => {
4545
static description = `first line
4646
multiline help`
4747

48+
static enableJsonFlag = true
49+
4850
static args = [{name: 'app_name', description: 'app to use'}]
4951

5052
static flags = {
@@ -97,6 +99,8 @@ ALIASES
9799

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

102+
static enableJsonFlag = true
103+
100104
static args = [{name: 'app_name', description: 'app to use'.repeat(35)}]
101105

102106
static flags = {
@@ -149,6 +153,8 @@ ALIASES
149153

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

156+
static enableJsonFlag = true
157+
152158
static args = [{name: 'app_name', description: 'app to use'.repeat(35)}]
153159

154160
static flags = {
@@ -238,6 +244,8 @@ DESCRIPTION
238244

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

247+
static enableJsonFlag = true
248+
241249
static args = [{name: 'app_name', description: 'app to use'}]
242250

243251
static flags = {

0 commit comments

Comments
 (0)