Commands

A command is a subclass of Dry::CLI::Command and it must respond to #call(*).

For a given command name, you can register a corresponding command.

Please note: there is no convention between the command name and the command object class name. The manual registration assigns a command object to a command name.

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

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

      class Hello < Dry::CLI::Command
        def call(*)
        end
      end
    end
  end
end

class Version < Dry::CLI::Command
  def call(*)
  end
end

Foo::CLI::Commands.register "hi", Foo::CLI::Commands::Hello
Foo::CLI::Commands.register "v",  Version

Dry::CLI.new(Foo::CLI::Commands).call

octocatEdit on GitHub