hammer_cli 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +4 -3
- data/bin/hammer +3 -3
- data/config/cli_config.template.yml +4 -3
- data/lib/hammer_cli/abstract.rb +14 -5
- data/lib/hammer_cli/apipie/read_command.rb +1 -5
- data/lib/hammer_cli/apipie/resource.rb +3 -3
- data/lib/hammer_cli/apipie/write_command.rb +3 -3
- data/lib/hammer_cli/exception_handler.rb +4 -3
- data/lib/hammer_cli/logger.rb +5 -5
- data/lib/hammer_cli/logger_watch.rb +1 -1
- data/lib/hammer_cli/main.rb +27 -6
- data/lib/hammer_cli/output/adapter/abstract.rb +19 -3
- data/lib/hammer_cli/output/adapter/base.rb +6 -0
- data/lib/hammer_cli/output/adapter/csv.rb +43 -0
- data/lib/hammer_cli/output/adapter/silent.rb +3 -1
- data/lib/hammer_cli/output/adapter/table.rb +6 -0
- data/lib/hammer_cli/output/adapter.rb +1 -0
- data/lib/hammer_cli/output/formatters.rb +35 -4
- data/lib/hammer_cli/output/output.rb +46 -14
- data/lib/hammer_cli/settings.rb +21 -3
- data/lib/hammer_cli/version.rb +1 -1
- data/lib/hammer_cli.rb +1 -1
- metadata +63 -46
- checksums.yaml +0 -7
data/README.md
CHANGED
@@ -69,9 +69,10 @@ Confirm your setup by running ```$ hammer -h``` and see if the desired commands
|
|
69
69
|
You will also most likely want to change the url of the Foreman server.
|
70
70
|
|
71
71
|
```yaml
|
72
|
-
:
|
73
|
-
:
|
74
|
-
:
|
72
|
+
:foreman:
|
73
|
+
:host: 'https://localhost/'
|
74
|
+
:username: 'admin'
|
75
|
+
:password: 'changeme'
|
75
76
|
```
|
76
77
|
|
77
78
|
Done. Your hammer client is configured and ready to use.
|
data/bin/hammer
CHANGED
@@ -46,9 +46,9 @@ end
|
|
46
46
|
require 'hammer_cli'
|
47
47
|
|
48
48
|
# load modules set in config
|
49
|
-
modules = HammerCLI::Settings
|
50
|
-
modules.each do |m|
|
51
|
-
require m
|
49
|
+
modules = HammerCLI::Settings.get(:modules) || []
|
50
|
+
modules.each do |m|
|
51
|
+
require m
|
52
52
|
logger.info "Extension module #{m} loaded"
|
53
53
|
end
|
54
54
|
|
@@ -2,9 +2,10 @@
|
|
2
2
|
# - hammer_cli_foreman
|
3
3
|
# - hammer_cli_katello_bridge
|
4
4
|
|
5
|
-
:
|
6
|
-
:
|
7
|
-
:
|
5
|
+
:foreman:
|
6
|
+
:host: 'https://localhost/'
|
7
|
+
:username: 'admin'
|
8
|
+
:password: 'changeme'
|
8
9
|
|
9
10
|
# :watch_plain: true disables color output of logger.watch in Clamp commands
|
10
11
|
:watch_plain: false
|
data/lib/hammer_cli/abstract.rb
CHANGED
@@ -15,6 +15,10 @@ module HammerCLI
|
|
15
15
|
attr_accessor :validation_block
|
16
16
|
end
|
17
17
|
|
18
|
+
def adapter
|
19
|
+
:base
|
20
|
+
end
|
21
|
+
|
18
22
|
def run(arguments)
|
19
23
|
exit_code = super
|
20
24
|
raise "exit code must be integer" unless exit_code.is_a? Integer
|
@@ -45,12 +49,8 @@ module HammerCLI
|
|
45
49
|
validator.run &self.class.validation_block if self.class.validation_block
|
46
50
|
end
|
47
51
|
|
48
|
-
def output
|
49
|
-
@output ||= HammerCLI::Output::Output.new(:context => context)
|
50
|
-
end
|
51
|
-
|
52
52
|
def exception_handler
|
53
|
-
@exception_handler ||= exception_handler_class.new :
|
53
|
+
@exception_handler ||= exception_handler_class.new(:context=>context, :adapter=>adapter)
|
54
54
|
end
|
55
55
|
|
56
56
|
def initialize(*args)
|
@@ -85,6 +85,15 @@ module HammerCLI
|
|
85
85
|
|
86
86
|
protected
|
87
87
|
|
88
|
+
def print_records(definition, records)
|
89
|
+
HammerCLI::Output::Output.print_records(definition, records, context,
|
90
|
+
:adapter => adapter)
|
91
|
+
end
|
92
|
+
|
93
|
+
def print_message(msg)
|
94
|
+
HammerCLI::Output::Output.print_message(msg, context, :adapter=>adapter)
|
95
|
+
end
|
96
|
+
|
88
97
|
def logger(name=self.class)
|
89
98
|
logger = Logging.logger[name]
|
90
99
|
logger.extend(HammerCLI::Logger::Watch) if not logger.respond_to? :watch
|
@@ -21,10 +21,6 @@ module HammerCLI::Apipie
|
|
21
21
|
@output_definition
|
22
22
|
end
|
23
23
|
|
24
|
-
def output
|
25
|
-
@output ||= HammerCLI::Output::Output.new :definition => output_definition
|
26
|
-
end
|
27
|
-
|
28
24
|
def execute
|
29
25
|
d = retrieve_data
|
30
26
|
logger.watch "Retrieved data: ", d
|
@@ -39,7 +35,7 @@ module HammerCLI::Apipie
|
|
39
35
|
end
|
40
36
|
|
41
37
|
def print_data(records)
|
42
|
-
|
38
|
+
print_records(output_definition, records)
|
43
39
|
end
|
44
40
|
|
45
41
|
def request_params
|
@@ -66,9 +66,9 @@ module HammerCLI::Apipie
|
|
66
66
|
|
67
67
|
def resource_config
|
68
68
|
config = {}
|
69
|
-
config[:base_url] = HammerCLI::Settings
|
70
|
-
config[:username] = context[:username] ||
|
71
|
-
config[:password] = context[:password] ||
|
69
|
+
config[:base_url] = HammerCLI::Settings.get(:foreman, :host)
|
70
|
+
config[:username] = context[:username] || ENV['FOREMAN_USERNAME'] || HammerCLI::Settings.get(:foreman, :username)
|
71
|
+
config[:password] = context[:password] || ENV['FOREMAN_PASSWORD'] || HammerCLI::Settings.get(:foreman, :password)
|
72
72
|
config
|
73
73
|
end
|
74
74
|
|
@@ -8,15 +8,15 @@ module HammerCLI::Apipie
|
|
8
8
|
|
9
9
|
def execute
|
10
10
|
send_request
|
11
|
-
|
11
|
+
print_success_message
|
12
12
|
return HammerCLI::EX_OK
|
13
13
|
end
|
14
14
|
|
15
15
|
protected
|
16
16
|
|
17
|
-
def
|
17
|
+
def print_success_message
|
18
18
|
msg = success_message
|
19
|
-
|
19
|
+
print_message(msg) unless msg.nil?
|
20
20
|
end
|
21
21
|
|
22
22
|
def send_request
|
@@ -5,8 +5,9 @@ module HammerCLI
|
|
5
5
|
class ExceptionHandler
|
6
6
|
|
7
7
|
def initialize(options={})
|
8
|
-
@output = options[:output] or raise "Missing option output"
|
9
8
|
@logger = Logging.logger['Exception']
|
9
|
+
@context = options[:context] || {}
|
10
|
+
@adapter = options[:adapter] || :base
|
10
11
|
end
|
11
12
|
|
12
13
|
def mappings
|
@@ -31,9 +32,9 @@ module HammerCLI
|
|
31
32
|
@logger.error error
|
32
33
|
|
33
34
|
if @options[:heading]
|
34
|
-
|
35
|
+
HammerCLI::Output::Output.print_error @options[:heading], error, @context, :adapter => @adapter
|
35
36
|
else
|
36
|
-
|
37
|
+
HammerCLI::Output::Output.print_error error, nil, @context, :adapter => @adapter
|
37
38
|
end
|
38
39
|
end
|
39
40
|
|
data/lib/hammer_cli/logger.rb
CHANGED
@@ -21,7 +21,7 @@ module HammerCLI
|
|
21
21
|
NOCOLOR_LAYOUT = Logging::Layouts::Pattern.new(:pattern => pattern, :color_scheme => nil)
|
22
22
|
DEFAULT_LOG_DIR = '/var/log/foreman'
|
23
23
|
|
24
|
-
log_dir = File.expand_path(HammerCLI::Settings
|
24
|
+
log_dir = File.expand_path(HammerCLI::Settings.get(:log_dir) || DEFAULT_LOG_DIR)
|
25
25
|
begin
|
26
26
|
FileUtils.mkdir_p(log_dir, :mode => 0750)
|
27
27
|
rescue Errno::EACCES => e
|
@@ -36,15 +36,15 @@ module HammerCLI
|
|
36
36
|
:layout => NOCOLOR_LAYOUT,
|
37
37
|
:truncate => false,
|
38
38
|
:keep => 5,
|
39
|
-
:size => HammerCLI::Settings
|
39
|
+
:size => HammerCLI::Settings.get(:log_size) || 1024*1024) # 1MB
|
40
40
|
# set owner and group (it's ignored if attribute is nil)
|
41
|
-
FileUtils.chown HammerCLI::Settings
|
41
|
+
FileUtils.chown HammerCLI::Settings.get(:log_owner), HammerCLI::Settings.get(:log_group), filename
|
42
42
|
rescue ArgumentError => e
|
43
43
|
puts "File #{filename} not writeable, won't log anything to file!"
|
44
44
|
end
|
45
45
|
|
46
|
-
logger.level = HammerCLI::Settings
|
46
|
+
logger.level = HammerCLI::Settings.get(:log_level)
|
47
47
|
|
48
|
-
end
|
48
|
+
end
|
49
49
|
|
50
50
|
end
|
@@ -5,7 +5,7 @@ module HammerCLI
|
|
5
5
|
module Watch
|
6
6
|
def watch(label, obj, options={})
|
7
7
|
if debug?
|
8
|
-
options = { :plain => HammerCLI::Settings
|
8
|
+
options = { :plain => HammerCLI::Settings.get(:watch_plain), :indent => -2 }.merge(options)
|
9
9
|
debug label + "\n" + obj.ai(options)
|
10
10
|
end
|
11
11
|
end
|
data/lib/hammer_cli/main.rb
CHANGED
@@ -17,6 +17,11 @@ module HammerCLI
|
|
17
17
|
|
18
18
|
option ["--show-ids"], :flag, "Show ids of associated resources"
|
19
19
|
|
20
|
+
option ["--csv"], :flag, "Output as CSV (same as --adapter=csv)"
|
21
|
+
option ["--output"], "ADAPTER", "Set output format. One of [%s]" %
|
22
|
+
HammerCLI::Output::Output.adapters.keys.join(', ')
|
23
|
+
option ["--csv-separator"], "SEPARATOR", "Character to separate the values"
|
24
|
+
|
20
25
|
option ["-P", "--ask-pass"], :flag, "Ask for password" do
|
21
26
|
context[:password] = get_password()
|
22
27
|
''
|
@@ -34,12 +39,30 @@ module HammerCLI
|
|
34
39
|
context[:show_ids] = show_ids
|
35
40
|
end
|
36
41
|
|
37
|
-
def
|
38
|
-
|
42
|
+
def run(*args)
|
43
|
+
super
|
44
|
+
end
|
45
|
+
|
46
|
+
def password=(p)
|
47
|
+
@password = p
|
48
|
+
context[:password] = p
|
39
49
|
end
|
40
50
|
|
41
|
-
def
|
42
|
-
context[:
|
51
|
+
def csv=(csv)
|
52
|
+
context[:adapter] = :csv
|
53
|
+
end
|
54
|
+
|
55
|
+
def csv_separator=(separator)
|
56
|
+
context[:csv_separator] = separator
|
57
|
+
end
|
58
|
+
|
59
|
+
def output=(adapter)
|
60
|
+
context[:adapter] = adapter
|
61
|
+
end
|
62
|
+
|
63
|
+
def username=(u)
|
64
|
+
@username = u
|
65
|
+
context[:username] = u
|
43
66
|
end
|
44
67
|
|
45
68
|
private
|
@@ -48,8 +71,6 @@ module HammerCLI
|
|
48
71
|
ask(prompt) {|q| q.echo = false}
|
49
72
|
end
|
50
73
|
|
51
|
-
|
52
|
-
|
53
74
|
end
|
54
75
|
|
55
76
|
end
|
@@ -1,11 +1,14 @@
|
|
1
|
-
|
2
1
|
module HammerCLI::Output::Adapter
|
3
2
|
|
4
3
|
class Abstract
|
5
4
|
|
6
|
-
def
|
5
|
+
def tags
|
6
|
+
[]
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(context={}, formatters={})
|
7
10
|
@context = context
|
8
|
-
@formatters = formatters
|
11
|
+
@formatters = HammerCLI::Output::Formatters::FormatterLibrary.new(filter_formatters(formatters))
|
9
12
|
end
|
10
13
|
|
11
14
|
def print_message(msg)
|
@@ -28,5 +31,18 @@ module HammerCLI::Output::Adapter
|
|
28
31
|
raise NotImplementedError
|
29
32
|
end
|
30
33
|
|
34
|
+
private
|
35
|
+
|
36
|
+
def filter_formatters(formatters_map)
|
37
|
+
formatters_map ||= {}
|
38
|
+
formatters_map.inject({}) do |map, (type, formatter_list)|
|
39
|
+
# remove incompatible formatters
|
40
|
+
filtered = formatter_list.select { |f| f.match?(tags) }
|
41
|
+
# put serializers first
|
42
|
+
map[type] = filtered.sort_by { |f| f.tags.include?(:flat) ? 0 : 1 }
|
43
|
+
map
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
31
47
|
end
|
32
48
|
end
|
@@ -4,6 +4,10 @@ module HammerCLI::Output::Adapter
|
|
4
4
|
GROUP_INDENT = " "*2
|
5
5
|
LABEL_DIVIDER = ": "
|
6
6
|
|
7
|
+
def tags
|
8
|
+
[:flat, :screen]
|
9
|
+
end
|
10
|
+
|
7
11
|
def print_records(fields, data)
|
8
12
|
self.fields = fields
|
9
13
|
|
@@ -117,4 +121,6 @@ module HammerCLI::Output::Adapter
|
|
117
121
|
attr_accessor :fields
|
118
122
|
|
119
123
|
end
|
124
|
+
|
125
|
+
HammerCLI::Output::Output.register_adapter(:base, Base)
|
120
126
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'csv'
|
2
|
+
if CSV.const_defined? :Reader
|
3
|
+
# Ruby 1.8 compatible
|
4
|
+
require 'fastercsv'
|
5
|
+
Object.send(:remove_const, :CSV)
|
6
|
+
CSV = FasterCSV
|
7
|
+
else
|
8
|
+
# CSV is now FasterCSV in ruby 1.9
|
9
|
+
end
|
10
|
+
|
11
|
+
module HammerCLI::Output::Adapter
|
12
|
+
|
13
|
+
class CSValues < Abstract
|
14
|
+
|
15
|
+
def tags
|
16
|
+
[:flat]
|
17
|
+
end
|
18
|
+
|
19
|
+
def print_records(fields, data)
|
20
|
+
csv_string = CSV.generate(
|
21
|
+
:col_sep => @context[:csv_separator] || ',',
|
22
|
+
:encoding => 'utf-8') do |csv|
|
23
|
+
# labels
|
24
|
+
csv << fields.select{ |f| !(f.class <= Fields::Id) || @context[:show_ids] }.map { |f| f.label }
|
25
|
+
# data
|
26
|
+
data.each do |d|
|
27
|
+
csv << fields.inject([]) do |row, f|
|
28
|
+
unless f.class <= Fields::Id && !@context[:show_ids]
|
29
|
+
value = (f.get_value(d) || '')
|
30
|
+
formatter = @formatters.formatter_for_type(f.class)
|
31
|
+
row << (formatter ? formatter.format(value) : value)
|
32
|
+
end
|
33
|
+
row
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
puts csv_string
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
HammerCLI::Output::Output.register_adapter(:csv, CSValues)
|
42
|
+
|
43
|
+
end
|
@@ -4,6 +4,10 @@ module HammerCLI::Output::Adapter
|
|
4
4
|
|
5
5
|
class Table < Abstract
|
6
6
|
|
7
|
+
def tags
|
8
|
+
[:screen, :flat]
|
9
|
+
end
|
10
|
+
|
7
11
|
def print_records(fields, data)
|
8
12
|
|
9
13
|
rows = data.collect do |d|
|
@@ -37,4 +41,6 @@ module HammerCLI::Output::Adapter
|
|
37
41
|
|
38
42
|
end
|
39
43
|
|
44
|
+
HammerCLI::Output::Output.register_adapter(:table, Table)
|
45
|
+
|
40
46
|
end
|
@@ -2,5 +2,6 @@ require File.join(File.dirname(__FILE__), 'adapter/abstract')
|
|
2
2
|
require File.join(File.dirname(__FILE__), 'adapter/base')
|
3
3
|
require File.join(File.dirname(__FILE__), 'adapter/table')
|
4
4
|
require File.join(File.dirname(__FILE__), 'adapter/silent')
|
5
|
+
require File.join(File.dirname(__FILE__), 'adapter/csv')
|
5
6
|
|
6
7
|
|
@@ -4,9 +4,10 @@ module HammerCLI::Output
|
|
4
4
|
# Registry for formatters
|
5
5
|
class FormatterLibrary
|
6
6
|
def initialize(formatter_map={})
|
7
|
+
|
7
8
|
@_formatters = {}
|
8
9
|
formatter_map.each do |type, formatters|
|
9
|
-
register_formatter(type, formatters)
|
10
|
+
register_formatter(type, *Array(formatters))
|
10
11
|
end
|
11
12
|
end
|
12
13
|
|
@@ -23,8 +24,25 @@ module HammerCLI::Output
|
|
23
24
|
end
|
24
25
|
end
|
25
26
|
|
27
|
+
# Tags:
|
28
|
+
# All the tags the formatter has, needs to be present in the addapter.
|
29
|
+
# Otherwise the formatter won't apply. Formatters with :flat tag are used first
|
30
|
+
# as we expect them to serialize the value.
|
31
|
+
#
|
32
|
+
# - by format: :flat x :data
|
33
|
+
# - by output: :file X :screen
|
34
|
+
|
26
35
|
# abstract formatter
|
27
36
|
class FieldFormatter
|
37
|
+
|
38
|
+
def tags
|
39
|
+
[]
|
40
|
+
end
|
41
|
+
|
42
|
+
def match?(other_tags)
|
43
|
+
tags & other_tags == tags
|
44
|
+
end
|
45
|
+
|
28
46
|
def format(data)
|
29
47
|
data
|
30
48
|
end
|
@@ -51,12 +69,21 @@ module HammerCLI::Output
|
|
51
69
|
@color = color
|
52
70
|
end
|
53
71
|
|
72
|
+
def tags
|
73
|
+
[:screen, :flat]
|
74
|
+
end
|
75
|
+
|
54
76
|
def format(data)
|
55
77
|
c = HighLine.color(data.to_s, @color)
|
56
78
|
end
|
57
79
|
end
|
58
80
|
|
59
81
|
class DateFormatter < FieldFormatter
|
82
|
+
|
83
|
+
def tags
|
84
|
+
[:flat]
|
85
|
+
end
|
86
|
+
|
60
87
|
def format(string_date)
|
61
88
|
t = DateTime.parse(string_date.to_s)
|
62
89
|
t.strftime("%Y/%m/%d %H:%M:%S")
|
@@ -66,14 +93,18 @@ module HammerCLI::Output
|
|
66
93
|
end
|
67
94
|
|
68
95
|
class ListFormatter < FieldFormatter
|
96
|
+
|
97
|
+
def tags
|
98
|
+
[:flat]
|
99
|
+
end
|
100
|
+
|
69
101
|
def format(list)
|
70
102
|
list.join(", ") if list
|
71
103
|
end
|
72
104
|
end
|
73
105
|
|
74
|
-
|
75
|
-
|
76
|
-
:List => ListFormatter.new)
|
106
|
+
HammerCLI::Output::Output.register_formatter(DateFormatter.new, :Date)
|
107
|
+
HammerCLI::Output::Output.register_formatter(ListFormatter.new, :List)
|
77
108
|
|
78
109
|
end
|
79
110
|
end
|
@@ -1,28 +1,60 @@
|
|
1
1
|
module HammerCLI::Output
|
2
2
|
class Output
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
def self.print_message(msg, context, options={})
|
5
|
+
adapter(options[:adapter], context).print_message(msg.to_s)
|
6
|
+
end
|
6
7
|
|
7
|
-
def
|
8
|
-
|
9
|
-
@adapter = options[:adapter] || HammerCLI::Output::Adapter::Base.new(
|
10
|
-
@context, HammerCLI::Output::Formatters::DEFAULT_FORMATTERS)
|
11
|
-
@definition = options[:definition] || HammerCLI::Output::Definition.new
|
8
|
+
def self.print_error(msg, details=nil, context={}, options={})
|
9
|
+
adapter(options[:adapter], context).print_error(msg.to_s, details)
|
12
10
|
end
|
13
11
|
|
14
|
-
def
|
15
|
-
adapter.
|
12
|
+
def self.print_records(definition, records, context, options={})
|
13
|
+
adapter(options[:adapter], context).print_records(definition.fields, [records].flatten(1))
|
16
14
|
end
|
17
15
|
|
18
|
-
def
|
19
|
-
adapter
|
16
|
+
def self.adapter(req_adapter, context)
|
17
|
+
if context[:adapter]
|
18
|
+
adapter_name = context[:adapter].to_sym
|
19
|
+
else
|
20
|
+
adapter_name = req_adapter
|
21
|
+
end
|
22
|
+
|
23
|
+
begin
|
24
|
+
init_adapter(adapter_name, context)
|
25
|
+
rescue NameError
|
26
|
+
Logging.logger[self.name].warn("Required adapter '#{adapter_name}' was not found, using 'base' instead")
|
27
|
+
init_adapter(:base, context)
|
28
|
+
end
|
20
29
|
end
|
21
30
|
|
22
|
-
def
|
23
|
-
|
31
|
+
def self.adapters
|
32
|
+
@adapters_hash ||= {}
|
33
|
+
@adapters_hash
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.formatters
|
37
|
+
@formatters_hash ||= {}
|
38
|
+
@formatters_hash
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.register_adapter(name, adapter_class)
|
42
|
+
adapters[name] = adapter_class
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.register_formatter(formatter, *field_types)
|
46
|
+
field_types.each do |type|
|
47
|
+
formatter_list = formatters[type] || []
|
48
|
+
formatter_list << formatter
|
49
|
+
formatters[type] = formatter_list
|
50
|
+
end
|
51
|
+
end
|
24
52
|
|
25
|
-
|
53
|
+
private
|
54
|
+
|
55
|
+
def self.init_adapter(adapter_name, context)
|
56
|
+
raise NameError unless adapters.has_key? adapter_name
|
57
|
+
adapters[adapter_name].new(context, formatters)
|
26
58
|
end
|
27
59
|
|
28
60
|
end
|
data/lib/hammer_cli/settings.rb
CHANGED
@@ -5,8 +5,11 @@ module HammerCLI
|
|
5
5
|
|
6
6
|
class Settings
|
7
7
|
|
8
|
-
def self.
|
9
|
-
settings
|
8
|
+
def self.get(*keys)
|
9
|
+
keys.inject(settings) do |value, key|
|
10
|
+
return nil unless value
|
11
|
+
value[key.to_sym]
|
12
|
+
end
|
10
13
|
end
|
11
14
|
|
12
15
|
def self.load_from_file(files)
|
@@ -23,7 +26,7 @@ module HammerCLI
|
|
23
26
|
end
|
24
27
|
|
25
28
|
def self.load(settings_hash)
|
26
|
-
settings
|
29
|
+
deep_merge!(settings, settings_hash)
|
27
30
|
end
|
28
31
|
|
29
32
|
def self.clear
|
@@ -42,6 +45,21 @@ module HammerCLI
|
|
42
45
|
@settings_hash
|
43
46
|
end
|
44
47
|
|
48
|
+
def self.deep_merge!(h, other_h)
|
49
|
+
other_h = symbolize_hash(other_h)
|
50
|
+
|
51
|
+
h.merge!(other_h) do |key, old_val, new_val|
|
52
|
+
if old_val.is_a? Hash and new_val.is_a? Hash
|
53
|
+
deep_merge!(old_val, new_val)
|
54
|
+
else
|
55
|
+
new_val
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.symbolize_hash(h)
|
61
|
+
h = h.inject({}) { |sym_hash,(k,v)| sym_hash.update(k.to_sym => v) }
|
62
|
+
end
|
45
63
|
end
|
46
64
|
|
47
65
|
|
data/lib/hammer_cli/version.rb
CHANGED
data/lib/hammer_cli.rb
CHANGED
@@ -2,10 +2,10 @@ require 'hammer_cli/version'
|
|
2
2
|
require 'hammer_cli/exit_codes'
|
3
3
|
require 'hammer_cli/settings'
|
4
4
|
require 'hammer_cli/validator'
|
5
|
+
require 'hammer_cli/output'
|
5
6
|
require 'hammer_cli/abstract'
|
6
7
|
require 'hammer_cli/main'
|
7
8
|
|
8
|
-
require 'hammer_cli/output'
|
9
9
|
require 'hammer_cli/apipie'
|
10
10
|
|
11
11
|
# extend MainCommand
|
metadata
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hammer_cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Martin Bačovský
|
@@ -9,94 +10,107 @@ authors:
|
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date: 2013-
|
13
|
+
date: 2013-10-08 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: clamp
|
16
17
|
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
17
19
|
requirements:
|
18
|
-
- - '>='
|
20
|
+
- - ! '>='
|
19
21
|
- !ruby/object:Gem::Version
|
20
22
|
version: '0'
|
21
23
|
type: :runtime
|
22
24
|
prerelease: false
|
23
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
24
27
|
requirements:
|
25
|
-
- - '>='
|
28
|
+
- - ! '>='
|
26
29
|
- !ruby/object:Gem::Version
|
27
30
|
version: '0'
|
28
31
|
- !ruby/object:Gem::Dependency
|
29
32
|
name: rest-client
|
30
33
|
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
31
35
|
requirements:
|
32
|
-
- - '>='
|
36
|
+
- - ! '>='
|
33
37
|
- !ruby/object:Gem::Version
|
34
38
|
version: '0'
|
35
39
|
type: :runtime
|
36
40
|
prerelease: false
|
37
41
|
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
38
43
|
requirements:
|
39
|
-
- - '>='
|
44
|
+
- - ! '>='
|
40
45
|
- !ruby/object:Gem::Version
|
41
46
|
version: '0'
|
42
47
|
- !ruby/object:Gem::Dependency
|
43
48
|
name: logging
|
44
49
|
requirement: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
45
51
|
requirements:
|
46
|
-
- - '>='
|
52
|
+
- - ! '>='
|
47
53
|
- !ruby/object:Gem::Version
|
48
54
|
version: '0'
|
49
55
|
type: :runtime
|
50
56
|
prerelease: false
|
51
57
|
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
52
59
|
requirements:
|
53
|
-
- - '>='
|
60
|
+
- - ! '>='
|
54
61
|
- !ruby/object:Gem::Version
|
55
62
|
version: '0'
|
56
63
|
- !ruby/object:Gem::Dependency
|
57
64
|
name: awesome_print
|
58
65
|
requirement: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
59
67
|
requirements:
|
60
|
-
- - '>='
|
68
|
+
- - ! '>='
|
61
69
|
- !ruby/object:Gem::Version
|
62
70
|
version: '0'
|
63
71
|
type: :runtime
|
64
72
|
prerelease: false
|
65
73
|
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
66
75
|
requirements:
|
67
|
-
- - '>='
|
76
|
+
- - ! '>='
|
68
77
|
- !ruby/object:Gem::Version
|
69
78
|
version: '0'
|
70
79
|
- !ruby/object:Gem::Dependency
|
71
80
|
name: table_print
|
72
81
|
requirement: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
73
83
|
requirements:
|
74
|
-
- - '>='
|
84
|
+
- - ! '>='
|
75
85
|
- !ruby/object:Gem::Version
|
76
86
|
version: '0'
|
77
87
|
type: :runtime
|
78
88
|
prerelease: false
|
79
89
|
version_requirements: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
80
91
|
requirements:
|
81
|
-
- - '>='
|
92
|
+
- - ! '>='
|
82
93
|
- !ruby/object:Gem::Version
|
83
94
|
version: '0'
|
84
95
|
- !ruby/object:Gem::Dependency
|
85
96
|
name: highline
|
86
97
|
requirement: !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
87
99
|
requirements:
|
88
|
-
- - '>='
|
100
|
+
- - ! '>='
|
89
101
|
- !ruby/object:Gem::Version
|
90
102
|
version: '0'
|
91
103
|
type: :runtime
|
92
104
|
prerelease: false
|
93
105
|
version_requirements: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
94
107
|
requirements:
|
95
|
-
- - '>='
|
108
|
+
- - ! '>='
|
96
109
|
- !ruby/object:Gem::Version
|
97
110
|
version: '0'
|
98
|
-
description:
|
99
|
-
|
111
|
+
description: ! 'Hammer cli provides universal extendable CLI interface for ruby apps
|
112
|
+
|
113
|
+
'
|
100
114
|
email: mbacovsk@redhat.com
|
101
115
|
executables:
|
102
116
|
- hammer
|
@@ -106,69 +120,72 @@ extra_rdoc_files:
|
|
106
120
|
- LICENSE
|
107
121
|
- hammer_cli_complete
|
108
122
|
- config/cli_config.template.yml
|
109
|
-
- doc/design.uml
|
110
123
|
- doc/design.png
|
124
|
+
- doc/design.uml
|
111
125
|
files:
|
112
|
-
- lib/hammer_cli
|
113
|
-
- lib/hammer_cli/
|
114
|
-
- lib/hammer_cli/
|
115
|
-
- lib/hammer_cli/apipie/write_command.rb
|
116
|
-
- lib/hammer_cli/apipie/command.rb
|
117
|
-
- lib/hammer_cli/apipie/options.rb
|
118
|
-
- lib/hammer_cli/apipie/read_command.rb
|
119
|
-
- lib/hammer_cli/apipie/resource.rb
|
120
|
-
- lib/hammer_cli/apipie.rb
|
121
|
-
- lib/hammer_cli/autocompletion.rb
|
122
|
-
- lib/hammer_cli/validator.rb
|
123
|
-
- lib/hammer_cli/exit_codes.rb
|
124
|
-
- lib/hammer_cli/version.rb
|
125
|
-
- lib/hammer_cli/logger_watch.rb
|
126
|
-
- lib/hammer_cli/main.rb
|
127
|
-
- lib/hammer_cli/settings.rb
|
128
|
-
- lib/hammer_cli/output/output.rb
|
126
|
+
- lib/hammer_cli.rb
|
127
|
+
- lib/hammer_cli/messages.rb
|
128
|
+
- lib/hammer_cli/output/fields.rb
|
129
129
|
- lib/hammer_cli/output/formatters.rb
|
130
|
-
- lib/hammer_cli/output/adapter/abstract.rb
|
131
130
|
- lib/hammer_cli/output/adapter/table.rb
|
132
131
|
- lib/hammer_cli/output/adapter/base.rb
|
132
|
+
- lib/hammer_cli/output/adapter/abstract.rb
|
133
133
|
- lib/hammer_cli/output/adapter/silent.rb
|
134
|
-
- lib/hammer_cli/output/
|
134
|
+
- lib/hammer_cli/output/adapter/csv.rb
|
135
135
|
- lib/hammer_cli/output/adapter.rb
|
136
|
+
- lib/hammer_cli/output/output.rb
|
137
|
+
- lib/hammer_cli/output/dsl.rb
|
136
138
|
- lib/hammer_cli/output/definition.rb
|
137
|
-
- lib/hammer_cli/
|
139
|
+
- lib/hammer_cli/abstract.rb
|
140
|
+
- lib/hammer_cli/shell.rb
|
141
|
+
- lib/hammer_cli/autocompletion.rb
|
142
|
+
- lib/hammer_cli/logger_watch.rb
|
138
143
|
- lib/hammer_cli/logger.rb
|
144
|
+
- lib/hammer_cli/apipie.rb
|
145
|
+
- lib/hammer_cli/apipie/command.rb
|
146
|
+
- lib/hammer_cli/apipie/options.rb
|
147
|
+
- lib/hammer_cli/apipie/resource.rb
|
148
|
+
- lib/hammer_cli/apipie/write_command.rb
|
149
|
+
- lib/hammer_cli/apipie/read_command.rb
|
150
|
+
- lib/hammer_cli/validator.rb
|
151
|
+
- lib/hammer_cli/version.rb
|
152
|
+
- lib/hammer_cli/exit_codes.rb
|
153
|
+
- lib/hammer_cli/output.rb
|
139
154
|
- lib/hammer_cli/exception_handler.rb
|
140
|
-
- lib/hammer_cli/
|
141
|
-
- lib/hammer_cli/
|
142
|
-
- lib/hammer_cli.rb
|
155
|
+
- lib/hammer_cli/main.rb
|
156
|
+
- lib/hammer_cli/option_formatters.rb
|
157
|
+
- lib/hammer_cli/settings.rb
|
143
158
|
- bin/hammer
|
144
159
|
- README.md
|
145
160
|
- LICENSE
|
146
161
|
- hammer_cli_complete
|
147
162
|
- config/cli_config.template.yml
|
148
|
-
- doc/design.uml
|
149
163
|
- doc/design.png
|
164
|
+
- doc/design.uml
|
150
165
|
homepage: http://github.com/theforeman/hammer-cli
|
151
166
|
licenses:
|
152
167
|
- GPL-3
|
153
|
-
metadata: {}
|
154
168
|
post_install_message:
|
155
169
|
rdoc_options: []
|
156
170
|
require_paths:
|
157
171
|
- lib
|
158
172
|
required_ruby_version: !ruby/object:Gem::Requirement
|
173
|
+
none: false
|
159
174
|
requirements:
|
160
|
-
- - '>='
|
175
|
+
- - ! '>='
|
161
176
|
- !ruby/object:Gem::Version
|
162
177
|
version: '0'
|
163
178
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
179
|
+
none: false
|
164
180
|
requirements:
|
165
|
-
- - '>='
|
181
|
+
- - ! '>='
|
166
182
|
- !ruby/object:Gem::Version
|
167
183
|
version: '0'
|
168
184
|
requirements: []
|
169
185
|
rubyforge_project:
|
170
|
-
rubygems_version:
|
186
|
+
rubygems_version: 1.8.24
|
171
187
|
signing_key:
|
172
|
-
specification_version:
|
188
|
+
specification_version: 3
|
173
189
|
summary: Universal command-line interface
|
174
190
|
test_files: []
|
191
|
+
has_rdoc:
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: cec260aec7ea81ebce48b8efe53cd738f8e63266
|
4
|
-
data.tar.gz: 1aa5bb89e0dc87783b4bd093a2b8dffb58ac9616
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: 0ea5172e0d0b8d3fdb743a3f26d3cf1a5ad351360b607f1a4343b7a09303b8d77c9c417106027a5163f49ac4382a158f31cdf23501d47d230594e44d92fa3e47
|
7
|
-
data.tar.gz: 6637eb0f497677b719636ac5b91c12e5ac3da1b96b68e95b49f36831a0d69ed7e355ada97dbd79d4b0ff9b08b4765f725a25fe8e9e934238522b3de7065729cf
|