Class: Bogo::Cli::Command

Inherits:
Object
  • Object
show all
Includes:
Memoization
Defined in:
lib/bogo-cli/command.rb

Overview

Abstract command class

Instance Attribute Summary collapse

Instance Method Summary collapse

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))
    process_cli_options(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 = args
  ui_args = Smash.new(
    :app_name => options.fetch(:app_name,
      self.class.name.split('::').first
    )
  ).merge(cli_opts.to_hash.to_smash).merge(opts)
  @ui = options.delete(:ui) || Ui.new(ui_args)
  load_config!
end

Instance Attribute Details

#argumentsArray (readonly)

Returns cli arguments.

Returns:

  • (Array)

    cli arguments



17
18
19
# File 'lib/bogo-cli/command.rb', line 17

def arguments
  @arguments
end

#defaultsHash (readonly)

Returns default options.

Returns:

  • (Hash)

    default options



15
16
17
# File 'lib/bogo-cli/command.rb', line 15

def defaults
  @defaults
end

#optionsHash (readonly)

Returns options.

Returns:

  • (Hash)

    options



13
14
15
# File 'lib/bogo-cli/command.rb', line 13

def options
  @options
end

#uiUi (readonly)

Returns:

  • (Ui)


19
20
21
# File 'lib/bogo-cli/command.rb', line 19

def ui
  @ui
end

Instance Method Details

#execute!TrueClass

Execute the command

Returns:

  • (TrueClass)

Raises:

  • (NotImplementedError)


48
49
50
# File 'lib/bogo-cli/command.rb', line 48

def execute!
  raise NotImplementedError
end