Subcommands

There is nothing special about subcommands, they are simply command objects registered under a nested command name:

#!/usr/bin/env ruby
require "bundler/setup"
require "dry/cli"

module Foo
  module CLI
    module Commands
      extend Dry::CLI::Registry

      module Generate
        class Configuration < Dry::CLI::Command
          def call(*)
          end
        end
      end
    end
  end
end

Foo::CLI::Commands.register "generate configuration", Foo::CLI::Commands::Generate::Configuration

Dry::CLI.new(Foo::CLI::Commands).call
$ foo generate
Commands:
  foo generate config           # Generate configuration

octocatEdit on GitHub