# Dry-cli global options

**URL:** <https://discourse.dry-rb.org/t/dry-cli-global-options/1081>\
**Category:** Support\
**Created:** [June 29, 2020, 6:22pm UTC](https://discourse.dry-rb.org/t/dry-cli-global-options/1081 "2020-06-29T18:22:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pointlessone](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/pointlessone/32/537_2.png) [@pointlessone](https://discourse.dry-rb.org/u/pointlessone)\
**Post date:** [June 29, 2020, 6:22pm UTC](https://discourse.dry-rb.org/t/dry-cli-global-options/1081/1 "2020-06-29T18:22:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![timriley](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/timriley/32/25_2.png) [@timriley](https://discourse.dry-rb.org/u/timriley)\
**Post date:** [July 2, 2020, 4:30am UTC](https://discourse.dry-rb.org/t/dry-cli-global-options/1081/2 "2020-07-02T04:30:38Z")

</div>

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

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

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

```

---

<div class="post-metadata">

**Author:** ![pointlessone](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/pointlessone/32/537_2.png) [@pointlessone](https://discourse.dry-rb.org/u/pointlessone)\
**Post date:** [July 3, 2020, 10:42am UTC](https://discourse.dry-rb.org/t/dry-cli-global-options/1081/3 "2020-07-03T10:42:26Z")

</div>

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`.

---

<div class="post-metadata">

**Author:** ![IvanShamatov](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/ivanshamatov/32/601_2.png) [@IvanShamatov](https://discourse.dry-rb.org/u/IvanShamatov)\
**Post date:** [February 5, 2021, 10:11am UTC](https://discourse.dry-rb.org/t/dry-cli-global-options/1081/4 "2021-02-05T10:11:15Z")

</div>

Options are unsorted array of strings, there is no difference in which order you type them.  
Though OptParser will think of string after option as a value for that option.

–global-arg subcommand # this will be translated in option with the key global-arg and value of subcommand
