jednano / gitlike-cli

A git-like CLI library for Node.js
16 stars 2 forks source link

Optional option argument #4

Closed naitian closed 6 years ago

naitian commented 8 years ago

In the coercion example, the command argument is required, but the -o option has an optional argument.

While ./coercion -o value file1.txt works (and logs options.optional: "value" and args.file: ["file1.txt"]), running ./coercion -o file1.txt throws a "Missing required arguments" error, even though the optional option does not have a required argument.

Am I typing the command/arguments incorrectly or does the library not support this?

jednano commented 8 years ago

I think this is the test that covers that use case.

Can you show me your whole program?

naitian commented 8 years ago

Thanks for the quick response! I was looking at the coercion example in the examples directory.

I think these are the two relevant blocks of code:

program
  .usage('<files>...')
  .option('-s, --square <x>', 'A square of x', square)
  .option('-r, --range <a>..<b>', 'A range', range)
  .option('-l, --list <items>', 'A list', list)
  .option('-o, --optional [value]', 'An optional value')
  .parse(process.argv);

var options = program.options;
console.log(' options.optional: %j', options.optional);
console.log(' args.files: %j', program.args.files);
jednano commented 8 years ago

It looks like it could definitely be a bug. Can you submit a breaking test in the form of a pull request?

naitian commented 8 years ago

Sorry, but I am unsure of what you mean? Could you clarify or provide an example? Thanks!

jednano commented 8 years ago

Have you submitted a pull request before?

naitian commented 8 years ago

Oh, yeah, I get the pull request part. It's writing the test that I'm not familiar with.

On Wed, Dec 30, 2015, 2:33 AM Jed Mao notifications@github.com wrote:

Have you submitted a pull request before?

— Reply to this email directly or view it on GitHub https://github.com/jedmao/gitlike-cli/issues/4#issuecomment-167951332.

jednano commented 8 years ago

There are already tests in this project. All you would need to do is add a use-case where the test fails. Then, a commit could be added to fix that fail case.

jednano commented 6 years ago

@naitian I'm going to close this issue for now, because you haven't provided a failing test case for what your expectations should be. Feel free to re-open if/when you decide to entertain this idea again.