hammer_cli 0.14.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/hammer +5 -4
- data/config/cli_config.template.yml +9 -0
- data/doc/creating_commands.md +23 -8
- data/doc/release_notes.md +9 -0
- data/lib/hammer_cli.rb +1 -0
- data/lib/hammer_cli/abstract.rb +2 -2
- data/lib/hammer_cli/context.rb +3 -5
- data/lib/hammer_cli/exception_handler.rb +3 -3
- data/lib/hammer_cli/main.rb +6 -1
- data/lib/hammer_cli/output/adapter/abstract.rb +1 -0
- data/lib/hammer_cli/output/adapter/csv.rb +0 -9
- data/lib/hammer_cli/output/adapter/json.rb +1 -9
- data/lib/hammer_cli/output/adapter/table.rb +4 -2
- data/lib/hammer_cli/output/adapter/tree_structure.rb +36 -4
- data/lib/hammer_cli/output/adapter/yaml.rb +1 -9
- data/lib/hammer_cli/output/output.rb +22 -6
- data/lib/hammer_cli/output/record_collection.rb +2 -1
- data/lib/hammer_cli/utils.rb +25 -3
- data/lib/hammer_cli/verbosity.rb +5 -0
- data/lib/hammer_cli/version.rb +1 -1
- data/locale/ca/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/de/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/en/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/en_GB/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/es/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/fr/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/it/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/ja/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/ko/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/pt_BR/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/ru/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/zh_CN/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/zh_TW/LC_MESSAGES/hammer-cli.mo +0 -0
- data/test/unit/apipie/command_test.rb +47 -0
- data/test/unit/apipie/test_helper.rb +4 -0
- data/test/unit/exception_handler_test.rb +1 -2
- data/test/unit/history_test.rb +1 -6
- data/test/unit/i18n_test.rb +6 -36
- data/test/unit/main_test.rb +8 -9
- data/test/unit/output/adapter/json_test.rb +59 -0
- data/test/unit/output/adapter/yaml_test.rb +59 -0
- data/test/unit/output/output_test.rb +173 -1
- data/test/unit/utils_test.rb +21 -22
- metadata +9 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aaf3be9933ac2bf33cd6a7bd3cd0f3d8fe3bf157
|
4
|
+
data.tar.gz: 3fd10d78572c35d887f0edc9b46d4382e4454006
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f18891b02bd45efcddf967b97bc74b58a277c28cfa8d0d22e4e339ecb9f876565e111cdc9bf670d4f122ae68cf858f398a067c75daf147b694de98573947b62
|
7
|
+
data.tar.gz: e9dee591bf84da08b467a36f155c97068951d9937e128fbb2d7b42d97af1fdd7f03040321daf5457472d66ddba55fb8677981e6180695ee130bfb1f20c32f8ce
|
data/bin/hammer
CHANGED
@@ -12,7 +12,8 @@ require 'hammer_cli/options/normalizers'
|
|
12
12
|
# Create fake command instance to use some global args before we start.
|
13
13
|
# Option descriptions are never displayed and thus do not require translation.
|
14
14
|
class PreParser < Clamp::Command
|
15
|
-
option [
|
15
|
+
option ['-v', '--[no-]verbose'], :flag, _('Be verbose (or not). True by default')
|
16
|
+
option ['-q', '--quiet'], :flag, _('Completely silent')
|
16
17
|
option ["-d", "--debug"], :flag, "show debugging output"
|
17
18
|
option ["-c", "--config"], "CFG_FILE", "path to custom config file" do |path|
|
18
19
|
File.expand_path path
|
@@ -80,7 +81,7 @@ HammerCLI::Settings.load({
|
|
80
81
|
:password => preparser.password,
|
81
82
|
:host => preparser.server,
|
82
83
|
:interactive => preparser.interactive,
|
83
|
-
:
|
84
|
+
:debug => preparser.debug?,
|
84
85
|
:no_headers => preparser.no_headers?,
|
85
86
|
:reload_cache => preparser.reload_cache?,
|
86
87
|
:verify_ssl => preparser.verify_ssl,
|
@@ -99,10 +100,10 @@ end
|
|
99
100
|
require 'hammer_cli/logger'
|
100
101
|
logger = Logging.logger['Init']
|
101
102
|
|
102
|
-
if preparser.
|
103
|
+
if preparser.debug?
|
103
104
|
root_logger = Logging.logger.root
|
104
105
|
root_logger.appenders = root_logger.appenders << ::Logging.appenders.stderr(:layout => HammerCLI::Logger::COLOR_LAYOUT)
|
105
|
-
root_logger.level = 'debug'
|
106
|
+
root_logger.level = 'debug'
|
106
107
|
end
|
107
108
|
|
108
109
|
require 'hammer_cli/version'
|
@@ -10,6 +10,9 @@
|
|
10
10
|
#:mark_translated: false
|
11
11
|
# Hide headers from output of list actions
|
12
12
|
# :no_headers: true
|
13
|
+
# Choose capitalization for JSON/YAML output.
|
14
|
+
# One of: 'downcase', 'capitalize', 'upcase'
|
15
|
+
# :capitalization: 'downcase'
|
13
16
|
|
14
17
|
# Enable/disable color output of logger in Clamp commands
|
15
18
|
:watch_plain: false
|
@@ -23,6 +26,12 @@
|
|
23
26
|
# Logging level. One of debug, info, warning, error, fatal
|
24
27
|
:log_level: 'error'
|
25
28
|
|
29
|
+
# Verbosity of the commands. Possible values:
|
30
|
+
# 0 - completely silent, errors to stderr. Equals to --quiet.
|
31
|
+
# 1 - data, interactive I/O. Equals to --no-verbose.
|
32
|
+
# 2 - data, messages, interactive I/O, progress bars. Equals to --verbose.
|
33
|
+
:verbosity: 2
|
34
|
+
|
26
35
|
#:log_owner: 'foreman'
|
27
36
|
#:log_group: 'foreman'
|
28
37
|
|
data/doc/creating_commands.md
CHANGED
@@ -244,18 +244,18 @@ option "--attributes", "ATTRIBUTES", "Values of various attributes",
|
|
244
244
|
|
245
245
|
### Advanced option evaluation
|
246
246
|
|
247
|
-
Sometimes it is necessary to tune the option values based on other parameters given on CLI.
|
247
|
+
Sometimes it is necessary to tune the option values based on other parameters given on CLI.
|
248
248
|
An example could be setting default values based on other options, values lookup in a DB, etc.
|
249
249
|
The right place for this are `OptionSources`. Abstract Hammer command uses two default option sources -
|
250
|
-
`HammerCLI::Options::Sources::CommandLine` responsible for intial population of the options,
|
250
|
+
`HammerCLI::Options::Sources::CommandLine` responsible for intial population of the options,
|
251
251
|
`HammerCLI::Options::Sources::SavedDefaults` adding defaults managed by the `defaults` command.
|
252
252
|
|
253
|
-
By overriding `option_sources` method in a command it is possible to add custom option sources
|
254
|
-
for various tasks to the list. The option sources are evaluated one by one each being given output
|
255
|
-
of the previous one as its input so the order in which the sources are listed matters.
|
253
|
+
By overriding `option_sources` method in a command it is possible to add custom option sources
|
254
|
+
for various tasks to the list. The option sources are evaluated one by one each being given output
|
255
|
+
of the previous one as its input so the order in which the sources are listed matters.
|
256
256
|
|
257
|
-
Option sources are collected only once per command call. The collection is triggered by first call
|
258
|
-
to the `options` or `all_options` method, but at latest right after the option validation
|
257
|
+
Option sources are collected only once per command call. The collection is triggered by first call
|
258
|
+
to the `options` or `all_options` method, but at latest right after the option validation
|
259
259
|
(before the command's `execute` method is invoked). The order is as follows:
|
260
260
|
1. parse
|
261
261
|
1. option normalization
|
@@ -545,6 +545,22 @@ def adapter
|
|
545
545
|
end
|
546
546
|
```
|
547
547
|
|
548
|
+
#### Verbosity
|
549
|
+
Currently Hammer [defines](https://github.com/theforeman/hammer-cli/blob/master/lib/hammer_cli/verbosity.rb) three basic verbose modes:
|
550
|
+
* __QUIET__ - Prints nothing
|
551
|
+
* __UNIX__ - Prints data only
|
552
|
+
* __VERBOSE__ - Prints data and other messages
|
553
|
+
|
554
|
+
By default Hammer works in `VERBOSE` mode, but it can be changed with specific option (see `hammer --help`) or in the configuration file.
|
555
|
+
|
556
|
+
If you want to force some messages to be printed with `print_message` in `UNIX` mode for example, you can specify `verbosity` of this message:
|
557
|
+
```ruby
|
558
|
+
class MyCommand < HammerCLI::Apipie::Command
|
559
|
+
def execute
|
560
|
+
print_message("Hello, %{name}!", { name: 'Jason' }, verbosity: HammerCLI::V_UNIX)
|
561
|
+
end
|
562
|
+
end
|
563
|
+
```
|
548
564
|
|
549
565
|
Other useful command features
|
550
566
|
-----------------------------
|
@@ -631,4 +647,3 @@ The best practice is to place module's configuration into a separate file named
|
|
631
647
|
the module. In this example it would be `~/.hammer/cli.modules.d/hello_world.yml`.
|
632
648
|
|
633
649
|
Read more about configuration locations in [the settings howto](installation.md#configuration).
|
634
|
-
|
data/doc/release_notes.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
Release notes
|
2
2
|
=============
|
3
|
+
### 0.14.0 (2018-10-24)
|
4
|
+
* Correct the gemspec ([PR #286](https://github.com/theforeman/hammer-cli/pull/286))
|
5
|
+
* Use the tty for the interactive output ([PR #289](https://github.com/theforeman/hammer-cli/pull/289)) ([#6935](http://projects.theforeman.org/issues/6935))
|
6
|
+
* Remove legacy code for ruby < 2.0 ([#21359](http://projects.theforeman.org/issues/21359))
|
7
|
+
* Verbose mode does not work and is inconsistent ([#14725](http://projects.theforeman.org/issues/14725))
|
8
|
+
* Enable formatters in json structured output ([PR #288](https://github.com/theforeman/hammer-cli/pull/288)) ([#24980](http://projects.theforeman.org/issues/24980))
|
9
|
+
* Hammer JSON output uses inconsistent capitalization ([#17010](http://projects.theforeman.org/issues/17010))
|
10
|
+
* Bump clamp dep to >=1.1 ([PR #282](https://github.com/theforeman/hammer-cli/pull/282))
|
11
|
+
|
3
12
|
### 0.14.0 (2018-08-27)
|
4
13
|
* Restore help building ([PR #280](https://github.com/theforeman/hammer-cli/pull/280)) ([#24488](http://projects.theforeman.org/issues/24488))
|
5
14
|
* Shouldn't translate the bool values in description ([#21381](http://projects.theforeman.org/issues/21381))
|
data/lib/hammer_cli.rb
CHANGED
data/lib/hammer_cli/abstract.rb
CHANGED
@@ -165,8 +165,8 @@ module HammerCLI
|
|
165
165
|
output.print_collection(definition, collection)
|
166
166
|
end
|
167
167
|
|
168
|
-
def print_message(msg, msg_params={})
|
169
|
-
output.print_message(msg, msg_params)
|
168
|
+
def print_message(msg, msg_params = {}, options = {})
|
169
|
+
output.print_message(msg, msg_params, options)
|
170
170
|
end
|
171
171
|
|
172
172
|
def self.logger(name=self)
|
data/lib/hammer_cli/context.rb
CHANGED
@@ -1,16 +1,14 @@
|
|
1
1
|
require 'hammer_cli/defaults'
|
2
2
|
|
3
3
|
module HammerCLI
|
4
|
-
|
5
4
|
def self.context
|
6
5
|
@context ||= {
|
7
6
|
:defaults => HammerCLI.defaults,
|
8
7
|
:is_tty? => HammerCLI.tty?,
|
9
8
|
:api_connection => HammerCLI::Connection.new(Logging.logger['Connection']),
|
10
|
-
:no_headers => HammerCLI::Settings.get(:ui, :no_headers)
|
9
|
+
:no_headers => HammerCLI::Settings.get(:ui, :no_headers),
|
10
|
+
:capitalization => HammerCLI.capitalization,
|
11
|
+
:verbosity => (HammerCLI::Settings.get(:verbosity) || HammerCLI::V_VERBOSE).to_i
|
11
12
|
}
|
12
13
|
end
|
13
|
-
|
14
14
|
end
|
15
|
-
|
16
|
-
|
@@ -49,8 +49,8 @@ module HammerCLI
|
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
|
-
def print_message(msg)
|
53
|
-
output.print_message(msg)
|
52
|
+
def print_message(msg, options = {})
|
53
|
+
output.print_message(msg, nil, options)
|
54
54
|
end
|
55
55
|
|
56
56
|
def log_full_error(e, message = e.message)
|
@@ -75,7 +75,7 @@ module HammerCLI
|
|
75
75
|
end
|
76
76
|
|
77
77
|
def handle_help_wanted(e)
|
78
|
-
print_message e.command.help
|
78
|
+
print_message e.command.help, verbosity: HammerCLI::V_QUIET
|
79
79
|
HammerCLI::EX_OK
|
80
80
|
end
|
81
81
|
|
data/lib/hammer_cli/main.rb
CHANGED
@@ -4,7 +4,12 @@ module HammerCLI
|
|
4
4
|
|
5
5
|
class MainCommand < AbstractCommand
|
6
6
|
|
7
|
-
option [
|
7
|
+
option ['-v', '--[no-]verbose'], :flag, _('Be verbose (or not). True by default') do |value|
|
8
|
+
context[:verbosity] = value == true ? HammerCLI::V_VERBOSE : HammerCLI::V_UNIX
|
9
|
+
end
|
10
|
+
option ['-q', '--quiet'], :flag, _('Completely silent') do
|
11
|
+
context[:verbosity] = HammerCLI::V_QUIET
|
12
|
+
end
|
8
13
|
option ["-d", "--debug"], :flag, _("Show debugging output"), :context_target => :debug
|
9
14
|
option ["-r", "--reload-cache"], :flag, _("Force reload of Apipie cache")
|
10
15
|
|
@@ -7,6 +7,7 @@ module HammerCLI::Output::Adapter
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def initialize(context={}, formatters={})
|
10
|
+
context[:verbosity] ||= HammerCLI::V_VERBOSE
|
10
11
|
@context = context
|
11
12
|
@formatters = HammerCLI::Output::Formatters::FormatterLibrary.new(filter_formatters(formatters))
|
12
13
|
@paginate_by_default = true
|
@@ -1,13 +1,4 @@
|
|
1
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
2
|
require File.join(File.dirname(__FILE__), 'wrapper_formatter')
|
12
3
|
|
13
4
|
module HammerCLI::Output::Adapter
|
@@ -12,15 +12,7 @@ module HammerCLI::Output::Adapter
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def print_message(msg, msg_params={})
|
15
|
-
|
16
|
-
name = msg_params["name"] || msg_params[:name]
|
17
|
-
|
18
|
-
data = {
|
19
|
-
:message => msg.format(msg_params)
|
20
|
-
}
|
21
|
-
data[:id] = id unless id.nil?
|
22
|
-
data[:name] = name unless name.nil?
|
23
|
-
|
15
|
+
data = prepare_message(msg, msg_params)
|
24
16
|
puts JSON.pretty_generate(data)
|
25
17
|
end
|
26
18
|
|
@@ -53,8 +53,10 @@ module HammerCLI::Output::Adapter
|
|
53
53
|
# and there is no --no-headers option
|
54
54
|
output_stream.puts line unless formatted_collection.empty? || @context[:no_headers]
|
55
55
|
|
56
|
-
if
|
57
|
-
|
56
|
+
if @context[:verbosity] >= collection.meta.pagination_verbosity &&
|
57
|
+
collection.respond_to?(:meta) && collection.meta.pagination_set? &&
|
58
|
+
collection.count < collection.meta.subtotal
|
59
|
+
pages = (collection.meta.subtotal.to_f / collection.meta.per_page).ceil
|
58
60
|
puts _("Page %{page} of %{total} (use --page and --per-page for navigation).") % {:page => collection.meta.page, :total => pages}
|
59
61
|
end
|
60
62
|
end
|
@@ -6,12 +6,30 @@ module HammerCLI::Output::Adapter
|
|
6
6
|
@paginate_by_default = false
|
7
7
|
end
|
8
8
|
|
9
|
+
def tags
|
10
|
+
[
|
11
|
+
:data
|
12
|
+
]
|
13
|
+
end
|
14
|
+
|
9
15
|
def prepare_collection(fields, collection)
|
10
16
|
collection.map do |element|
|
11
17
|
render_fields(fields, element)
|
12
18
|
end
|
13
19
|
end
|
14
20
|
|
21
|
+
def prepare_message(msg, msg_params = {})
|
22
|
+
id = msg_params['id'] || msg_params[:id]
|
23
|
+
name = msg_params['name'] || msg_params[:name]
|
24
|
+
|
25
|
+
data = {
|
26
|
+
capitalize(:message) => msg.format(msg_params)
|
27
|
+
}
|
28
|
+
data[capitalize(:id)] = id unless id.nil?
|
29
|
+
data[capitalize(:name)] = name unless name.nil?
|
30
|
+
data
|
31
|
+
end
|
32
|
+
|
15
33
|
protected
|
16
34
|
|
17
35
|
def field_filter
|
@@ -26,7 +44,7 @@ module HammerCLI::Output::Adapter
|
|
26
44
|
fields.reduce({}) do |hash, field|
|
27
45
|
field_data = data_for_field(field, data)
|
28
46
|
next unless field.display?(field_data)
|
29
|
-
hash.update(field.label => render_field(field, field_data))
|
47
|
+
hash.update(capitalize(field.label) => render_field(field, field_data))
|
30
48
|
end
|
31
49
|
end
|
32
50
|
|
@@ -38,15 +56,24 @@ module HammerCLI::Output::Adapter
|
|
38
56
|
end
|
39
57
|
render_data(field, map_data(fields_data))
|
40
58
|
else
|
41
|
-
|
59
|
+
formatter = @formatters.formatter_for_type(field.class)
|
60
|
+
parameters = field.parameters
|
61
|
+
parameters[:context] = @context
|
62
|
+
if formatter
|
63
|
+
data = formatter.format(data, field.parameters)
|
64
|
+
end
|
65
|
+
|
66
|
+
return data unless data.is_a?(Hash)
|
67
|
+
data.transform_keys { |key| capitalize(key) }
|
42
68
|
end
|
43
69
|
end
|
44
70
|
|
45
71
|
def render_data(field, data)
|
72
|
+
data = data.map! { |d| d.transform_keys { |key| capitalize(key) } if d.is_a?(Hash) }
|
46
73
|
if field.is_a?(Fields::Collection)
|
47
|
-
if
|
74
|
+
if field.parameters[:numbered]
|
48
75
|
numbered_data(data)
|
49
|
-
else
|
76
|
+
else
|
50
77
|
data
|
51
78
|
end
|
52
79
|
else
|
@@ -69,5 +96,10 @@ module HammerCLI::Output::Adapter
|
|
69
96
|
end
|
70
97
|
end
|
71
98
|
|
99
|
+
def capitalize(string)
|
100
|
+
capitalization = @context[:capitalization]
|
101
|
+
return string if capitalization.nil?
|
102
|
+
string.send(@context[:capitalization]) unless string.nil?
|
103
|
+
end
|
72
104
|
end
|
73
105
|
end
|
@@ -12,15 +12,7 @@ module HammerCLI::Output::Adapter
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def print_message(msg, msg_params={})
|
15
|
-
|
16
|
-
name = msg_params["name"] || msg_params[:name]
|
17
|
-
|
18
|
-
data = {
|
19
|
-
:message => msg.format(msg_params)
|
20
|
-
}
|
21
|
-
data[:id] = id unless id.nil?
|
22
|
-
data[:name] = name unless name.nil?
|
23
|
-
|
15
|
+
data = prepare_message(msg, msg_params)
|
24
16
|
puts YAML.dump(data)
|
25
17
|
end
|
26
18
|
|
@@ -8,29 +8,30 @@ module HammerCLI::Output
|
|
8
8
|
class Output
|
9
9
|
|
10
10
|
def initialize(context={}, options={})
|
11
|
+
context[:verbosity] ||= HammerCLI::V_VERBOSE
|
11
12
|
self.context = context
|
12
13
|
self.default_adapter = options[:default_adapter]
|
13
14
|
end
|
14
15
|
|
15
16
|
attr_accessor :default_adapter
|
16
17
|
|
17
|
-
def print_message(msg, msg_params={})
|
18
|
-
adapter.print_message(msg.to_s, msg_params)
|
18
|
+
def print_message(msg, msg_params = {}, options = {})
|
19
|
+
adapter.print_message(msg.to_s, msg_params) if appropriate_verbosity?(:message, options)
|
19
20
|
end
|
20
21
|
|
21
|
-
def print_error(msg, details=nil, msg_params={})
|
22
|
-
adapter.print_error(msg.to_s, details, msg_params)
|
22
|
+
def print_error(msg, details=nil, msg_params = {}, options = {})
|
23
|
+
adapter.print_error(msg.to_s, details, msg_params) if appropriate_verbosity?(:error, options)
|
23
24
|
end
|
24
25
|
|
25
26
|
def print_record(definition, record)
|
26
|
-
adapter.print_record(definition.fields, record)
|
27
|
+
adapter.print_record(definition.fields, record) if appropriate_verbosity?(:record)
|
27
28
|
end
|
28
29
|
|
29
30
|
def print_collection(definition, collection)
|
30
31
|
unless collection.class <= HammerCLI::Output::RecordCollection
|
31
32
|
collection = HammerCLI::Output::RecordCollection.new([collection].flatten(1))
|
32
33
|
end
|
33
|
-
adapter.print_collection(definition.fields, collection)
|
34
|
+
adapter.print_collection(definition.fields, collection) if appropriate_verbosity?(:collection)
|
34
35
|
end
|
35
36
|
|
36
37
|
def adapter
|
@@ -66,6 +67,21 @@ module HammerCLI::Output
|
|
66
67
|
end
|
67
68
|
end
|
68
69
|
|
70
|
+
protected
|
71
|
+
|
72
|
+
def appropriate_verbosity?(msg_type, options = {})
|
73
|
+
default = case msg_type
|
74
|
+
when :message
|
75
|
+
HammerCLI::V_VERBOSE
|
76
|
+
when :error
|
77
|
+
HammerCLI::V_QUIET
|
78
|
+
when :record, :collection
|
79
|
+
HammerCLI::V_UNIX
|
80
|
+
end
|
81
|
+
msg_verbosity = options[:verbosity] || default
|
82
|
+
context[:verbosity] >= msg_verbosity
|
83
|
+
end
|
84
|
+
|
69
85
|
private
|
70
86
|
|
71
87
|
attr_accessor :context
|
@@ -3,7 +3,7 @@ module HammerCLI::Output
|
|
3
3
|
|
4
4
|
class MetaData
|
5
5
|
|
6
|
-
attr_accessor :total, :subtotal, :page, :per_page, :search, :sort_by, :sort_order
|
6
|
+
attr_accessor :total, :subtotal, :page, :per_page, :search, :sort_by, :sort_order, :pagination_verbosity
|
7
7
|
|
8
8
|
def initialize(options={})
|
9
9
|
@total = options[:total].to_i if options[:total]
|
@@ -13,6 +13,7 @@ module HammerCLI::Output
|
|
13
13
|
@search = options[:search]
|
14
14
|
@sort_by = options[:sort_by]
|
15
15
|
@sort_order = options[:sort_order]
|
16
|
+
@pagination_verbosity = options[:pagination_verbosity] || HammerCLI::V_VERBOSE
|
16
17
|
end
|
17
18
|
|
18
19
|
def pagination_set?
|
data/lib/hammer_cli/utils.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
|
+
require 'highline'
|
1
2
|
|
2
3
|
class String
|
3
|
-
|
4
|
-
# string formatting for ruby 1.8
|
5
4
|
def format(params)
|
6
5
|
if params.is_a? Hash
|
7
6
|
array_params = self.scan(/%[<{]([^>}]*)[>}]/).collect do |name|
|
@@ -42,6 +41,18 @@ class String
|
|
42
41
|
|
43
42
|
end
|
44
43
|
|
44
|
+
class Hash
|
45
|
+
# for ruby < 2.5.0
|
46
|
+
def transform_keys
|
47
|
+
result = {}
|
48
|
+
each do |key, value|
|
49
|
+
new_key = yield key
|
50
|
+
result[new_key] = value
|
51
|
+
end
|
52
|
+
result
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
45
56
|
module HammerCLI
|
46
57
|
|
47
58
|
def self.tty?
|
@@ -49,7 +60,6 @@ module HammerCLI
|
|
49
60
|
end
|
50
61
|
|
51
62
|
def self.interactive?
|
52
|
-
return false unless tty?
|
53
63
|
return HammerCLI::Settings.get(:_params, :interactive) unless HammerCLI::Settings.get(:_params, :interactive).nil?
|
54
64
|
HammerCLI::Settings.get(:ui, :interactive) != false
|
55
65
|
end
|
@@ -62,4 +72,16 @@ module HammerCLI
|
|
62
72
|
path
|
63
73
|
end
|
64
74
|
|
75
|
+
def self.capitalization
|
76
|
+
supported = %w[downcase capitalize upcase]
|
77
|
+
capitalization = HammerCLI::Settings.get(:ui, :capitalization).to_s
|
78
|
+
return nil if capitalization.empty?
|
79
|
+
return capitalization if supported.include?(capitalization)
|
80
|
+
warn _("Cannot use such capitalization. Try one of %s.") % supported.join(', ')
|
81
|
+
nil
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.interactive_output
|
85
|
+
@interactive_output ||= HighLine.new($stdin, IO.new(IO.sysopen('/dev/tty', 'w'), 'w'))
|
86
|
+
end
|
65
87
|
end
|
data/lib/hammer_cli/version.rb
CHANGED
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -128,4 +128,51 @@ describe HammerCLI::Apipie::Command do
|
|
128
128
|
|
129
129
|
end
|
130
130
|
|
131
|
+
context 'verbosity' do
|
132
|
+
class MessagesCommand < HammerCLI::Apipie::Command
|
133
|
+
def execute
|
134
|
+
messages = %w[quiet unix verbose very_verbose]
|
135
|
+
print_message(messages[0], {}, verbosity: HammerCLI::V_QUIET)
|
136
|
+
print_message(messages[1], {}, verbosity: HammerCLI::V_UNIX)
|
137
|
+
print_message(messages[2], {}, verbosity: HammerCLI::V_VERBOSE)
|
138
|
+
print_message(messages[3], {}, verbosity: HammerCLI::V_VERBOSE + 1)
|
139
|
+
HammerCLI::EX_OK
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
let(:messages) { %w[quiet unix verbose very_verbose] }
|
144
|
+
|
145
|
+
it 'should print quiet messages only when hammer verbosity level is V_QUIET' do
|
146
|
+
expected_messages = [
|
147
|
+
messages[0],
|
148
|
+
''
|
149
|
+
].join("\n")
|
150
|
+
expected_result = success_result(expected_messages)
|
151
|
+
result = run_cmd([], { :verbosity => HammerCLI::V_QUIET }, MessagesCommand)
|
152
|
+
assert_cmd(expected_result, result)
|
153
|
+
end
|
154
|
+
|
155
|
+
it 'should print quiet + no-verbose messages only when hammer verbosity level is V_UNIX' do
|
156
|
+
expected_messages = [
|
157
|
+
messages[0],
|
158
|
+
messages[1],
|
159
|
+
''
|
160
|
+
].join("\n")
|
161
|
+
expected_result = success_result(expected_messages)
|
162
|
+
result = run_cmd([], { :verbosity => HammerCLI::V_UNIX }, MessagesCommand)
|
163
|
+
assert_cmd(expected_result, result)
|
164
|
+
end
|
165
|
+
|
166
|
+
it 'should print quiet + no-verbose + verbose messages only when hammer verbosity level is V_VERBOSE' do
|
167
|
+
expected_messages = [
|
168
|
+
messages[0],
|
169
|
+
messages[1],
|
170
|
+
messages[2],
|
171
|
+
''
|
172
|
+
].join("\n")
|
173
|
+
expected_result = success_result(expected_messages)
|
174
|
+
result = run_cmd([], { :verbosity => HammerCLI::V_VERBOSE }, MessagesCommand)
|
175
|
+
assert_cmd(expected_result, result)
|
176
|
+
end
|
177
|
+
end
|
131
178
|
end
|
@@ -30,7 +30,7 @@ describe HammerCLI::ExceptionHandler do
|
|
30
30
|
end
|
31
31
|
|
32
32
|
it "should handle help request" do
|
33
|
-
output.expects(:print_message).with(cmd.help)
|
33
|
+
output.expects(:print_message).with(cmd.help, nil, verbosity: HammerCLI::V_QUIET)
|
34
34
|
handler.handle_exception(Clamp::HelpWanted.new(cmd), :heading => heading)
|
35
35
|
|
36
36
|
end
|
@@ -56,4 +56,3 @@ describe HammerCLI::ExceptionHandler do
|
|
56
56
|
end
|
57
57
|
|
58
58
|
end
|
59
|
-
|
data/test/unit/history_test.rb
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
require 'tempfile'
|
2
2
|
|
3
3
|
describe HammerCLI::ShellHistory do
|
4
|
-
|
5
4
|
before :each do
|
6
|
-
|
7
|
-
while not Readline::HISTORY.empty?
|
8
|
-
Readline::HISTORY.pop
|
9
|
-
end
|
5
|
+
Readline::HISTORY.clear
|
10
6
|
end
|
11
7
|
|
12
8
|
let :history_file do
|
@@ -68,4 +64,3 @@ describe HammerCLI::ShellHistory do
|
|
68
64
|
end
|
69
65
|
|
70
66
|
end
|
71
|
-
|
data/test/unit/i18n_test.rb
CHANGED
@@ -40,52 +40,23 @@ describe HammerCLI::I18n do
|
|
40
40
|
let(:domain2) { TestLocaleDomain.new('domain2', true) }
|
41
41
|
let(:unavailable_domain) { TestLocaleDomain.new('domain3', false) }
|
42
42
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
it "creates base merge repository" do
|
47
|
-
HammerCLI::I18n.translation_repository.class.must_equal FastGettext::TranslationRepository::Merge
|
48
|
-
end
|
49
|
-
|
50
|
-
it "registers available domains at gettext" do
|
51
|
-
repo = mock
|
52
|
-
FastGettext::TranslationRepository.expects(:build).with(domain1.domain_name,
|
53
|
-
:path => domain1.locale_dir,
|
54
|
-
:type => domain1.type,
|
55
|
-
:report_warning => false).returns(repo)
|
56
|
-
|
57
|
-
HammerCLI::I18n.translation_repository.expects(:add_repo).with(repo)
|
58
|
-
HammerCLI::I18n.add_domain(domain1)
|
59
|
-
end
|
60
|
-
|
61
|
-
it "skips registering domains that are not available" do
|
62
|
-
HammerCLI::I18n.add_domain(domain1)
|
63
|
-
HammerCLI::I18n.add_domain(domain2)
|
64
|
-
HammerCLI::I18n.add_domain(unavailable_domain)
|
65
|
-
HammerCLI::I18n.domains.must_equal [domain1, domain2]
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
describe "with fast_gettext < 1.2.0" do
|
71
|
-
let(:fast_gettext_version) { '1.1.0' }
|
72
|
-
|
73
|
-
it "creates base chain repository" do
|
74
|
-
HammerCLI::I18n.translation_repository.class.must_equal FastGettext::TranslationRepository::Chain
|
43
|
+
describe 'with fast_gettext >= 1.2.0' do
|
44
|
+
it 'creates base merge repository' do
|
45
|
+
HammerCLI::I18n.translation_repository.class.must_equal FastGettext::TranslationRepository::Merge
|
75
46
|
end
|
76
47
|
|
77
|
-
it
|
48
|
+
it 'registers available domains at gettext' do
|
78
49
|
repo = mock
|
79
50
|
FastGettext::TranslationRepository.expects(:build).with(domain1.domain_name,
|
80
51
|
:path => domain1.locale_dir,
|
81
52
|
:type => domain1.type,
|
82
53
|
:report_warning => false).returns(repo)
|
83
54
|
|
84
|
-
HammerCLI::I18n.translation_repository.
|
55
|
+
HammerCLI::I18n.translation_repository.expects(:add_repo).with(repo)
|
85
56
|
HammerCLI::I18n.add_domain(domain1)
|
86
57
|
end
|
87
58
|
|
88
|
-
it
|
59
|
+
it 'skips registering domains that are not available' do
|
89
60
|
HammerCLI::I18n.add_domain(domain1)
|
90
61
|
HammerCLI::I18n.add_domain(domain2)
|
91
62
|
HammerCLI::I18n.add_domain(unavailable_domain)
|
@@ -93,4 +64,3 @@ describe HammerCLI::I18n do
|
|
93
64
|
end
|
94
65
|
end
|
95
66
|
end
|
96
|
-
|
data/test/unit/main_test.rb
CHANGED
@@ -41,16 +41,15 @@ describe HammerCLI::MainCommand do
|
|
41
41
|
end
|
42
42
|
|
43
43
|
|
44
|
-
describe
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
44
|
+
describe 'verbose' do
|
45
|
+
it 'stores verbosity level into context' do
|
46
|
+
cmd.run(['-v'])
|
47
|
+
context[:verbosity].must_equal HammerCLI::V_VERBOSE
|
48
|
+
cmd.run(['--no-verbose'])
|
49
|
+
context[:verbosity].must_equal HammerCLI::V_UNIX
|
50
|
+
cmd.run(['--quiet'])
|
51
|
+
context[:verbosity].must_equal HammerCLI::V_QUIET
|
49
52
|
end
|
50
|
-
|
51
53
|
end
|
52
|
-
|
53
54
|
end
|
54
|
-
|
55
55
|
end
|
56
|
-
|
@@ -245,6 +245,65 @@ describe HammerCLI::Output::Adapter::Json do
|
|
245
245
|
proc { adapter.print_collection(fields, data) }.must_output(expected_output)
|
246
246
|
end
|
247
247
|
|
248
|
+
context 'capitalization' do
|
249
|
+
let(:fields) { [name, surname] }
|
250
|
+
let(:raw_hash) { { 'Name' => 'John', 'Surname' => 'Doe' } }
|
251
|
+
let(:settings) { HammerCLI::Settings }
|
252
|
+
let(:context) { { :capitalization => HammerCLI.capitalization } }
|
253
|
+
|
254
|
+
it 'should respect selected downcase capitalization' do
|
255
|
+
settings.load({ :ui => { :capitalization => :downcase } })
|
256
|
+
hash = [raw_hash.transform_keys(&:downcase)]
|
257
|
+
expected_output = JSON.pretty_generate(hash) + "\n"
|
258
|
+
out, = capture_io do
|
259
|
+
adapter.print_collection(fields, data)
|
260
|
+
end
|
261
|
+
out.must_equal(expected_output)
|
262
|
+
end
|
263
|
+
|
264
|
+
it 'should respect selected capitalize capitalization' do
|
265
|
+
settings.load({ :ui => { :capitalization => :capitalize } })
|
266
|
+
hash = [raw_hash.transform_keys(&:capitalize)]
|
267
|
+
expected_output = JSON.pretty_generate(hash) + "\n"
|
268
|
+
out, = capture_io do
|
269
|
+
adapter.print_collection(fields, data)
|
270
|
+
end
|
271
|
+
out.must_equal(expected_output)
|
272
|
+
end
|
273
|
+
|
274
|
+
it 'should respect selected upcase capitalization' do
|
275
|
+
settings.load({ :ui => { :capitalization => :upcase } })
|
276
|
+
hash = [raw_hash.transform_keys(&:upcase)]
|
277
|
+
expected_output = JSON.pretty_generate(hash) + "\n"
|
278
|
+
out, = capture_io do
|
279
|
+
adapter.print_collection(fields, data)
|
280
|
+
end
|
281
|
+
out.must_equal(expected_output)
|
282
|
+
end
|
283
|
+
|
284
|
+
it 'should print a warn for not supported capitalization' do
|
285
|
+
settings.load({ :ui => { :capitalization => :unsupported } })
|
286
|
+
hash = [raw_hash]
|
287
|
+
expected_error = "Cannot use such capitalization. Try one of downcase, capitalize, upcase.\n"
|
288
|
+
expected_output = JSON.pretty_generate(hash) + "\n"
|
289
|
+
out, err = capture_io do
|
290
|
+
adapter.print_collection(fields, data)
|
291
|
+
end
|
292
|
+
out.must_equal(expected_output)
|
293
|
+
err.must_equal(expected_error)
|
294
|
+
end
|
295
|
+
|
296
|
+
it "shouldn't change capitalization if wasn't selected" do
|
297
|
+
settings.load({ :ui => { :capitalization => nil } })
|
298
|
+
hash = [raw_hash]
|
299
|
+
expected_output = JSON.pretty_generate(hash) + "\n"
|
300
|
+
out, = capture_io do
|
301
|
+
adapter.print_collection(fields, data)
|
302
|
+
end
|
303
|
+
out.must_equal(expected_output)
|
304
|
+
end
|
305
|
+
end
|
306
|
+
|
248
307
|
context "show ids" do
|
249
308
|
|
250
309
|
let(:context) { {:show_ids => true} }
|
@@ -242,6 +242,65 @@ describe HammerCLI::Output::Adapter::Yaml do
|
|
242
242
|
proc { adapter.print_collection(fields, data) }.must_output(expected_output)
|
243
243
|
end
|
244
244
|
|
245
|
+
context 'capitalization' do
|
246
|
+
let(:fields) { [name, surname] }
|
247
|
+
let(:raw_hash) { { 'Name' => 'John', 'Surname' => 'Doe' } }
|
248
|
+
let(:settings) { HammerCLI::Settings }
|
249
|
+
let(:context) { { :capitalization => HammerCLI.capitalization } }
|
250
|
+
|
251
|
+
it 'should respect selected downcase capitalization' do
|
252
|
+
settings.load({ :ui => { :capitalization => :downcase } })
|
253
|
+
hash = [raw_hash.transform_keys(&:downcase)]
|
254
|
+
expected_output = YAML.dump(hash)
|
255
|
+
out, = capture_io do
|
256
|
+
adapter.print_collection(fields, data)
|
257
|
+
end
|
258
|
+
out.must_equal(expected_output)
|
259
|
+
end
|
260
|
+
|
261
|
+
it 'should respect selected capitalize capitalization' do
|
262
|
+
settings.load({ :ui => { :capitalization => :capitalize } })
|
263
|
+
hash = [raw_hash.transform_keys(&:capitalize)]
|
264
|
+
expected_output = YAML.dump(hash)
|
265
|
+
out, = capture_io do
|
266
|
+
adapter.print_collection(fields, data)
|
267
|
+
end
|
268
|
+
out.must_equal(expected_output)
|
269
|
+
end
|
270
|
+
|
271
|
+
it 'should respect selected upcase capitalization' do
|
272
|
+
settings.load({ :ui => { :capitalization => :upcase } })
|
273
|
+
hash = [raw_hash.transform_keys(&:upcase)]
|
274
|
+
expected_output = YAML.dump(hash)
|
275
|
+
out, = capture_io do
|
276
|
+
adapter.print_collection(fields, data)
|
277
|
+
end
|
278
|
+
out.must_equal(expected_output)
|
279
|
+
end
|
280
|
+
|
281
|
+
it 'should print a warn for not supported capitalization' do
|
282
|
+
settings.load({ :ui => { :capitalization => :unsupported } })
|
283
|
+
hash = [raw_hash]
|
284
|
+
expected_error = "Cannot use such capitalization. Try one of downcase, capitalize, upcase.\n"
|
285
|
+
expected_output = YAML.dump(hash)
|
286
|
+
out, err = capture_io do
|
287
|
+
adapter.print_collection(fields, data)
|
288
|
+
end
|
289
|
+
out.must_equal(expected_output)
|
290
|
+
err.must_equal(expected_error)
|
291
|
+
end
|
292
|
+
|
293
|
+
it "shouldn't change capitalization if wasn't selected" do
|
294
|
+
settings.load({ :ui => { :capitalization => nil } })
|
295
|
+
hash = [raw_hash]
|
296
|
+
expected_output = YAML.dump(hash)
|
297
|
+
out, = capture_io do
|
298
|
+
adapter.print_collection(fields, data)
|
299
|
+
end
|
300
|
+
out.must_equal(expected_output)
|
301
|
+
end
|
302
|
+
end
|
303
|
+
|
245
304
|
context "show ids" do
|
246
305
|
|
247
306
|
let(:context) { {:show_ids => true} }
|
@@ -112,5 +112,177 @@ describe HammerCLI::Output::Output do
|
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
115
|
-
|
115
|
+
describe 'verbosity' do
|
116
|
+
let(:msg) { "Some message\n" }
|
117
|
+
let(:quiet_opts) { { :verbosity => HammerCLI::V_QUIET } }
|
118
|
+
let(:no_verbose_opts) { { :verbosity => HammerCLI::V_UNIX } }
|
119
|
+
let(:verbose_opts) { { :verbosity => HammerCLI::V_VERBOSE } }
|
120
|
+
let(:very_verbose_opts) { { :verbosity => HammerCLI::V_VERBOSE + 1 } }
|
121
|
+
let(:data) do
|
122
|
+
HammerCLI::Output::RecordCollection.new(
|
123
|
+
[{
|
124
|
+
:id => 112,
|
125
|
+
:name => 'John',
|
126
|
+
:surname => 'Doe'
|
127
|
+
}]
|
128
|
+
)
|
129
|
+
end
|
130
|
+
let(:id) { Fields::Id.new(:path => [:id], :label => 'Id') }
|
131
|
+
let(:name) { Fields::Field.new(:path => [:name], :label => 'Name') }
|
132
|
+
let(:surname) { Fields::Field.new(:path => [:surname], :label => 'Surname') }
|
133
|
+
let(:definition) { HammerCLI::Output::Definition.new }
|
134
|
+
let(:expected_record_output) do
|
135
|
+
[
|
136
|
+
"Name: John",
|
137
|
+
"Surname: Doe",
|
138
|
+
"\n"
|
139
|
+
].join("\n")
|
140
|
+
end
|
141
|
+
|
142
|
+
context 'quiet' do
|
143
|
+
let(:context) { quiet_opts }
|
144
|
+
let(:output) { HammerCLI::Output::Output.new(context) }
|
145
|
+
|
146
|
+
it 'should not print info messages with higher verbosity level' do
|
147
|
+
assert_output('', nil) do
|
148
|
+
output.print_message(msg)
|
149
|
+
end
|
150
|
+
assert_output('', nil) do
|
151
|
+
output.print_message(msg, {}, no_verbose_opts)
|
152
|
+
end
|
153
|
+
assert_output('', nil) do
|
154
|
+
output.print_message(msg, {}, verbose_opts)
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
it 'should print message with lower or equal verbosity level' do
|
159
|
+
assert_output(msg, nil) do
|
160
|
+
output.print_message(msg, {}, quiet_opts)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
it 'should print error message even when hammer verbosity is level 0' do
|
165
|
+
assert_output(nil, msg) do
|
166
|
+
output.print_error(msg)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
it 'should not print error messages with higher verbosity level' do
|
171
|
+
assert_output(nil, '') do
|
172
|
+
output.print_error(msg, nil, {}, verbose_opts)
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
it 'should not print record data' do
|
177
|
+
definition.append([id, name, surname])
|
178
|
+
assert_output('', nil) do
|
179
|
+
output.print_record(definition, data.first)
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
it 'should not print collection data' do
|
184
|
+
definition.append([id, name, surname])
|
185
|
+
assert_output('', nil) do
|
186
|
+
output.print_record(definition, data)
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
context 'no-verbose' do
|
192
|
+
let(:context) { no_verbose_opts }
|
193
|
+
let(:output) { HammerCLI::Output::Output.new(context) }
|
194
|
+
|
195
|
+
it 'should not print info messages with higher verbosity level' do
|
196
|
+
assert_output('', nil) do
|
197
|
+
output.print_message(msg)
|
198
|
+
end
|
199
|
+
assert_output('', nil) do
|
200
|
+
output.print_message(msg, {}, verbose_opts)
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
it 'should print message with lower or equal verbosity level' do
|
205
|
+
assert_output(msg, nil) do
|
206
|
+
output.print_message(msg, {}, quiet_opts)
|
207
|
+
end
|
208
|
+
assert_output(msg, nil) do
|
209
|
+
output.print_message(msg, {}, no_verbose_opts)
|
210
|
+
end
|
211
|
+
end
|
116
212
|
|
213
|
+
it 'should print error message' do
|
214
|
+
assert_output(nil, msg) do
|
215
|
+
output.print_error(msg)
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
it 'should not print error messages with higher verbosity level' do
|
220
|
+
assert_output(nil, '') do
|
221
|
+
output.print_error(msg, nil, {}, verbose_opts)
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
it 'should print record data' do
|
226
|
+
definition.append([id, name, surname])
|
227
|
+
assert_output(expected_record_output, nil) do
|
228
|
+
output.print_record(definition, data.first)
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
it 'should print collection data' do
|
233
|
+
definition.append([id, name, surname])
|
234
|
+
assert_output(expected_record_output, nil) do
|
235
|
+
output.print_record(definition, data)
|
236
|
+
end
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
context 'verbose' do
|
241
|
+
let(:context) { verbose_opts }
|
242
|
+
let(:output) { HammerCLI::Output::Output.new(context) }
|
243
|
+
it 'should not print info messages with higher verbosity level' do
|
244
|
+
assert_output('', nil) do
|
245
|
+
output.print_message(msg, {}, very_verbose_opts)
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
it 'should print message with lower or equal verbosity level' do
|
250
|
+
assert_output(msg, nil) do
|
251
|
+
output.print_message(msg, {}, quiet_opts)
|
252
|
+
end
|
253
|
+
assert_output(msg, nil) do
|
254
|
+
output.print_message(msg, {}, no_verbose_opts)
|
255
|
+
end
|
256
|
+
assert_output(msg, nil) do
|
257
|
+
output.print_message(msg, {}, verbose_opts)
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
it 'should print error message' do
|
262
|
+
assert_output(nil, msg) do
|
263
|
+
output.print_error(msg)
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
267
|
+
it 'should not print error messages with higher verbosity level' do
|
268
|
+
assert_output(nil, '') do
|
269
|
+
output.print_error(msg, nil, {}, very_verbose_opts)
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
273
|
+
it 'should print record data' do
|
274
|
+
definition.append([id, name, surname])
|
275
|
+
assert_output(expected_record_output, nil) do
|
276
|
+
output.print_record(definition, data.first)
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
it 'should print collection data' do
|
281
|
+
definition.append([id, name, surname])
|
282
|
+
assert_output(expected_record_output, nil) do
|
283
|
+
output.print_record(definition, data)
|
284
|
+
end
|
285
|
+
end
|
286
|
+
end
|
287
|
+
end
|
288
|
+
end
|
data/test/unit/utils_test.rb
CHANGED
@@ -9,41 +9,32 @@ module Constant
|
|
9
9
|
end
|
10
10
|
|
11
11
|
describe String do
|
12
|
+
context 'formatting' do
|
13
|
+
let(:str) { 'AA%<a>s BB%<b>s' }
|
14
|
+
let(:curly_str) { 'AA%{a} BB%{b}' }
|
15
|
+
let(:pos_str) { 'AA%s BB%s' }
|
16
|
+
let(:str_with_percent) { 'Error: AA%<a>s BB%<b>s <%# template error %> verify this %>' }
|
12
17
|
|
13
|
-
|
14
|
-
|
15
|
-
let(:str) { "AA%<a>s BB%<b>s" }
|
16
|
-
let(:curly_str) { "AA%{a} BB%{b}" }
|
17
|
-
let(:pos_str) { "AA%s BB%s" }
|
18
|
-
let(:str_with_percent) { "Error: AA%<a>s BB%<b>s <%# template error %> verify this %>" }
|
19
|
-
|
20
|
-
it "should not fail without expected parameters" do
|
18
|
+
it 'should not fail without expected parameters' do
|
21
19
|
str.format({}).must_equal 'AA BB'
|
22
20
|
end
|
23
|
-
|
24
|
-
it "should replace positional parameters" do
|
21
|
+
it 'should replace positional parameters' do
|
25
22
|
pos_str.format(['A', 'B']).must_equal 'AAA BBB'
|
26
23
|
end
|
27
|
-
|
28
|
-
it "should replace named parameters" do
|
24
|
+
it 'should replace named parameters' do
|
29
25
|
str.format(:a => 'A', :b => 'B').must_equal 'AAA BBB'
|
30
26
|
end
|
31
|
-
|
32
|
-
it "should replace named parameters with string keys" do
|
27
|
+
it 'should replace named parameters with string keys' do
|
33
28
|
str.format('a' => 'A', 'b' => 'B').must_equal 'AAA BBB'
|
34
29
|
end
|
35
|
-
|
36
|
-
it "should replace named parameters marked with curly brackets" do
|
30
|
+
it 'should replace named parameters marked with curly brackets' do
|
37
31
|
curly_str.format(:a => 'A', :b => 'B').must_equal 'AAA BBB'
|
38
32
|
end
|
39
|
-
|
40
|
-
it "should not fail due to presence of percent chars in string" do
|
33
|
+
it 'should not fail due to presence of percent chars in string' do
|
41
34
|
str_with_percent.format({}).must_equal 'Error: AA BB <%# template error %> verify this %>'
|
42
35
|
end
|
43
|
-
|
44
36
|
end
|
45
37
|
|
46
|
-
|
47
38
|
context "camelize" do
|
48
39
|
|
49
40
|
it "should camelize string with underscores" do
|
@@ -110,7 +101,16 @@ describe String do
|
|
110
101
|
|
111
102
|
end
|
112
103
|
|
113
|
-
|
104
|
+
describe Hash do
|
105
|
+
context 'transform_keys' do
|
106
|
+
let(:hash) { { :one => 'one', :two => 'two', 'three' => 3 } }
|
107
|
+
let(:transformed_hash) { { :ONE => 'one', :TWO => 'two', 'THREE' => 3 } }
|
108
|
+
it 'should return a new hash with new keys' do
|
109
|
+
new_hash = hash.transform_keys(&:upcase)
|
110
|
+
new_hash.must_equal transformed_hash
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
114
|
|
115
115
|
describe HammerCLI do
|
116
116
|
|
@@ -170,4 +170,3 @@ describe HammerCLI do
|
|
170
170
|
end
|
171
171
|
|
172
172
|
end
|
173
|
-
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hammer_cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.15.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Bačovský
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-
|
12
|
+
date: 2018-10-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: clamp
|
@@ -17,7 +17,7 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - ">="
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: '1.
|
20
|
+
version: '1.1'
|
21
21
|
- - "<"
|
22
22
|
- !ruby/object:Gem::Version
|
23
23
|
version: 1.2.0
|
@@ -27,7 +27,7 @@ dependencies:
|
|
27
27
|
requirements:
|
28
28
|
- - ">="
|
29
29
|
- !ruby/object:Gem::Version
|
30
|
-
version: '1.
|
30
|
+
version: '1.1'
|
31
31
|
- - "<"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 1.2.0
|
@@ -260,6 +260,7 @@ files:
|
|
260
260
|
- lib/hammer_cli/testing/output_matchers.rb
|
261
261
|
- lib/hammer_cli/utils.rb
|
262
262
|
- lib/hammer_cli/validator.rb
|
263
|
+
- lib/hammer_cli/verbosity.rb
|
263
264
|
- lib/hammer_cli/version.rb
|
264
265
|
- locale/ca/LC_MESSAGES/hammer-cli.mo
|
265
266
|
- locale/de/LC_MESSAGES/hammer-cli.mo
|
@@ -422,6 +423,7 @@ files:
|
|
422
423
|
- test/unit/apipie/command_test.rb
|
423
424
|
- test/unit/apipie/option_builder_test.rb
|
424
425
|
- test/unit/apipie/option_definition_test.rb
|
426
|
+
- test/unit/apipie/test_helper.rb
|
425
427
|
- test/unit/ca_cert_manager_test.rb
|
426
428
|
- test/unit/completer_test.rb
|
427
429
|
- test/unit/connection_test.rb
|
@@ -468,9 +470,9 @@ files:
|
|
468
470
|
- test/unit/test_helper.rb
|
469
471
|
- test/unit/utils_test.rb
|
470
472
|
- test/unit/validator_test.rb
|
471
|
-
homepage:
|
473
|
+
homepage: https://github.com/theforeman/hammer-cli
|
472
474
|
licenses:
|
473
|
-
- GPL-3
|
475
|
+
- GPL-3.0
|
474
476
|
metadata: {}
|
475
477
|
post_install_message:
|
476
478
|
rdoc_options: []
|
@@ -661,6 +663,7 @@ test_files:
|
|
661
663
|
- test/unit/apipie/option_definition_test.rb
|
662
664
|
- test/unit/apipie/command_test.rb
|
663
665
|
- test/unit/apipie/option_builder_test.rb
|
666
|
+
- test/unit/apipie/test_helper.rb
|
664
667
|
- test/unit/validator_test.rb
|
665
668
|
- test/unit/options/option_collector_test.rb
|
666
669
|
- test/unit/options/sources/saved_defaults_test.rb
|