Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove false from version type, add fallback message #258

Merged
merged 3 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using || over ?? because in #256, the normalization turns pkg.version into an empty string.

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',
});