cacjs / cac

Simple yet powerful framework for building command-line apps.
MIT License
2.65k stars 104 forks source link

Required option not working as expected #107

Closed Codpoe closed 3 years ago

Codpoe commented 3 years ago

Issue Type

Expected

cli
  .command('create [dir]')
  .option('--template <template>')

If I didn't pass the template, it should throw an error like:option "template" value is missing.

Actual

No error, continue to execute

Possible Solutions

Command.ts - checkOptionValue

Info

0x009922 commented 3 years ago

@Codpoe, why this issue is closed? I've faced with this problem too.

Codpoe commented 3 years ago

@0x009922 In the case I mentioned above, if my usage is:

create --template

It will throw an error. That is, if you write a argument name but don’t include a value, it will report an error. And I think it was the right thing to do, so I closed the issue.

But on the whole, I think it would be better if cac could support something like requiredOption in commander. Maybe like this:

cli
  .command('create [dir]')
  .option('--template <template>', { required: true });
0x009922 commented 3 years ago

@Codpoe, I agree with you about requiredOption, it look's like really missing feature.

aleclarson commented 2 years ago

https://www.npmjs.com/package/@cac/required-option