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

Document ability to disable numeric conversion for positional arguments (non-options) #52

Closed
shadowspawn opened this issue Nov 25, 2023 · 2 comments · Fixed by #53
Closed
Labels
documentation Improvements or additions to documentation

Comments

@shadowspawn
Copy link
Collaborator

It is possible to disable the automatic conversion to numbers for positional arguments, and not just for options:

const argv = minimist(process.argv.slice(2), {
   string: ['_'] // disable numeric conversion of positional arguments (non-options)

I think worth documenting as it does fill out the control over conversions. (Although it does feel a bit of a trick.)

Background: I didn't realise this was possible until shown in: #51 (comment)

@shadowspawn
Copy link
Collaborator Author

shadowspawn commented May 11, 2024

For historical interest, was a related issue on the original Minimist repo asking for this functionality, with multiple comments and some upvotes:

Add option to disable numeric conversion for arguments
https://web.archive.org/web/20200904203043/https://github.com/substack/minimist/issues/36


var argv = require('minimist')(process.argv.slice(2));

console.dir(argv);

If I invoke my command using my-command 2.0, I end up with something like this:

{ _: [ 2 ]}

I realize if this was an option I could use opts.string to tell minimist to treat my option as a string but how can I do this for arguments? This is very similar to issue minimist/issues/21 but the difference is that minimist/issues/21 could be fixed using a minimist option while I see no option for minimist arguments.

@shadowspawn
Copy link
Collaborator Author

shadowspawn commented May 11, 2024

And another historical issue suggesting should be documented:

Document that rest arguments have their type inferred too
https://web.archive.org/web/20200904203142/https://github.com/substack/minimist/issues/32


I was not expecting rest arguments to have their type inferred. Might be a good idea to make that clear.

Also show how to force rest arguments to a specific type:

require('minimist')(process.argv.slice(2), {string: ['_']})

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

Successfully merging a pull request may close this issue.

1 participant