hammer_cli 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -2
- data/bin/hammer +6 -0
- data/config/cli_config.template.yml +3 -0
- data/doc/creating_commands.md +19 -0
- data/doc/i18n.md +15 -0
- data/doc/installation.md +1 -1
- data/doc/release_notes.md +61 -0
- data/lib/hammer_cli/abstract.rb +10 -37
- data/lib/hammer_cli/apipie/command.rb +10 -6
- data/lib/hammer_cli/apipie/option_builder.rb +26 -13
- data/lib/hammer_cli/apipie/options.rb +12 -10
- data/lib/hammer_cli/completer.rb +2 -2
- data/lib/hammer_cli/exception_handler.rb +5 -4
- data/lib/hammer_cli/exceptions.rb +1 -0
- data/lib/hammer_cli/i18n.rb +41 -0
- data/lib/hammer_cli/main.rb +2 -2
- data/lib/hammer_cli/options/normalizers.rb +31 -0
- data/lib/hammer_cli/output/adapter/abstract.rb +5 -1
- data/lib/hammer_cli/output/adapter/csv.rb +140 -12
- data/lib/hammer_cli/shell.rb +6 -6
- data/lib/hammer_cli/subcommand.rb +82 -0
- data/lib/hammer_cli/utils.rb +13 -0
- data/lib/hammer_cli/version.rb +1 -1
- data/locale/Makefile +11 -10
- data/locale/README.md +18 -0
- data/locale/en/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/en/hammer-cli.po +227 -0
- data/locale/en_GB/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/en_GB/hammer-cli.po +274 -0
- data/locale/es/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/es/hammer-cli.po +275 -0
- data/locale/fr/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/fr/hammer-cli.po +276 -0
- data/locale/hammer-cli.pot +158 -93
- data/test/reports/TEST-Fields-ContainerField-display-.xml +7 -0
- data/test/reports/TEST-Fields-ContainerField-display-blank-is-allowed.xml +15 -0
- data/test/reports/TEST-Fields-ContainerField-display-blank-is-not-allowed.xml +15 -0
- data/test/reports/TEST-Fields-ContainerField.xml +7 -0
- data/test/reports/TEST-Fields-Field-display-.xml +7 -0
- data/test/reports/TEST-Fields-Field-display-blank-is-allowed.xml +11 -0
- data/test/reports/TEST-Fields-Field-display-blank-is-not-allowed.xml +11 -0
- data/test/reports/TEST-Fields-Field-hide-blank-.xml +11 -0
- data/test/reports/TEST-Fields-Field-parameters.xml +9 -0
- data/test/reports/TEST-Fields-Field.xml +13 -0
- data/test/reports/TEST-HammerCLI-AbstractCommand-build-options.xml +15 -0
- data/test/reports/TEST-HammerCLI-AbstractCommand-exception-handler.xml +13 -0
- data/test/reports/TEST-HammerCLI-AbstractCommand-logging.xml +21 -0
- data/test/reports/TEST-HammerCLI-AbstractCommand-option-builder.xml +11 -0
- data/test/reports/TEST-HammerCLI-AbstractCommand-options.xml +11 -0
- data/test/reports/TEST-HammerCLI-AbstractCommand-output.xml +19 -0
- data/test/reports/TEST-HammerCLI-AbstractCommand-subcommand-behavior-remove-subcommand.xml +11 -0
- data/test/reports/TEST-HammerCLI-AbstractCommand-subcommand-behavior-subcommand-.xml +13 -0
- data/test/reports/TEST-HammerCLI-AbstractCommand-subcommand-behavior-subcommand.xml +11 -0
- data/test/reports/TEST-HammerCLI-AbstractCommand-subcommand-behavior.xml +7 -0
- data/test/reports/TEST-HammerCLI-AbstractCommand.xml +11 -0
- data/test/reports/TEST-HammerCLI-Apipie-Command-options.xml +11 -0
- data/test/reports/TEST-HammerCLI-Apipie-Command-resource-defined.xml +9 -0
- data/test/reports/TEST-HammerCLI-Apipie-Command-setting-resources.xml +19 -0
- data/test/reports/TEST-HammerCLI-Apipie-Command.xml +9 -0
- data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder-aliasing-resources.xml +13 -0
- data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder-filtering-options.xml +15 -0
- data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder-required-options.xml +11 -0
- data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder-setting-correct-normalizers.xml +9 -0
- data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder-with-hash-params.xml +11 -0
- data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder-with-one-simple-param.xml +15 -0
- data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder.xml +7 -0
- data/test/reports/TEST-HammerCLI-Completer-command-completion.xml +29 -0
- data/test/reports/TEST-HammerCLI-Completer-option-value-completion.xml +17 -0
- data/test/reports/TEST-HammerCLI-Completer-subcommand-completion.xml +19 -0
- data/test/reports/TEST-HammerCLI-Completer.xml +7 -0
- data/test/reports/TEST-HammerCLI-CompleterLine-line-complete.xml +25 -0
- data/test/reports/TEST-HammerCLI-CompleterLine-splitting-words.xml +29 -0
- data/test/reports/TEST-HammerCLI-CompleterLine.xml +7 -0
- data/test/reports/TEST-HammerCLI-CompleterWord-complete-.xml +23 -0
- data/test/reports/TEST-HammerCLI-CompleterWord-quote.xml +15 -0
- data/test/reports/TEST-HammerCLI-CompleterWord-quoted-.xml +13 -0
- data/test/reports/TEST-HammerCLI-CompleterWord.xml +7 -0
- data/test/reports/TEST-HammerCLI-Connection.xml +21 -0
- data/test/reports/TEST-HammerCLI-ExceptionHandler.xml +21 -0
- data/test/reports/TEST-HammerCLI-I18n.xml +11 -0
- data/test/reports/TEST-HammerCLI-MainCommand-loading-context-password.xml +11 -0
- data/test/reports/TEST-HammerCLI-MainCommand-loading-context-username.xml +11 -0
- data/test/reports/TEST-HammerCLI-MainCommand-loading-context-verbose.xml +9 -0
- data/test/reports/TEST-HammerCLI-MainCommand-loading-context.xml +7 -0
- data/test/reports/TEST-HammerCLI-MainCommand.xml +7 -0
- data/test/reports/TEST-HammerCLI-Modules-find-by-name.xml +13 -0
- data/test/reports/TEST-HammerCLI-Modules-load-a-module-module-not-found.xml +13 -0
- data/test/reports/TEST-HammerCLI-Modules-load-a-module-module-runtime-exception.xml +13 -0
- data/test/reports/TEST-HammerCLI-Modules-load-a-module-success.xml +15 -0
- data/test/reports/TEST-HammerCLI-Modules-load-a-module.xml +7 -0
- data/test/reports/TEST-HammerCLI-Modules-load-all-modules.xml +9 -0
- data/test/reports/TEST-HammerCLI-Modules-names.xml +13 -0
- data/test/reports/TEST-HammerCLI-Modules.xml +7 -0
- data/test/reports/TEST-HammerCLI-OptionBuilderContainer.0.xml +7 -0
- data/test/reports/TEST-HammerCLI-OptionBuilderContainer.xml +11 -0
- data/test/reports/TEST-HammerCLI-Options-Normalizers-abstract.xml +9 -0
- data/test/reports/TEST-HammerCLI-Options-Normalizers-bool.xml +31 -0
- data/test/reports/TEST-HammerCLI-Options-Normalizers-datetime.xml +17 -0
- data/test/reports/TEST-HammerCLI-Options-Normalizers-enum.xml +15 -0
- data/test/reports/TEST-HammerCLI-Options-Normalizers-enumlist.xml +21 -0
- data/test/reports/TEST-HammerCLI-Options-Normalizers-json-input.xml +15 -0
- data/test/reports/TEST-HammerCLI-Options-Normalizers-key-value-list.xml +17 -0
- data/test/reports/TEST-HammerCLI-Options-Normalizers-list.xml +15 -0
- data/test/reports/TEST-HammerCLI-Options-Normalizers.xml +7 -0
- data/test/reports/TEST-HammerCLI-Options-OptionDefinition-context.xml +9 -0
- data/test/reports/TEST-HammerCLI-Options-OptionDefinition-formatters.xml +11 -0
- data/test/reports/TEST-HammerCLI-Options-OptionDefinition.xml +7 -0
- data/test/reports/TEST-HammerCLI-Output-Adapter-Abstract-error-messages.xml +15 -0
- data/test/reports/TEST-HammerCLI-Output-Adapter-Abstract-messages.xml +11 -0
- data/test/reports/TEST-HammerCLI-Output-Adapter-Abstract-test-data-for-field.xml +15 -0
- data/test/reports/TEST-HammerCLI-Output-Adapter-Abstract.xml +17 -0
- data/test/reports/TEST-HammerCLI-Output-Adapter-Base-print-collection-show-ids.xml +9 -0
- data/test/reports/TEST-HammerCLI-Output-Adapter-Base-print-collection.xml +27 -0
- data/test/reports/TEST-HammerCLI-Output-Adapter-Base.xml +7 -0
- data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues-print-collection-formatters.xml +11 -0
- data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues-print-collection-handle-fields-with-collections.xml +13 -0
- data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues-print-collection-handle-fields-with-containers.xml +11 -0
- data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues-print-collection-handle-ids.xml +11 -0
- data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues-print-collection.xml +11 -0
- data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues-print-message.xml +11 -0
- data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues.xml +7 -0
- data/test/reports/TEST-HammerCLI-Output-Adapter-Table-print-collection-column-width.xml +15 -0
- data/test/reports/TEST-HammerCLI-Output-Adapter-Table-print-collection-formatters.xml +11 -0
- data/test/reports/TEST-HammerCLI-Output-Adapter-Table-print-collection-handle-ids.xml +11 -0
- data/test/reports/TEST-HammerCLI-Output-Adapter-Table-print-collection-sort-columns.xml +9 -0
- data/test/reports/TEST-HammerCLI-Output-Adapter-Table-print-collection.xml +11 -0
- data/test/reports/TEST-HammerCLI-Output-Adapter-Table.xml +7 -0
- data/test/reports/TEST-HammerCLI-Output-Definition-empty-.xml +11 -0
- data/test/reports/TEST-HammerCLI-Output-Definition.xml +11 -0
- data/test/reports/TEST-HammerCLI-Output-Dsl-collection.xml +13 -0
- data/test/reports/TEST-HammerCLI-Output-Dsl-custom-fields.xml +11 -0
- data/test/reports/TEST-HammerCLI-Output-Dsl-fields.xml +15 -0
- data/test/reports/TEST-HammerCLI-Output-Dsl-label.xml +13 -0
- data/test/reports/TEST-HammerCLI-Output-Dsl-path-definition.xml +13 -0
- data/test/reports/TEST-HammerCLI-Output-Dsl.xml +9 -0
- data/test/reports/TEST-HammerCLI-Output-FieldFilter.xml +13 -0
- data/test/reports/TEST-HammerCLI-Output-Formatters-BooleanFormatter.xml +11 -0
- data/test/reports/TEST-HammerCLI-Output-Formatters-ColorFormatter.xml +9 -0
- data/test/reports/TEST-HammerCLI-Output-Formatters-DateFormatter.xml +11 -0
- data/test/reports/TEST-HammerCLI-Output-Formatters-FieldFormatter.xml +13 -0
- data/test/reports/TEST-HammerCLI-Output-Formatters-FormatterContainer.xml +13 -0
- data/test/reports/TEST-HammerCLI-Output-Formatters-FormatterLibrary.xml +11 -0
- data/test/reports/TEST-HammerCLI-Output-Formatters-KeyValueFormatter.xml +13 -0
- data/test/reports/TEST-HammerCLI-Output-Formatters-ListFormatter.xml +13 -0
- data/test/reports/TEST-HammerCLI-Output-Formatters-LongTextFormatter.xml +13 -0
- data/test/reports/TEST-HammerCLI-Output-Output-adapters.xml +17 -0
- data/test/reports/TEST-HammerCLI-Output-Output-data.xml +15 -0
- data/test/reports/TEST-HammerCLI-Output-Output-formatters.xml +9 -0
- data/test/reports/TEST-HammerCLI-Output-Output-messages.xml +19 -0
- data/test/reports/TEST-HammerCLI-Output-Output.xml +7 -0
- data/test/reports/TEST-HammerCLI-Output-RecordCollection.xml +13 -0
- data/test/reports/TEST-HammerCLI-Settings-load-from-paths.xml +15 -0
- data/test/reports/TEST-HammerCLI-Settings.xml +25 -0
- data/test/reports/TEST-HammerCLI-ShellHistory-loading-old-history.xml +11 -0
- data/test/reports/TEST-HammerCLI-ShellHistory-saving-history.xml +15 -0
- data/test/reports/TEST-HammerCLI-ShellHistory.xml +7 -0
- data/test/reports/TEST-MiniTest-Spec.xml +7 -0
- data/test/reports/TEST-String-camelize.xml +11 -0
- data/test/reports/TEST-String-formatting.xml +17 -0
- data/test/reports/TEST-String-indent.xml +11 -0
- data/test/reports/TEST-String-interactive-.xml +13 -0
- data/test/reports/TEST-String.xml +7 -0
- data/test/reports/TEST-constraints-HammerCLI-Validator-AllConstraint-exist-.xml +13 -0
- data/test/reports/TEST-constraints-HammerCLI-Validator-AllConstraint.xml +7 -0
- data/test/reports/TEST-constraints-HammerCLI-Validator-AnyConstraint-exist-.xml +13 -0
- data/test/reports/TEST-constraints-HammerCLI-Validator-AnyConstraint.xml +7 -0
- data/test/reports/TEST-constraints-HammerCLI-Validator-BaseConstraint-exist-.xml +9 -0
- data/test/reports/TEST-constraints-HammerCLI-Validator-BaseConstraint-rejected.xml +13 -0
- data/test/reports/TEST-constraints-HammerCLI-Validator-BaseConstraint-required.xml +13 -0
- data/test/reports/TEST-constraints-HammerCLI-Validator-BaseConstraint.xml +7 -0
- data/test/reports/TEST-constraints.xml +7 -0
- data/test/unit/abstract_test.rb +15 -11
- data/test/unit/apipie/command_test.rb +29 -1
- data/test/unit/apipie/option_builder_test.rb +22 -0
- data/test/unit/fixtures/apipie/documented.json +44 -0
- data/test/unit/options/normalizers_test.rb +35 -0
- data/test/unit/output/adapter/csv_test.rb +104 -4
- data/test/unit/utils_test.rb +58 -0
- metadata +292 -6
@@ -12,28 +12,152 @@ module HammerCLI::Output::Adapter
|
|
12
12
|
|
13
13
|
class CSValues < Abstract
|
14
14
|
|
15
|
+
class Cell
|
16
|
+
attr_accessor :field_wrapper, :data
|
17
|
+
|
18
|
+
def initialize(field_wrapper, data, formatters)
|
19
|
+
@field_wrapper = field_wrapper
|
20
|
+
@data = data
|
21
|
+
@formatters = formatters
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.create_cells(field_wrappers, data, formatters)
|
25
|
+
results = []
|
26
|
+
field_wrappers.each do |field_wrapper|
|
27
|
+
field = field_wrapper.field
|
28
|
+
if field.is_a? Fields::Collection
|
29
|
+
results = results + expand_collection(field, data, formatters)
|
30
|
+
elsif field.is_a?(Fields::ContainerField)
|
31
|
+
results = results + expand_container(field, data, formatters)
|
32
|
+
else
|
33
|
+
results << Cell.new(field_wrapper, data, formatters)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
return results
|
37
|
+
end
|
38
|
+
|
39
|
+
def formatted_value
|
40
|
+
formatter = @formatters.formatter_for_type(@field_wrapper.field.class)
|
41
|
+
formatter ? formatter.format(value) : value.to_s
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.values(headers, cells)
|
45
|
+
headers.map do |header|
|
46
|
+
cell = cells.find { |cell| cell.in_column?(header) }
|
47
|
+
cell ? cell.formatted_value : ''
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.headers(cells, context)
|
52
|
+
cells.map(&:field_wrapper).select { |fw| ! fw.is_id? ||
|
53
|
+
context[:show_ids] }.map(&:display_name)
|
54
|
+
end
|
55
|
+
|
56
|
+
def in_column?(header)
|
57
|
+
self.field_wrapper.display_name == header
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def self.expand_collection(field, data, formatters)
|
63
|
+
results = []
|
64
|
+
collection_data = data_for_field(field, data) || []
|
65
|
+
collection_data.each_with_index do |child_data, i|
|
66
|
+
field.fields.each do |child_field|
|
67
|
+
child_field_wrapper = FieldWrapper.new(child_field)
|
68
|
+
child_field_wrapper.append_prefix(field.label)
|
69
|
+
child_field_wrapper.append_suffix((i + 1).to_s)
|
70
|
+
results << Cell.new(child_field_wrapper, collection_data[i] || {}, formatters)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
results
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.expand_container(field, data, formatters)
|
77
|
+
child_fields = FieldWrapper.wrap(field.fields)
|
78
|
+
child_fields.each{ |child| child.append_prefix(field.label) }
|
79
|
+
create_cells(child_fields, data_for_field(field, data), formatters)
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.data_for_field(field, data)
|
83
|
+
HammerCLI::Output::Adapter::CSValues.data_for_field(field, data)
|
84
|
+
end
|
85
|
+
|
86
|
+
def value
|
87
|
+
Cell.data_for_field(@field_wrapper.field, data)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
class FieldWrapper
|
92
|
+
attr_accessor :name, :field
|
93
|
+
|
94
|
+
def self.wrap(fields)
|
95
|
+
fields.map{ |f| FieldWrapper.new(f) }
|
96
|
+
end
|
97
|
+
|
98
|
+
def initialize(field)
|
99
|
+
@field = field
|
100
|
+
@name = nil
|
101
|
+
@prefixes = []
|
102
|
+
@suffixes = []
|
103
|
+
@data
|
104
|
+
end
|
105
|
+
|
106
|
+
def append_suffix(suffix)
|
107
|
+
@suffixes << suffix
|
108
|
+
end
|
109
|
+
|
110
|
+
def append_prefix(prefix)
|
111
|
+
@prefixes << prefix
|
112
|
+
end
|
113
|
+
|
114
|
+
def prefix
|
115
|
+
@prefixes.join("::")
|
116
|
+
end
|
117
|
+
|
118
|
+
def suffix
|
119
|
+
@suffixes.join("::")
|
120
|
+
end
|
121
|
+
|
122
|
+
def display_name
|
123
|
+
names = []
|
124
|
+
names << prefix unless prefix.empty?
|
125
|
+
names << @field.label if @field.label
|
126
|
+
names << suffix unless suffix.empty?
|
127
|
+
names.join("::")
|
128
|
+
end
|
129
|
+
|
130
|
+
def is_id?
|
131
|
+
self.field.class <= Fields::Id
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
15
135
|
def tags
|
16
136
|
[:flat]
|
17
137
|
end
|
18
138
|
|
139
|
+
def row_data(fields, collection)
|
140
|
+
result = []
|
141
|
+
collection.each do |data|
|
142
|
+
result << Cell.create_cells(FieldWrapper.wrap(fields), data, @formatters)
|
143
|
+
end
|
144
|
+
result
|
145
|
+
end
|
146
|
+
|
19
147
|
def print_record(fields, record)
|
20
148
|
print_collection(fields, [record].flatten(1))
|
21
149
|
end
|
22
150
|
|
23
151
|
def print_collection(fields, collection)
|
152
|
+
rows = row_data(fields, collection)
|
153
|
+
# get headers using columns heuristic
|
154
|
+
headers = rows.map{ |r| Cell.headers(r, @context) }.max_by{ |headers| headers.size }
|
155
|
+
# or use headers from output definition
|
156
|
+
headers ||= default_headers(fields)
|
24
157
|
csv_string = generate do |csv|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
collection.each do |d|
|
29
|
-
csv << fields.inject([]) do |row, f|
|
30
|
-
unless f.class <= Fields::Id && !@context[:show_ids]
|
31
|
-
value = data_for_field(f, d)
|
32
|
-
formatter = @formatters.formatter_for_type(f.class)
|
33
|
-
row << ((formatter ? formatter.format(value) : value) || '')
|
34
|
-
end
|
35
|
-
row
|
36
|
-
end
|
158
|
+
csv << headers if headers
|
159
|
+
rows.each do |row|
|
160
|
+
csv << Cell.values(headers, row)
|
37
161
|
end
|
38
162
|
end
|
39
163
|
puts csv_string
|
@@ -73,6 +197,10 @@ module HammerCLI::Output::Adapter
|
|
73
197
|
)
|
74
198
|
end
|
75
199
|
|
200
|
+
def default_headers(fields)
|
201
|
+
fields.select{ |f| !(f.class <= Fields::Id) || @context[:show_ids] }.map { |f| f.label }
|
202
|
+
end
|
203
|
+
|
76
204
|
end
|
77
205
|
|
78
206
|
HammerCLI::Output::Output.register_adapter(:csv, CSValues)
|
data/lib/hammer_cli/shell.rb
CHANGED
@@ -28,7 +28,7 @@ module HammerCLI
|
|
28
28
|
|
29
29
|
def self.load_commands(main_cls)
|
30
30
|
cmds = main_cls.recognised_subcommands.select do |sub_cmd|
|
31
|
-
!
|
31
|
+
!sub_cmd.is_called?("shell")
|
32
32
|
end
|
33
33
|
self.recognised_subcommands.push(*cmds)
|
34
34
|
end
|
@@ -103,11 +103,11 @@ module HammerCLI
|
|
103
103
|
line = HammerCLI::CompleterLine.new(line)
|
104
104
|
ShellMainCommand.run('', line, context) unless line.empty?
|
105
105
|
end
|
106
|
-
rescue Interrupt
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
106
|
+
rescue Interrupt; end
|
107
|
+
|
108
|
+
puts
|
109
|
+
system('stty', stty_save) # Restore
|
110
|
+
HammerCLI::EX_OK
|
111
111
|
end
|
112
112
|
|
113
113
|
private
|
@@ -0,0 +1,82 @@
|
|
1
|
+
|
2
|
+
module HammerCLI
|
3
|
+
|
4
|
+
module Subcommand
|
5
|
+
|
6
|
+
class LazyDefinition < Clamp::Subcommand::Definition
|
7
|
+
|
8
|
+
def initialize(names, description, subcommand_class_name, path)
|
9
|
+
@names = Array(names)
|
10
|
+
@description = description
|
11
|
+
@subcommand_class_name = subcommand_class_name
|
12
|
+
@path = path
|
13
|
+
@loaded = false
|
14
|
+
end
|
15
|
+
|
16
|
+
def loaded?
|
17
|
+
@loaded
|
18
|
+
end
|
19
|
+
|
20
|
+
def subcommand_class
|
21
|
+
if !@loaded
|
22
|
+
require @path
|
23
|
+
@loaded = true
|
24
|
+
@constantized_class = @subcommand_class_name.constantize
|
25
|
+
end
|
26
|
+
@constantized_class
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.included(base)
|
32
|
+
base.extend(ClassMethods)
|
33
|
+
end
|
34
|
+
|
35
|
+
module ClassMethods
|
36
|
+
def remove_subcommand(name)
|
37
|
+
self.recognised_subcommands.delete_if do |sc|
|
38
|
+
if sc.is_called?(name)
|
39
|
+
logger.info "subcommand #{name} (#{sc.subcommand_class}) was removed."
|
40
|
+
true
|
41
|
+
else
|
42
|
+
false
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def subcommand!(name, description, subcommand_class = self, &block)
|
48
|
+
remove_subcommand(name)
|
49
|
+
subcommand(name, description, subcommand_class, &block)
|
50
|
+
logger.info "subcommand #{name} (#{subcommand_class}) was created."
|
51
|
+
end
|
52
|
+
|
53
|
+
def subcommand(name, description, subcommand_class = self, &block)
|
54
|
+
existing = find_subcommand(name)
|
55
|
+
if existing
|
56
|
+
raise HammerCLI::CommandConflict, _("can't replace subcommand %<name>s (%<existing_class>s) with %<name>s (%<new_class>s)") % {
|
57
|
+
:name => name,
|
58
|
+
:existing_class => existing.subcommand_class,
|
59
|
+
:new_class => subcommand_class
|
60
|
+
}
|
61
|
+
end
|
62
|
+
super
|
63
|
+
end
|
64
|
+
|
65
|
+
def lazy_subcommand(name, description, subcommand_class, path)
|
66
|
+
# call original subcommand to ensure command's parameters are set correctly
|
67
|
+
# (hammer command SUBCOMMAND [ARGS] ...)
|
68
|
+
subcommand(name, description, Class)
|
69
|
+
# replace last subcommand definition with correct lazy-loaded one
|
70
|
+
recognised_subcommands[-1] = LazyDefinition.new(name, description, subcommand_class, path)
|
71
|
+
end
|
72
|
+
|
73
|
+
def lazy_subcommand!(name, description, subcommand_class, path)
|
74
|
+
remove_subcommand(name)
|
75
|
+
self.lazy_subcommand(name, description, subcommand_class, path)
|
76
|
+
logger.info "subcommand #{name} (#{subcommand_class}) was created."
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
end
|
data/lib/hammer_cli/utils.rb
CHANGED
@@ -24,6 +24,11 @@ class String
|
|
24
24
|
gsub(/^/, indent_str)
|
25
25
|
end
|
26
26
|
|
27
|
+
def constantize
|
28
|
+
raise NameError, "Can't constantize empty string" if self.empty?
|
29
|
+
HammerCLI.constant_path(self)[-1]
|
30
|
+
end
|
31
|
+
|
27
32
|
end
|
28
33
|
|
29
34
|
module HammerCLI
|
@@ -34,4 +39,12 @@ module HammerCLI
|
|
34
39
|
HammerCLI::Settings.get(:ui, :interactive) != false
|
35
40
|
end
|
36
41
|
|
42
|
+
def self.constant_path(name)
|
43
|
+
path = name.to_s.split('::').inject([Object]) do |mod, class_name|
|
44
|
+
mod << mod[-1].const_get(class_name)
|
45
|
+
end
|
46
|
+
path.shift
|
47
|
+
path
|
48
|
+
end
|
49
|
+
|
37
50
|
end
|
data/lib/hammer_cli/version.rb
CHANGED
data/locale/Makefile
CHANGED
@@ -7,6 +7,7 @@
|
|
7
7
|
# make clean - clean everything
|
8
8
|
#
|
9
9
|
DOMAIN = hammer-cli
|
10
|
+
VERSION = $(shell ruby -e 'require "rubygems";spec = Gem::Specification::load("../hammer_cli.gemspec");puts spec.version')
|
10
11
|
POTFILE = $(DOMAIN).pot
|
11
12
|
MOFILE = $(DOMAIN).mo
|
12
13
|
POFILES = $(shell find . -name '*.po')
|
@@ -45,20 +46,20 @@ uniq-po:
|
|
45
46
|
|
46
47
|
tx-pull:
|
47
48
|
tx pull -f
|
49
|
+
for f in $(POFILES) ; do \
|
50
|
+
sed -i 's/^\("Project-Id-Version: \).*$$/\1$(DOMAIN) $(VERSION)\\n"/' $$f; \
|
51
|
+
done
|
48
52
|
-git commit -a -m "i18n - extracting new, pulling from tx"
|
49
53
|
|
50
54
|
extract-strings:
|
51
|
-
bundle exec rake
|
55
|
+
bundle exec rake gettext:find
|
52
56
|
|
53
|
-
|
54
|
-
# merging po files is unnecessary when using transifex.com
|
57
|
+
reset-po:
|
58
|
+
# merging po files is unnecessary when using transifex.com
|
55
59
|
git checkout -- ../locale/*/*po
|
60
|
+
|
61
|
+
tx-update: tx-pull extract-strings reset-po $(MOFILES)
|
62
|
+
# amend mo files
|
63
|
+
git add ../locale/*/LC_MESSAGES
|
56
64
|
git commit -a --amend -m "i18n - extracting new, pulling from tx"
|
57
65
|
-echo Changes commited!
|
58
|
-
|
59
|
-
# Remove all MO files
|
60
|
-
clean:
|
61
|
-
-rm -f messages.mo
|
62
|
-
find . \( -name "*.mo" -o -name "*.pox" \) -exec rm -f '{}' ';'
|
63
|
-
find . -path *LC_MESSAGES | xargs rm -rf
|
64
|
-
|
data/locale/README.md
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Updating the translations
|
2
|
+
-------------------------
|
3
|
+
|
4
|
+
1. Check if there are any new languages with progress more than 50% on [transifex](https://www.transifex.com/projects/p/foreman/resource/hammer-cli/). If so, do the following for each of the new languages:
|
5
|
+
|
6
|
+
```
|
7
|
+
mkdir locale/<lang>
|
8
|
+
cp locale/hammer-cli.pot locale/<lang>/hammer-cli.po
|
9
|
+
```
|
10
|
+
2. Make sure you have `transifex-client` installed
|
11
|
+
|
12
|
+
3. Update the translations. From GIT repo root directory run:
|
13
|
+
|
14
|
+
```
|
15
|
+
make -C locale tx-update
|
16
|
+
```
|
17
|
+
|
18
|
+
It will download translations from transifex, generates `mo` files, updates strings in `pot` file and wraps all the changes in a new commit. Transifex automatically updates its strings when the commit is pushed to Github.
|
Binary file
|
@@ -0,0 +1,227 @@
|
|
1
|
+
# SOME DESCRIPTIVE TITLE.
|
2
|
+
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
|
3
|
+
# This file is distributed under the same license as the hammer-cli package.
|
4
|
+
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
|
5
|
+
#
|
6
|
+
#, fuzzy
|
7
|
+
msgid ""
|
8
|
+
msgstr ""
|
9
|
+
"Project-Id-Version: hammer-cli 0.1.2\n"
|
10
|
+
"Report-Msgid-Bugs-To: \n"
|
11
|
+
"POT-Creation-Date: 2014-05-09 16:07-0400\n"
|
12
|
+
"PO-Revision-Date: 2014-03-04 16:38+0000\n"
|
13
|
+
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
14
|
+
"Language-Team: LANGUAGE <LL@li.org>\n"
|
15
|
+
"Language: \n"
|
16
|
+
"MIME-Version: 1.0\n"
|
17
|
+
"Content-Type: text/plain; charset=UTF-8\n"
|
18
|
+
"Content-Transfer-Encoding: 8bit\n"
|
19
|
+
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
|
20
|
+
|
21
|
+
#: lib/hammer_cli/validator.rb:41
|
22
|
+
msgid "Unknown option name '%s'"
|
23
|
+
msgstr ""
|
24
|
+
|
25
|
+
#: lib/hammer_cli/validator.rb:62
|
26
|
+
msgid "You can't set all options %s at one time"
|
27
|
+
msgstr ""
|
28
|
+
|
29
|
+
#: lib/hammer_cli/validator.rb:63
|
30
|
+
msgid "Options %s are required"
|
31
|
+
msgstr ""
|
32
|
+
|
33
|
+
#: lib/hammer_cli/validator.rb:79
|
34
|
+
msgid "You can't set any of options %s"
|
35
|
+
msgstr ""
|
36
|
+
|
37
|
+
#: lib/hammer_cli/validator.rb:80
|
38
|
+
msgid "At least one of options %s is required"
|
39
|
+
msgstr ""
|
40
|
+
|
41
|
+
#: lib/hammer_cli/output/formatters.rb:154
|
42
|
+
msgid "no"
|
43
|
+
msgstr ""
|
44
|
+
|
45
|
+
#: lib/hammer_cli/output/formatters.rb:154
|
46
|
+
msgid "yes"
|
47
|
+
msgstr ""
|
48
|
+
|
49
|
+
#: lib/hammer_cli/output/adapter/csv.rb:47
|
50
|
+
msgid "Message"
|
51
|
+
msgstr ""
|
52
|
+
|
53
|
+
#: lib/hammer_cli/output/adapter/csv.rb:51
|
54
|
+
msgid "Id"
|
55
|
+
msgstr ""
|
56
|
+
|
57
|
+
#: lib/hammer_cli/output/adapter/csv.rb:56
|
58
|
+
msgid "Name"
|
59
|
+
msgstr ""
|
60
|
+
|
61
|
+
#: lib/hammer_cli/exception_handler.rb:60
|
62
|
+
msgid "Error: %s"
|
63
|
+
msgstr ""
|
64
|
+
|
65
|
+
#: lib/hammer_cli/exception_handler.rb:66
|
66
|
+
msgid "Error: %{message}\\n\\nSee: '%{path} --help'"
|
67
|
+
msgstr ""
|
68
|
+
|
69
|
+
#: lib/hammer_cli/exception_handler.rb:83
|
70
|
+
msgid "Invalid username or password"
|
71
|
+
msgstr ""
|
72
|
+
|
73
|
+
#: lib/hammer_cli/exception_handler.rb:90
|
74
|
+
msgid ""
|
75
|
+
"Could not load API description from the server\\n - is your server down?\\n"
|
76
|
+
"\\\\n \" - was \\\"#{rake_command}\\\" run on the server when "
|
77
|
+
"using apipie cache? (typical production settings))\\n\""
|
78
|
+
msgstr ""
|
79
|
+
|
80
|
+
#: lib/hammer_cli/logger.rb:28
|
81
|
+
msgid "No permissions to create log dir %s"
|
82
|
+
msgstr ""
|
83
|
+
|
84
|
+
#: lib/hammer_cli/logger.rb:43
|
85
|
+
msgid "File %s not writeable, won't log anything to the file!"
|
86
|
+
msgstr ""
|
87
|
+
|
88
|
+
#: lib/hammer_cli/modules.rb:10
|
89
|
+
msgid ""
|
90
|
+
"Legacy configuration of modules detected. Check section about configuration "
|
91
|
+
"in user manual"
|
92
|
+
msgstr ""
|
93
|
+
|
94
|
+
#: lib/hammer_cli/modules.rb:42
|
95
|
+
msgid "Warning: An error occured while loading module %s"
|
96
|
+
msgstr ""
|
97
|
+
|
98
|
+
#: lib/hammer_cli/shell.rb:10
|
99
|
+
msgid "Print help for commands"
|
100
|
+
msgstr ""
|
101
|
+
|
102
|
+
#: lib/hammer_cli/shell.rb:22
|
103
|
+
msgid "Exit interactive shell"
|
104
|
+
msgstr ""
|
105
|
+
|
106
|
+
#: lib/hammer_cli/shell.rb:120
|
107
|
+
msgid "Welcome to the hammer interactive shell"
|
108
|
+
msgstr ""
|
109
|
+
|
110
|
+
#: lib/hammer_cli/shell.rb:121
|
111
|
+
msgid "Type 'help' for usage information"
|
112
|
+
msgstr ""
|
113
|
+
|
114
|
+
#: lib/hammer_cli/shell.rb:122
|
115
|
+
msgid ""
|
116
|
+
"Command completion is disabled on ruby < 1.9 due to compatibility problems."
|
117
|
+
msgstr ""
|
118
|
+
|
119
|
+
#: lib/hammer_cli/shell.rb:138
|
120
|
+
msgid "Interactive shell"
|
121
|
+
msgstr ""
|
122
|
+
|
123
|
+
#: lib/hammer_cli/options/option_definition.rb:68
|
124
|
+
msgid "Can be specified multiple times. "
|
125
|
+
msgstr ""
|
126
|
+
|
127
|
+
#: lib/hammer_cli/options/option_definition.rb:69
|
128
|
+
msgid "Default: "
|
129
|
+
msgstr ""
|
130
|
+
|
131
|
+
#: lib/hammer_cli/options/option_definition.rb:69
|
132
|
+
msgid ", or "
|
133
|
+
msgstr ""
|
134
|
+
|
135
|
+
#: lib/hammer_cli/options/normalizers.rb:26
|
136
|
+
msgid "Comma-separated list of key=value."
|
137
|
+
msgstr ""
|
138
|
+
|
139
|
+
#: lib/hammer_cli/options/normalizers.rb:35
|
140
|
+
msgid "value must be defined as a comma-separated list of key=value"
|
141
|
+
msgstr ""
|
142
|
+
|
143
|
+
#: lib/hammer_cli/options/normalizers.rb:46
|
144
|
+
msgid "Comma separated list of values."
|
145
|
+
msgstr ""
|
146
|
+
|
147
|
+
#: lib/hammer_cli/options/normalizers.rb:58
|
148
|
+
msgid "One of true/false, yes/no, 1/0."
|
149
|
+
msgstr ""
|
150
|
+
|
151
|
+
#: lib/hammer_cli/options/normalizers.rb:68
|
152
|
+
msgid "value must be one of true/false, yes/no, 1/0"
|
153
|
+
msgstr ""
|
154
|
+
|
155
|
+
#: lib/hammer_cli/options/normalizers.rb:107
|
156
|
+
msgid "Unable to parse JSON input"
|
157
|
+
msgstr ""
|
158
|
+
|
159
|
+
#: lib/hammer_cli/options/normalizers.rb:120
|
160
|
+
msgid "One of %s"
|
161
|
+
msgstr ""
|
162
|
+
|
163
|
+
#: lib/hammer_cli/options/normalizers.rb:127
|
164
|
+
msgid "value must be one of '%s'"
|
165
|
+
msgstr ""
|
166
|
+
|
167
|
+
#: lib/hammer_cli/options/normalizers.rb:146
|
168
|
+
msgid "Date and time in YYYY-MM-DD HH:MM:SS or ISO 8601 format"
|
169
|
+
msgstr ""
|
170
|
+
|
171
|
+
#: lib/hammer_cli/options/normalizers.rb:153
|
172
|
+
msgid "'%s' is not a valid date"
|
173
|
+
msgstr ""
|
174
|
+
|
175
|
+
#: lib/hammer_cli/main.rb:7
|
176
|
+
msgid "be verbose"
|
177
|
+
msgstr ""
|
178
|
+
|
179
|
+
#: lib/hammer_cli/main.rb:8
|
180
|
+
msgid "show debugging output "
|
181
|
+
msgstr ""
|
182
|
+
|
183
|
+
#: lib/hammer_cli/main.rb:9
|
184
|
+
msgid "path to custom config file"
|
185
|
+
msgstr ""
|
186
|
+
|
187
|
+
#: lib/hammer_cli/main.rb:11
|
188
|
+
msgid "username to access the remote system"
|
189
|
+
msgstr ""
|
190
|
+
|
191
|
+
#: lib/hammer_cli/main.rb:13
|
192
|
+
msgid "password to access the remote system"
|
193
|
+
msgstr ""
|
194
|
+
|
195
|
+
#: lib/hammer_cli/main.rb:16
|
196
|
+
msgid "show version"
|
197
|
+
msgstr ""
|
198
|
+
|
199
|
+
#: lib/hammer_cli/main.rb:25
|
200
|
+
msgid "Show ids of associated resources"
|
201
|
+
msgstr ""
|
202
|
+
|
203
|
+
#: lib/hammer_cli/main.rb:27
|
204
|
+
msgid "Explicitly turn interactive mode on/off"
|
205
|
+
msgstr ""
|
206
|
+
|
207
|
+
#: lib/hammer_cli/main.rb:31
|
208
|
+
msgid "Output as CSV (same as --output=csv)"
|
209
|
+
msgstr ""
|
210
|
+
|
211
|
+
#: lib/hammer_cli/main.rb:32
|
212
|
+
msgid "Set output format. One of [%s]"
|
213
|
+
msgstr ""
|
214
|
+
|
215
|
+
#: lib/hammer_cli/main.rb:35
|
216
|
+
msgid "Character to separate the values"
|
217
|
+
msgstr ""
|
218
|
+
|
219
|
+
#: lib/hammer_cli/main.rb:39
|
220
|
+
msgid "Get list of possible endings"
|
221
|
+
msgstr ""
|
222
|
+
|
223
|
+
#: lib/hammer_cli/settings.rb:28
|
224
|
+
msgid ""
|
225
|
+
"Warning: location hammer.modules.d is deprecated, move your module "
|
226
|
+
"configurations to cli.modules.d"
|
227
|
+
msgstr ""
|
Binary file
|