Class: Omnibus::Command::Base
- Inherits:
-
Thor
- Object
- Thor
- Omnibus::Command::Base
show all
- Includes:
- Logging
- Defined in:
- lib/omnibus/cli/base.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Logging
included
Constructor Details
#initialize(args, options, config) ⇒ Base
Returns a new instance of Base.
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
83
84
85
86
|
# File 'lib/omnibus/cli/base.rb', line 43
def initialize(args, options, config)
super(args, options, config)
if @options[:log_level]
Omnibus.logger.level = @options[:log_level]
end
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)
if args.length > 1 && !(args & Thor::HELP_MAPPINGS).empty?
args -= Thor::HELP_MAPPINGS
args.insert(-2, "help")
end
super
end
|
.exit_on_failure? ⇒ Boolean
36
37
38
|
# File 'lib/omnibus/cli/base.rb', line 36
def exit_on_failure?
true
end
|
Instance Method Details
#help ⇒ Object
110
111
112
|
# File 'lib/omnibus/cli/base.rb', line 110
def help(*)
super
end
|