Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

Arguments that have custom parsers throw missing argument errors when the parsed value is falsy #112

Closed
gkovalechyn opened this issue Jul 25, 2020 · 1 comment · Fixed by #114

Comments

@gkovalechyn
Copy link

In my project I have a simple command to delete an element by its index, but when the argument is "0" and is parsed to a number through a custom parser the validator fails due to a missing argument exception.

Example:

import { Command } from "@oclif/command";

export default class TestCommand extends Command {
	static description = "Throws a missing argument exception when the argument is 0";

	static args = [
		{
			name: "value",
			required: true,
			description: "A number",
			parse: (value: string): number => parseInt(value, 10)
		}
	];

	public async run(): Promise<void> {
		const { args } = this.parse(TestCommand);

		this.log(`Received: ${args.value}`);
	}
}

Running the command with the argument "0" it will throw an exception with saying it has a missing value even though it was provided while running it with the argument "1" will run the command successfuly.

It seems to be caused by this comparison:

if (!parse.output.argv[index]) {

@RasPhilCo
Copy link
Contributor

Good catch!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants