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

Consider using optimist for command options parsing #96

Open
mstade opened this issue Sep 19, 2012 · 2 comments
Open

Consider using optimist for command options parsing #96

mstade opened this issue Sep 19, 2012 · 2 comments

Comments

@mstade
Copy link
Contributor

mstade commented Sep 19, 2012

Volo provides some mechanism for passing arguments to volo commands, but it's fairly limited. Would you consider incorporating something like optimist into volo? It's currently not possible to use optimist for options parsing, since process.argv inside of a volofile or command doesn't contain the arguments passed on the command line.

Since volo already recognizes the flags property in commands, maybe that could be used to leverage some of the fancier features of optimist, such as defaults and validation?

@jrburke
Copy link
Member

jrburke commented Sep 25, 2012

What is not possible with the existing command line parsing in volo? Commands can implement a "validate" method to validate the values that are parsed, for example.

Also, right now the flags mechanism allows either -flag or --flag, and translating a short -f to a flag boolean value. Not a big thing though, just trying to list out what may be issues in the conversion.

I'm not opposed to switching to optimist, but want to know how things will change, what is gained/lost.

@mstade
Copy link
Contributor Author

mstade commented Oct 1, 2012

I don't think anything is lost really, more gained. For instance, it'll properly handle things like -multi and it would correctly expand to -m -u -l -t -i. Flags can be negated with the --no- convention, default values can be assigned with less typing, -- is understood as an instruction to stop parsing, complex arguments like --foo.bar will be turned into an object graph etc. As far as I can tell, there are no features that volo currently support that would be lost with optimist, but plenty that would be gained.

If you don't want to tie volo to optimist, I guess it could be hidden as an implementation detail, and just having people provide a map, much like flags but more powerful. Call it a new key, options or args or something and you've got less hassle with backwards compatibility.

Another option is to not parse things altogether and just provide the argv object, or provide it in addition to whatever parsing volo does, so people can use whatever parsing method they like. It may make things a bit inconsistent (different commands parsing things differently) but wouldn't tie volo to anything then.

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