linghuaj / node-proxy-server

[CodePath] Proxy server created for node camp
1 stars 0 forks source link

[bonus question]how to handle argv for space seperated values? #2

Open linghuaj opened 9 years ago

linghuaj commented 9 years ago

Hi @codepathreview @codepath I have a question about the prework for the bonus part one.(allow child process for the process) The questions asks you to "bode index --exec grep require"

but the second part of the arguments get pushed to a anonymous property when i took a took at argv.exec.

bode index --exec grep require niuniu -x niuniu2 niuniu3

I'm trying something like this, and i was expecting in my code, i am able to get something like

exec: ['grep', 'require']
x:['niuniu2', 'niuniu3']

but instead, i'm getting

argv { _: [ 'require', 'niuniu', 'niuniu3' ],
  exec: 'grep',
  x: 'niuniu2',
  host: 'localhost',
  '$0': 'index' }

where all the space seperated values are pushed in to one arr. Any suggestion?

thanks

CrabDude commented 9 years ago

Unfortunately, no. .nargs(key, number) let's you grab a array of values and hardcoded length for a given flag, but it doesn't support variadic flags unfortunately.

You can however use another package! Checkout the variadic argument support in commander (an even more popular and powerful options parsing library).

linghuaj commented 9 years ago

Hey @CrabDude

Thanks a lot for the answer, I'll give it a try

linghuaj commented 9 years ago

@CrabDude hey adam, I took a look through commander documentation. looks like commander only support last argument as variadic.

"The last argument of a command can be variadic, and only the last argument. To make an argument variadic you have to append ... to the argument name."

CrabDude commented 9 years ago

Ah, yes. That's unfortunate. At that point would need to implement the functionality yourself if you wanted to support multiple variadic arguments.

On Tuesday, April 28, 2015, Linghua Jin notifications@github.com wrote:

@CrabDude https://github.com/CrabDude hey adam, I took a look through commander documentation. looks like commander only support last argument as variadic.

"The last argument of a command can be variadic, and only the last argument. To make an argument variadic you have to append ... to the argument name."

— Reply to this email directly or view it on GitHub https://github.com/vanessachem/codpath-proxy-server/issues/2#issuecomment-97208894 .

Adam Crabtree Noderiety PO Box 3823 Los Altos, CA 94024 Telephone: _(_469) 777-8415 https://mail.google.com/ Email: dude@noderiety.com

This e-mail message is intended for the use of the addressee(s) only and may contain information that is privileged-confidential and exempt from disclosure under applicable law. If the reader of the message is not the intended recipient or agent responsible for delivering the message to the intended recipient, you are hereby notified that any review, dissemination, distribution or copying of this communication is strictly prohibited. If you receive this communication in error, please notify us immediately by reply e-mail and delete the original message. Thank you.