Class: Omnibus::Command::Base

Inherits:
Thor
  • Object
show all
Includes:
Logging
Defined in:
lib/omnibus/cli/base.rb

Direct Known Subclasses

Omnibus::CLI, Cache, Publish

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logging

included

Constructor Details

#initialize(args, options, config) ⇒ Base


39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/omnibus/cli/base.rb', line 39

def initialize(args, options, config)
  super(args, options, config)

  # Set the log_level
  if @options[:log_level]
    Omnibus.logger.level = @options[:log_level]
  end

  # Do not load the Omnibus config if we are asking for help or the version
  if %w(help version).include?(config[:current_command].name)
    log.debug(log_key) { 'Skipping Omnibus loading (detected help or version)' }
    return
  end

  if File.exist?(@options[:config])
    log.info(log_key) { "Using config from '#{@options[:config]}'" }
    Omnibus.load_configuration(@options[:config])
  else
    if @options[:config] == Omnibus::DEFAULT_CONFIG
      log.debug(log_key) { 'Config file not given - using defaults' }
    else
      raise "The given config file '#{@options[:config]}' does not exist!"
    end
  end

  @options[:override].each do |key, value|
    if %w(true false nil).include?(value)
      log.debug(log_key) { "Detected #{value.inspect} should be an object" }
      value = { 'true' => true, 'false' => false, 'nil' => nil }[value]
    end

    if value =~ /\A[[:digit:]]+\Z/
      log.debug(log_key) { "Detected #{value.inspect} should be an integer" }
      value = value.to_i
    end

    if Config.respond_to?(key)
      log.debug(log_key) { "Setting Config.#{key} = #{value.inspect}" }
      Config.send(key, value)
    else
      log.debug (log_key){ "Skipping option '#{key}' - not a config option" }
    end
  end
end

Class Method Details

.dispatch(m, args, options, config) ⇒ Object


25
26
27
28
29
30
31
32
33
34
# File 'lib/omnibus/cli/base.rb', line 25

def dispatch(m, args, options, config)
  # Handle the case where Thor thinks a trailing --help is actually an
  # argument and blows up...
  if args.length > 1 && !(args & Thor::HELP_MAPPINGS).empty?
    args = args - Thor::HELP_MAPPINGS
    args.insert(-2, 'help')
  end

  super
end

Instance Method Details

#helpObject


106
107
108
# File 'lib/omnibus/cli/base.rb', line 106

def help(*)
  super
end