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
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
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/bogo-cli/command.rb', line 24 def initialize(cli_opts, args) if(cli_opts.is_a?(Slop)) (cli_opts) else @defaults = Smash.new = cli_opts.to_hash.to_smash(:snake) [, *.values].compact.each do |hsh| next unless hsh.is_a?(Hash) hsh.delete_if{|k,v| v.nil?} end end @arguments = args ui_args = Smash.new( :app_name => .fetch(:app_name, self.class.name.split('::').first ) ).merge(cli_opts.to_hash.to_smash).merge(opts) @ui = .delete(:ui) || Ui.new(ui_args) load_config! end |
Instance Attribute Details
#arguments ⇒ Array (readonly)
Returns cli arguments.
17 18 19 |
# File 'lib/bogo-cli/command.rb', line 17 def arguments @arguments end |
#defaults ⇒ Hash (readonly)
Returns default options.
15 16 17 |
# File 'lib/bogo-cli/command.rb', line 15 def defaults @defaults end |
#options ⇒ Hash (readonly)
Returns options.
13 14 15 |
# File 'lib/bogo-cli/command.rb', line 13 def end |
#ui ⇒ Ui (readonly)
19 20 21 |
# File 'lib/bogo-cli/command.rb', line 19 def ui @ui end |
Instance Method Details
#execute! ⇒ TrueClass
Execute the command
48 49 50 |
# File 'lib/bogo-cli/command.rb', line 48 def execute! raise NotImplementedError end |