node-argp icon indicating copy to clipboard operation
node-argp copied to clipboard

Getting current command and/or argument a little unclear

Open moll opened this issue 10 years ago • 4 comments

Hey,

So far seems like a decent lib. At least the autogenerated help texts aren't an ugly mess of unnecessary whitespace they are in koolaid argparsers. :)

Anyways, I'm trying to create a simple CLI with commands. By calling the various methods on the Argp instance I've managed to set the necessary option requirements and commands. However, it's a little unclear, how does one get the command or argument name that was processed other than with a big messy if statement or resorting to process.argv iterating. I'm trying to keep things sequential rather than use events, too.

Let's say we're trying to emulate Git which can be called in the following way:

git --work-tree=/var/foo stash save --keep-index "Stash name"

How would you get a string stash for command and string save for subcommand/argument out of that with Argp?

In my testing, when setting stash as a command, the argv returned object also lists stash as an empty array besides the save array. Shouldn't stash contain all non-option args that come after it so you could at least shift it and get save?

I've skimmed the code in argp.js and it seems to also make an assumption that the command is always in the first position, rather than coming right after global options. Did I read that code correctly?

Thanks!

moll avatar Mar 30 '14 13:03 moll