Skip to content

Commit

Permalink
Remove false from version type, add fallback message (#258)
Browse files Browse the repository at this point in the history
  • Loading branch information
tommy-mitchell authored Feb 29, 2024
1 parent a85c6e4 commit c00d5c5
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 1 addition & 3 deletions source/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,8 @@ export type Options<Flags extends AnyFlags> = {

/**
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.
Expand Down
2 changes: 1 addition & 1 deletion source/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down
1 change: 1 addition & 0 deletions source/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion test-d/build.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ expectType<Result<never>>(meow({importMeta, description: false}));
expectType<Result<never>>(meow({importMeta, help: 'foo'}));
expectType<Result<never>>(meow({importMeta, help: false}));
expectType<Result<never>>(meow({importMeta, version: 'foo'}));
expectType<Result<never>>(meow({importMeta, version: false}));
expectType<Result<never>>(meow({importMeta, autoHelp: false}));
expectType<Result<never>>(meow({importMeta, autoVersion: false}));
expectType<Result<never>>(meow({importMeta, pkg: {foo: 'bar'}}));
Expand Down
1 change: 0 additions & 1 deletion test-d/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ expectType<Result<never>>(meow({importMeta, description: false}));
expectType<Result<never>>(meow({importMeta, help: 'foo'}));
expectType<Result<never>>(meow({importMeta, help: false}));
expectType<Result<never>>(meow({importMeta, version: 'foo'}));
expectType<Result<never>>(meow({importMeta, version: false}));
expectType<Result<never>>(meow({importMeta, autoHelp: false}));
expectType<Result<never>>(meow({importMeta, autoVersion: false}));
expectType<Result<never>>(meow({importMeta, pkg: {foo: 'bar'}}));
Expand Down
8 changes: 7 additions & 1 deletion test/options/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
});

0 comments on commit c00d5c5

Please sign in to comment.