From c00d5c5570a1c0ba9923a17c969fe04873413d8f Mon Sep 17 00:00:00 2001 From: Tommy Date: Wed, 28 Feb 2024 21:49:30 -0600 Subject: [PATCH] Remove `false` from `version` type, add fallback message (#258) --- readme.md | 2 +- source/index.d.ts | 4 +--- source/index.js | 2 +- source/options.js | 1 + test-d/build.test-d.ts | 1 - test-d/index.test-d.ts | 1 - test/options/version.js | 8 +++++++- 7 files changed, 11 insertions(+), 8 deletions(-) diff --git a/readme.md b/readme.md index dc0cddc..ec553f5 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 a2ef9f1..b8f194f 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 515a4b4..ce26a8c 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 9d43722..9d06253 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', +});