Class: Dry::CLI
- Inherits:
-
Object
- Object
- Dry::CLI
- 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
Defined Under Namespace
Modules: Banner, Inflector, Inline, Parser, ProgramName, Registry, Usage Classes: Argument, Command, CommandRegistry, Error, InvalidCallbackError, Option, UnknownCommandError
Constant Summary collapse
- VERSION =
"1.1.0"
Class Method Summary collapse
-
.command?(command) ⇒ TrueClass, FalseClass
private
Check if command.
Instance Method Summary collapse
-
#call(arguments: ARGV, out: $stdout, err: $stderr) ⇒ Object
Invoke the CLI.
-
#initialize(command_or_registry = nil, &block) ⇒ Dry::CLI
constructor
Create a new instance.
Constructor Details
#initialize(command_or_registry = nil, &block) ⇒ Dry::CLI
Create a new instance
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
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
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 |