Class: Bogo::Cli::Command
- Inherits:
-
Object
- Object
- Bogo::Cli::Command
- Includes:
- Memoization
- Defined in:
- lib/bogo-cli/command.rb
Overview
Abstract command class
Instance Attribute Summary collapse
-
#arguments ⇒ Array
readonly
Cli arguments.
-
#defaults ⇒ Hash
readonly
Default options.
-
#options ⇒ Hash
readonly
Options.
- #ui ⇒ Ui readonly
Class Method Summary collapse
-
.ui(u = nil) ⇒ Bogo::Ui
Get or set default UI.
Instance Method Summary collapse
-
#execute! ⇒ TrueClass
Execute the command.
-
#initialize(cli_opts, args) ⇒ self
constructor
Build new command instance.
Constructor Details
#initialize(cli_opts, args) ⇒ self
Build new command instance
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/bogo-cli/command.rb', line 33 def initialize(cli_opts, args) @defaults = Smash.new = Smash.new case cli_opts when Bogo::Cli::Parser::OptionValues (cli_opts) when Bogo::Cli::Parser::Command = cli_opts.parse(args).first else = cli_opts.to_h.to_smash(:snake) end [, *.values].compact.each do |hsh| next unless hsh.is_a?(Hash) hsh.delete_if { |k, v| v.nil? } end @arguments = validate_arguments!(args) load_config! ui_args = Smash.new( :app_name => .fetch(:app_name, self.class.name.split("::").first), ).merge(config) @ui = .delete(:ui) || Ui.new(ui_args) Bogo::Cli::Command.ui(ui) configure_logger! end |
Instance Attribute Details
#arguments ⇒ Array (readonly)
Returns cli arguments.
26 27 28 |
# File 'lib/bogo-cli/command.rb', line 26 def arguments @arguments end |
#defaults ⇒ Hash (readonly)
Returns default options.
24 25 26 |
# File 'lib/bogo-cli/command.rb', line 24 def defaults @defaults end |
#options ⇒ Hash (readonly)
Returns options.
22 23 24 |
# File 'lib/bogo-cli/command.rb', line 22 def end |
#ui ⇒ Ui (readonly)
28 29 30 |
# File 'lib/bogo-cli/command.rb', line 28 def ui @ui end |
Class Method Details
.ui(u = nil) ⇒ Bogo::Ui
Get or set default UI
14 15 16 17 |
# File 'lib/bogo-cli/command.rb', line 14 def self.ui(u = nil) @ui = u if u @ui end |
Instance Method Details
#execute! ⇒ TrueClass
Execute the command
62 63 64 |
# File 'lib/bogo-cli/command.rb', line 62 def execute! raise NotImplementedError end |