Dry-cli global options

Is there a way to specify global options?

Use case:

My tool works with pre-defined dir structures. There can be multiple such dirs. I want an option that can specify this directory and want it influence each subcommand.

Think git and gitdir. You can specify gitdir and it will have effect on all subcommands.

I’ve handled this by providing a “base” command class, which all the specific command classes should inherit from:

class BaseCommand < Hanami::CLI::Command
  def self.inherited(klass)
    super

    klass.option :env, aliases: ["-e"], default: nil, desc: "Application environment"
  end
end
1 Like

I assume this will let me specify options once but have them available in all commands. This is useful.

However, this doesn’t look like I’ll be able to specify any arguments before the subcommand. E.g. command --global-arg subcommand --arg.