Class: Dry::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/dry/cli.rb,
lib/dry/cli/usage.rb,
lib/dry/cli/banner.rb,
lib/dry/cli/errors.rb,
lib/dry/cli/inline.rb,
lib/dry/cli/option.rb,
lib/dry/cli/parser.rb,
lib/dry/cli/command.rb,
lib/dry/cli/version.rb,
lib/dry/cli/registry.rb,
lib/dry/cli/inflector.rb,
lib/dry/cli/program_name.rb,
lib/dry/cli/command_registry.rb

Overview

General purpose Command Line Interface (CLI) framework for Ruby

Since:

  • 0.1.0

Defined Under Namespace

Modules: Banner, Inflector, Inline, Parser, ProgramName, Registry, Usage Classes: Argument, Command, CommandRegistry, Error, InvalidCallbackError, Option, UnknownCommandError

Constant Summary collapse

VERSION =

Since:

  • 0.1.0

"1.0.0"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command_or_registry = nil, &block) ⇒ Dry::CLI

Create a new instance

Parameters:

Since:

  • 0.1.0



45
46
47
48
49
50
51
52
53
54
# File 'lib/dry/cli.rb', line 45

def initialize(command_or_registry = nil, &block)
  @kommand = command_or_registry if command?(command_or_registry)

  @registry =
    if block_given?
      anonymous_registry(&block)
    else
      command_or_registry
    end
end

Class Method Details

.command?(command) ⇒ TrueClass, FalseClass

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Check if command

Parameters:

  • command (Object)

    the command to check

Returns:

  • (TrueClass, FalseClass)

    true if instance of ‘Dry::CLI::Command`

Since:

  • 0.1.0



28
29
30
31
32
33
34
35
# File 'lib/dry/cli.rb', line 28

def self.command?(command)
  case command
  when Class
    command.ancestors.include?(Command)
  else
    command.is_a?(Command)
  end
end

Instance Method Details

#call(arguments: ARGV, out: $stdout, err: $stderr) ⇒ Object

Invoke the CLI

Parameters:

  • arguments (Array<string>) (defaults to: ARGV)

    the command line arguments (defaults to ‘ARGV`)

  • out (IO) (defaults to: $stdout)

    the standard output (defaults to ‘$stdout`)

  • err (IO) (defaults to: $stderr)

    the error output (defaults to ‘$stderr`)

Since:

  • 0.1.0



63
64
65
66
67
68
69
70
# File 'lib/dry/cli.rb', line 63

def call(arguments: ARGV, out: $stdout, err: $stderr)
  @out, @err = out, err
  kommand ? perform_command(arguments) : perform_registry(arguments)
rescue SignalException => e
  signal_exception(e)
rescue Errno::EPIPE
  # no op
end