diff --git a/readme.md b/readme.md index 7f51362..61d585b 100644 --- a/readme.md +++ b/readme.md @@ -161,7 +161,7 @@ The description will be shown above your help text automatically. ##### version -Type: `string | boolean`\ +Type: `string`\ Default: The package.json `"version"` property Set a custom version output. diff --git a/source/index.d.ts b/source/index.d.ts index 5fa3b34..7da71ae 100644 --- a/source/index.d.ts +++ b/source/index.d.ts @@ -180,10 +180,8 @@ export type Options = { /** Set a custom version output. Default: The package.json `"version"` property. - - Set it to `false` to disable it altogether. */ - readonly version?: string | false; + readonly version?: string; /** Automatically show the help text when the `--help` flag is present. Useful to set this value to `false` when a CLI manages child CLIs with their own help text. diff --git a/source/index.js b/source/index.js index 7881e24..da32775 100644 --- a/source/index.js +++ b/source/index.js @@ -36,7 +36,7 @@ const buildResult = (options, parserOptions) => { }; const showVersion = () => { - console.log(typeof options.version === 'string' ? options.version : package_.version); + console.log(options.version); process.exit(0); }; diff --git a/source/options.js b/source/options.js index d46d317..69d3edf 100644 --- a/source/options.js +++ b/source/options.js @@ -75,6 +75,7 @@ export const buildOptions = (helpText, options) => { inferType: false, input: 'string', help: helpText, + version: foundPackage?.packageJson.version || 'No version found', autoHelp: true, autoVersion: true, booleanDefault: false, diff --git a/test-d/build.test-d.ts b/test-d/build.test-d.ts index 29ec7de..f05ae20 100644 --- a/test-d/build.test-d.ts +++ b/test-d/build.test-d.ts @@ -40,7 +40,6 @@ expectType>(meow({importMeta, description: false})); expectType>(meow({importMeta, help: 'foo'})); expectType>(meow({importMeta, help: false})); expectType>(meow({importMeta, version: 'foo'})); -expectType>(meow({importMeta, version: false})); expectType>(meow({importMeta, autoHelp: false})); expectType>(meow({importMeta, autoVersion: false})); expectType>(meow({importMeta, pkg: {foo: 'bar'}})); diff --git a/test-d/index.test-d.ts b/test-d/index.test-d.ts index aa5bf91..a1d0f65 100644 --- a/test-d/index.test-d.ts +++ b/test-d/index.test-d.ts @@ -40,7 +40,6 @@ expectType>(meow({importMeta, description: false})); expectType>(meow({importMeta, help: 'foo'})); expectType>(meow({importMeta, help: false})); expectType>(meow({importMeta, version: 'foo'})); -expectType>(meow({importMeta, version: false})); expectType>(meow({importMeta, autoHelp: false})); expectType>(meow({importMeta, autoVersion: false})); expectType>(meow({importMeta, pkg: {foo: 'bar'}})); diff --git a/test/options/version.js b/test/options/version.js index 29b5f28..576a6a6 100644 --- a/test/options/version.js +++ b/test/options/version.js @@ -38,10 +38,16 @@ test('custom version', verifyVersion, { test('version = false has no effect', verifyVersion, { args: '--version', execaOptions: {env: {VERSION: 'false'}}, - expected: '1.0.0', + expected: 'false', }); test('manual showVersion', verifyVersion, { args: '--show-version', expected: '1.0.0', }); + +test('no version fallback message', verifyVersion, { + fixture: 'with-package-json/default/fixture.js', + args: '--version', + expected: 'No version found', +});