Skip to content

Commit

Permalink
Merge pull request #753 from oclif/sm/scoped-env-var-CONTENT_TYPE
Browse files Browse the repository at this point in the history
fix: allow CONTENT_TYPE env to work for all oclif cmds
  • Loading branch information
WillieRuemmele authored Aug 3, 2023
2 parents 599b234 + 378a4f7 commit b25ed8d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}

/**
Expand Down
16 changes: 16 additions & 0 deletions test/command/command.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit b25ed8d

Please sign in to comment.