diff --git a/src/command.ts b/src/command.ts index 708780546..3fc4995b8 100644 --- a/src/command.ts +++ b/src/command.ts @@ -288,7 +288,7 @@ export abstract class Command { return jsonIndex > -1 && (ptIndex === -1 || jsonIndex < ptIndex) } - return this.argv.includes('--json') + return this.argv.includes('--json') || this.config.scopedEnvVar?.('CONTENT_TYPE')?.toLowerCase() === 'json' } /** diff --git a/test/command/command.test.ts b/test/command/command.test.ts index f72e75ea6..ecade0257 100644 --- a/test/command/command.test.ts +++ b/test/command/command.test.ts @@ -525,6 +525,22 @@ describe('command', () => { }) .it('json enabled/pass through disabled/--json flag before --/jsonEnabled() should be true') + fancy + .stdout() + .do(async () => { + class CMD extends Command { + static enableJsonFlag = true + async run() {} + } + + // mock a scopedEnvVar being set to JSON + const cmd = new CMD([], { + bin: 'FOO', scopedEnvVar: (foo: string) => foo.includes('CONTENT_TYPE') ? 'json' : undefined, + } as any) + expect(cmd.jsonEnabled()).to.equal(true) + }) + .it('json enabled from env') + fancy .stdout() .do(async () => { diff --git a/test/interfaces/args.test.ts b/test/interfaces/args.test-types.ts similarity index 100% rename from test/interfaces/args.test.ts rename to test/interfaces/args.test-types.ts diff --git a/test/interfaces/flags.test.ts b/test/interfaces/flags.test-types.ts similarity index 100% rename from test/interfaces/flags.test.ts rename to test/interfaces/flags.test-types.ts