From 71db0dc63ad5d4a43df72ac4a040df2d92d3b0e1 Mon Sep 17 00:00:00 2001 From: mshanemc Date: Mon, 31 Jul 2023 13:02:34 -0500 Subject: [PATCH 1/3] fix: allow CONTENT_TYPE env to work for all oclif cmds --- src/command.ts | 2 +- test/command/command.test.ts | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) 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..f10d1cfd4 100644 --- a/test/command/command.test.ts +++ b/test/command/command.test.ts @@ -1,6 +1,6 @@ import {expect, fancy} from 'fancy-test' // import path = require('path') -import {Args, Command as Base, Flags, toCached} from '../../src' +import {Args, Command as Base, Config, Flags, toCached} from '../../src' // import {TestHelpClassConfig} from './helpers/test-help-in-src/src/test-help-plugin' // const pjson = require('../package.json') @@ -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 () => { From a5d267f21c2523d066d6410dd83d994cc8782d75 Mon Sep 17 00:00:00 2001 From: mshanemc Date: Mon, 31 Jul 2023 14:37:35 -0500 Subject: [PATCH 2/3] test: don't try to execute tds "tests" --- test/interfaces/{args.test.ts => args.test-types.ts} | 0 test/interfaces/{flags.test.ts => flags.test-types.ts} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename test/interfaces/{args.test.ts => args.test-types.ts} (100%) rename test/interfaces/{flags.test.ts => flags.test-types.ts} (100%) 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 From 378a4f71583b4fb424dc38b192172ab759eed7e1 Mon Sep 17 00:00:00 2001 From: mshanemc Date: Mon, 31 Jul 2023 14:38:05 -0500 Subject: [PATCH 3/3] test: remove Config import --- test/command/command.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/command/command.test.ts b/test/command/command.test.ts index f10d1cfd4..ecade0257 100644 --- a/test/command/command.test.ts +++ b/test/command/command.test.ts @@ -1,6 +1,6 @@ import {expect, fancy} from 'fancy-test' // import path = require('path') -import {Args, Command as Base, Config, Flags, toCached} from '../../src' +import {Args, Command as Base, Flags, toCached} from '../../src' // import {TestHelpClassConfig} from './helpers/test-help-in-src/src/test-help-plugin' // const pjson = require('../package.json')