diff --git a/src/config/plugin.ts b/src/config/plugin.ts index 09be87e44..8b352a569 100644 --- a/src/config/plugin.ts +++ b/src/config/plugin.ts @@ -65,18 +65,10 @@ function determineCommandDiscoveryOptions( return {globPatterns: GLOB_PATTERNS, strategy: 'pattern', target: commandDiscovery} } - if (commandDiscovery.strategy === 'explicit') { - if (!commandDiscovery.target) throw new CLIError('`oclif.commandDiscovery.target` is required.') - return commandDiscovery - } - - if (commandDiscovery.strategy === 'pattern') { - if (!commandDiscovery.target) { - throw new CLIError('`oclif.commandDiscovery.target` is required.') - } + if (!commandDiscovery.target) throw new CLIError('`oclif.commandDiscovery.target` is required.') + if (!commandDiscovery.strategy) throw new CLIError('`oclif.commandDiscovery.strategy` is required.') - return commandDiscovery - } + return commandDiscovery } type CommandExportModule = { diff --git a/test/command/explicit-command-strategy.test.ts b/test/command/explicit-command-strategy.test.ts index 623e8a697..c8085f314 100644 --- a/test/command/explicit-command-strategy.test.ts +++ b/test/command/explicit-command-strategy.test.ts @@ -26,8 +26,9 @@ USAGE $ oclif foo COMMAND COMMANDS - foo bar foo bar description - foo baz foo baz description + foo alias foo bar description + foo bar foo bar description + foo baz foo baz description `) }) @@ -36,4 +37,9 @@ COMMANDS await run(['foo:bar'], resolve(__dirname, 'fixtures/explicit-commands/package.json')) expect(stdoutStub.firstCall.firstArg).to.equal('hello world!\n') }) + + it('should run alias', async () => { + await run(['foo:alias'], resolve(__dirname, 'fixtures/explicit-commands/package.json')) + expect(stdoutStub.firstCall.firstArg).to.equal('hello world!\n') + }) }) diff --git a/test/command/fixtures/explicit-commands/package.json b/test/command/fixtures/explicit-commands/package.json index 5984450f0..c96e8e813 100644 --- a/test/command/fixtures/explicit-commands/package.json +++ b/test/command/fixtures/explicit-commands/package.json @@ -24,9 +24,5 @@ } } } - }, - "devDependencies": { - "globby": "^8.0.1", - "ts-node": "^6.0.2" } } diff --git a/test/command/fixtures/explicit-commands/src/commands.ts b/test/command/fixtures/explicit-commands/src/commands.ts index 46853dba1..c80593378 100644 --- a/test/command/fixtures/explicit-commands/src/commands.ts +++ b/test/command/fixtures/explicit-commands/src/commands.ts @@ -4,4 +4,5 @@ import FooBaz from './commands/foo/baz' export default { 'foo:bar': FooBar, 'foo:baz': FooBaz, + 'foo:alias': FooBar, } diff --git a/test/command/fixtures/single-cmd-cli/package.json b/test/command/fixtures/single-cmd-cli/package.json new file mode 100644 index 000000000..aab6f1da7 --- /dev/null +++ b/test/command/fixtures/single-cmd-cli/package.json @@ -0,0 +1,10 @@ +{ + "name": "single-cmd-cli", + "version": "0.0.0", + "description": "Single Command CLI", + "private": true, + "oclif": { + "default": ".", + "commands": "./dist" + } +} diff --git a/test/command/fixtures/single-cmd-cli/src/index.ts b/test/command/fixtures/single-cmd-cli/src/index.ts new file mode 100644 index 000000000..4a11aea3a --- /dev/null +++ b/test/command/fixtures/single-cmd-cli/src/index.ts @@ -0,0 +1,9 @@ +// eslint-disable-next-line node/no-unpublished-import +import {Command} from '../../../../../src/index' + +export default class FooBar extends Command { + public static description = 'Description of single command CLI.' + public async run(): Promise<void> { + this.log('hello world!') + } +} diff --git a/test/command/fixtures/single-cmd-cli/tsconfig.json b/test/command/fixtures/single-cmd-cli/tsconfig.json new file mode 100644 index 000000000..968ea6fbe --- /dev/null +++ b/test/command/fixtures/single-cmd-cli/tsconfig.json @@ -0,0 +1,7 @@ +{ + "compilerOptions": { + "outDir": "dist", + "rootDirs": ["./src"] + }, + "include": ["./src/**/*"] +} diff --git a/test/command/fixtures/typescript/package.json b/test/command/fixtures/typescript/package.json index a0605a200..abfdf0c88 100644 --- a/test/command/fixtures/typescript/package.json +++ b/test/command/fixtures/typescript/package.json @@ -21,9 +21,5 @@ } } } - }, - "devDependencies": { - "globby": "^8.0.1", - "ts-node": "^6.0.2" } } diff --git a/test/command/single-command-cli.test.ts b/test/command/single-command-cli.test.ts new file mode 100644 index 000000000..564b67190 --- /dev/null +++ b/test/command/single-command-cli.test.ts @@ -0,0 +1,38 @@ +import {expect} from 'chai' +import {resolve} from 'node:path' +import {SinonSandbox, SinonStub, createSandbox} from 'sinon' +import stripAnsi from 'strip-ansi' + +import {run, ux} from '../../src/index' + +describe('single command cli', () => { + let sandbox: SinonSandbox + let stdoutStub: SinonStub + + beforeEach(() => { + sandbox = createSandbox() + stdoutStub = sandbox.stub(ux.write, 'stdout') + }) + + afterEach(() => { + sandbox.restore() + }) + + it('should show help for commands', async () => { + await run(['--help'], resolve(__dirname, 'fixtures/single-cmd-cli/package.json')) + expect(stdoutStub.args.map((a) => stripAnsi(a[0])).join('')).to.equal(`Description of single command CLI. + +USAGE + $ single-cmd-cli . + +DESCRIPTION + Description of single command CLI. + +`) + }) + + it('should run command', async () => { + await run([], resolve(__dirname, 'fixtures/single-cmd-cli/package.json')) + expect(stdoutStub.firstCall.firstArg).to.equal('hello world!\n') + }) +})