commander-rb / commander

The complete solution for Ruby command-line executables
MIT License
821 stars 74 forks source link

Nesting options or adding flags to options? #34

Closed lebogan closed 8 years ago

lebogan commented 8 years ago

Does this even make sense?:

I'm building a simple Sinatra application builder with Commander. On my option to build with the inline method, I want to choose between Slim or Erb. It would go something like this:

$ sincab init --inline -s myapp
or
$ sincab init --inline -e myapp

Those two flags would only belong to the --inline option.

Thanks for any thoughts on this.

ggilder commented 8 years ago

It's an interesting use case — albeit one that almost seems too complicated for a command-line tool 😉

In general I don't think I've seen a command-line app framework that supports something like this, but there's a few workarounds I've seen:

  1. Each of the flags is just a normal option, and your command does some validation, e.g. raise an error if you use -s without --inline, or raise an error if you use --inline without one of the -s/-e flags
  2. Flatten the nesting so that instead of --inline you have --inline-slim and --inline-erb
lebogan commented 8 years ago

As always, thanks for your insight. Commander can handle this!:-) I'm testing both options so I will close this issue.