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

Default value type not applied to aliases #10

Closed
andrewiggins opened this issue Mar 24, 2020 · 2 comments
Closed

Default value type not applied to aliases #10

andrewiggins opened this issue Mar 24, 2020 · 2 comments

Comments

@andrewiggins
Copy link

Hey Luke 👋

Related: lukeed/sade#17

Was using sade in a project where I wanted an option to be coerced to a string always, so I specified that a default value of "". However I noticed that when using the alias of the option, the value was not turned into a string (repo below). For me, the use case is for simple file matching, where some file names may begin with a number. So the option may be passed a value of "01" and I want that as a string, not the number 1.

I think lukeed/sade#17 is related to what I want here, but seeing as how that issue is old and closed without discussion I thought maybe opening a new issue focused around the use case would be helpful. Apologies if I thought wrong here 😬

Repo

test.js:

const sade = require("sade"); // v1.7.3

// Using `isOne` just to simplify this program
const { args } = sade("test", true)
  .option("-a --arg", "Test option", "")
  .parse(process.argv, { lazy: true });

console.log(args);

Output with --arg:

$ node .\test.js --arg 01
[ { _: [], arg: '01', a: '01' } ]

Output with -a alias:
(expected to be the same as --arg output)

$ node .\test.js -a 01   
[ { _: [], a: 1, arg: 1 } ]

If you think this is something that should/can be fixed, happy to open a PR. My assumption is that we need to pass defaults for option names and aliases to mri?

Thanks!

P.S. Love all awesome libraries you build - thanks for giving these to us 😁

@lukeed
Copy link
Owner

lukeed commented Mar 24, 2020

Thank you :)

Can't remember why I closed that. I think I thought I fixed it? Clearly not, though.

This is actually a mri bug & so I'll transfer this over there. Thanks!

@lukeed lukeed transferred this issue from lukeed/sade Mar 24, 2020
@lukeed lukeed closed this as completed in 5437ea5 Mar 24, 2020
@lukeed
Copy link
Owner

lukeed commented Mar 24, 2020

Released within [email protected] and should be picked up in your next sade install too.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants