denisdefreyne / cri

A tool for building commandline applications
MIT License
120 stars 19 forks source link

Subcommand where the root command has an option #80

Closed anibalrojas closed 6 years ago

anibalrojas commented 6 years ago

Is it possible to implement something like command --option subcommand --another-option?

There is an option in my design that is "common" to all subcommands, for me it makes sense to be passed to the root command instead of repeating its definition in all subcommand blocks. For sure I could use a helper, but the pattern I am proposing looks better to me. Thanks in advance.

denisdefreyne commented 6 years ago

Hi,

Cri supports this. Take a look at samples/sample_nested.rb for example:

$ bundle
$ bundle exec ruby samples/sample_nested.rb -d sub -e -p
[snip]
options:   {:ddd=>true, :eee=>true, :ppp=>true}

Options that apply to the root command can be passed before the subcommand (as in -d), but also after (as in -e). Options that apply to the subcommand can only be passed after the subcommand (as in -p).

anibalrojas commented 6 years ago

Perfect, thanks a lot for your quick answer.