Class: Hanami::CLI
- Inherits:
-
Object
- Object
- Hanami::CLI
- Defined in:
- lib/hanami/cli.rb,
lib/hanami/cli/usage.rb,
lib/hanami/cli/banner.rb,
lib/hanami/cli/errors.rb,
lib/hanami/cli/option.rb,
lib/hanami/cli/parser.rb,
lib/hanami/cli/command.rb,
lib/hanami/cli/version.rb,
lib/hanami/cli/registry.rb,
lib/hanami/cli/program_name.rb,
lib/hanami/cli/command_registry.rb
Overview
General purpose Command Line Interface (CLI) framework for Ruby
Defined Under Namespace
Modules: Banner, Parser, ProgramName, Registry, Usage Classes: Argument, Command, CommandRegistry, Error, InvalidCallbackError, Option, UnknownCommandError
Constant Summary collapse
- VERSION =
"0.3.1".freeze
Class Method Summary collapse
-
.command?(command) ⇒ TrueClass, FalseClass
private
Check if command.
- .const_missing(name) ⇒ Object
Instance Method Summary collapse
-
#call(arguments: ARGV, out: $stdout) ⇒ Object
Invoke the CLI.
-
#initialize(registry) ⇒ Hanami::CLI
constructor
Create a new instance.
Constructor Details
#initialize(registry) ⇒ Hanami::CLI
Create a new instance
40 41 42 |
# File 'lib/hanami/cli.rb', line 40 def initialize(registry) @commands = registry 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
25 26 27 28 29 30 31 32 |
# File 'lib/hanami/cli.rb', line 25 def self.command?(command) case command when Class command.ancestors.include?(Command) else command.is_a?(Command) end end |
.const_missing(name) ⇒ Object
38 39 40 41 42 |
# File 'lib/hanami/cli/errors.rb', line 38 def self.const_missing(name) super unless name == :UnkwnownCommandError Hanami::Utils::Deprecation.new('UnkwnownCommandError is deprecated, please use UnknownCommandError') UnknownCommandError end |
Instance Method Details
#call(arguments: ARGV, out: $stdout) ⇒ Object
Invoke the CLI
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/hanami/cli.rb', line 50 def call(arguments: ARGV, out: $stdout) result = commands.get(arguments) if result.found? command, args = parse(result, out) result.before_callbacks.run(command, args) command.call(args) result.after_callbacks.run(command, args) else usage(result, out) end end |