cac icon indicating copy to clipboard operation
cac copied to clipboard

Short option property does not update when using long option

Open shanoaice opened this issue 2 years ago • 2 comments

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

shanoaice avatar Jan 06 '23 03:01 shanoaice

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.

Rendez avatar Mar 01 '23 13:03 Rendez

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.

Rendez avatar Mar 02 '23 10:03 Rendez