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/spell_checker.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, SpellChecker, Usage Classes: Argument, Command, CommandRegistry, Error, InvalidCallbackError, Option, UnknownCommandError
Constant Summary collapse
- VERSION =
"1.2.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
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/dry/cli.rb', line 46 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
29 30 31 32 33 34 35 36 |
# File 'lib/dry/cli.rb', line 29 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
64 65 66 67 68 69 70 71 |
# File 'lib/dry/cli.rb', line 64 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 |