cac
cac copied to clipboard
Short option property does not update when using long option
Issue Type
- [x] Bug Report
- [ ] Feature Request
- [ ] Other
Expected
I got such code:
cli.option('-b, --base-url <baseUrl>', 'Set the instance URL', {
default: 'https://github.com',
})
const opt = cli.parse()
console.log(opt)
When I run with --base-url "https://gitlab.com"
, I expect it to output such object:
{
args: [],
options: { '--': [], b: 'https://gitlab.com', baseUrl: 'https://gitlab.com' }
}
Actual
Instead it gives me this:
{
args: [],
options: { '--': [], b: 'https://github.com', baseUrl: 'https://gitlab.com' }
}
Info
- CAC version:
6.7.14
- Reproduction link: https://replit.com/@shanoaice/cac-short-opt-bug
This seems controversial at first, but I think he's right. They are two different flags, but the same option in the end and they should be getting the same default or value. I will take this on and see how far I can get.
The MR above fixes the issue when setting default
. However, I left intact the part where the underlying mri
library, used for option parsing, doesn't parse -b
if you only pass the --base-url
option, but parses both if -b
is passed. I hope this addresses the main problem which was in my opinion, setting the default to one of the names when the second (long version) is provided.