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

List values, shorthand flag with more than 1 character values #908

Closed
flyfishMT opened this issue Jan 18, 2019 · 4 comments
Closed

List values, shorthand flag with more than 1 character values #908

flyfishMT opened this issue Jan 18, 2019 · 4 comments

Comments

@flyfishMT
Copy link

I am having some issues, I may just not understand how this works. This is on windows 10.

Lists

program
.option('-c, --components <components>', 'List of components to create')
.parse(process.argv);

Test
index.js --components dir\one dir\two

Expected results:
program.components = ["dir\\one", "dir\\two"]
Actual:
program.components = "dir\\one";

Shorthand flag, more than one character:

program
  .option('-tf, --testfolder [testfolder]', 'Description')
  .parse(process.argv);

index.js --testfolder somefolder
Results
program.testfolder = "somefolder"

index.js -tf somefolder
Results
program.testfolder = undefined

However, with a single char:

program
  .option('-x, --testfolder [testfolder]', 'Description')
  .parse(process.argv);

index.js -x somefolder
Results
program.testfolder = "somefolder"

@flyfishMT flyfishMT changed the title List values List values, shorthand flag with more than 1 character values Jan 18, 2019
@shadowspawn
Copy link
Collaborator

shadowspawn commented Jan 19, 2019

  1. List: I think this may take a coercion to declare and turn the option parameter into an array. For example:
function splitComponents(val) {
  return val.split(',');
}

program
  .option('-c, --components <components>', 'List of components to create', splitComponents)

and call like:

node index.js --components dir\one,dir\two
  1. Short flags are a single character, with single leading dash. Multiple flags may be combined as mentioned in the README:

Short flags may be passed as a single arg, for example -abc is equivalent to -a -b -c.

  1. You asked about options, but on a related note about arguments, the last argument may be a variadic argument

@shadowspawn
Copy link
Collaborator

See also #913 for some other approaches to options taking lists.

@shadowspawn
Copy link
Collaborator

An answer was provided, and no further activity in a month. Closing this as resolved.

Feel free to open a new issue if it comes up again, with new information and renewed interest.

@flyfishMT
Copy link
Author

Thank you, this was great help. Sorry for not posting back and closing.

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