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
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/bogo-cli/command.rb', line 32 def initialize(cli_opts, args) if (cli_opts.is_a?(Slop)) (cli_opts) else @defaults = Smash.new @options = cli_opts.to_hash.to_smash(:snake) [@options, *@options.values].compact.each do |hsh| next unless hsh.is_a?(Hash) hsh.delete_if { |k, v| v.nil? } end 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.
25 26 27 |
# File 'lib/bogo-cli/command.rb', line 25 def arguments @arguments end |
#defaults ⇒ Hash (readonly)
Returns default options.
23 24 25 |
# File 'lib/bogo-cli/command.rb', line 23 def defaults @defaults end |
#options ⇒ Hash (readonly)
Returns options.
21 22 23 |
# File 'lib/bogo-cli/command.rb', line 21 def @options end |
#ui ⇒ Ui (readonly)
27 28 29 |
# File 'lib/bogo-cli/command.rb', line 27 def ui @ui end |
Class Method Details
.ui(u = nil) ⇒ Bogo::Ui
Get or set default UI
13 14 15 16 |
# File 'lib/bogo-cli/command.rb', line 13 def self.ui(u = nil) @ui = u if u @ui end |
Instance Method Details
#execute! ⇒ TrueClass
Execute the command
57 58 59 |
# File 'lib/bogo-cli/command.rb', line 57 def execute! raise NotImplementedError end |