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

oclif rejects empty string given for required argument #982

Closed
rrthomas opened this issue Apr 25, 2021 · 3 comments · Fixed by #983
Closed

oclif rejects empty string given for required argument #982

rrthomas opened this issue Apr 25, 2021 · 3 comments · Fixed by #983
Labels
bug Something isn't working

Comments

@rrthomas
Copy link
Contributor

Do you want to request a feature or report a bug?

Report a bug

What is the current behavior?

oclif rejects an empty string argument when a string argument is requried

Example code:

import {Command, flags} from '@oclif/command'

class Foo extends Command {
  static description = 'describe the command here'

  static args = [{name: 'file', required: true}]

  async run() {
    const {args, flags} = this.parse(Foo)
  }
}

export = Foo

Example output:

$ ./bin/run
 ›   Error: Missing 1 required arg:
 ›   file
 ›   See more help with --help
$ ./bin/run ''
 ›   Error: Missing 1 required arg:
 ›   file
 ›   See more help with --help
$ ./bin/run 'foo'
$

The first error is expected (we omitted the argument). The second is not (we supplied an empty string as argument). In the 3rd case, the command succeeds as expected.

What is the expected behavior?

An empty string argument should be accepted.

I'm using oclif/command 1.8.0 on Ubuntu 20.04.

@derekhe
Copy link

derekhe commented Jul 22, 2021

Yes, this is the issue. I'm implementing npm-deprecate like command, the requirement is:

To un-deprecate a package, specify an empty string ("") for the message argument. Note that you must use double quotes with no space between them to format an empty string.

I can't do this in oclif if I mark the message as required

@mdonnalley mdonnalley transferred this issue from oclif/oclif Mar 1, 2024
@mdonnalley mdonnalley added the bug Something isn't working label Mar 1, 2024
Copy link

git2gus bot commented Mar 1, 2024

This issue has been linked to a new work item: W-15161625

@rrthomas
Copy link
Contributor Author

rrthomas commented Mar 4, 2024

Many thanks for fixing this issue! I used argparse for the project I was working on 3 years ago, as oclif had this problem, and yargs had another similar edge case which their devs marked WONTFIX (single - passed as positional arg disappeared), so it's good to know that in future I can just use oclif again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants