hammer_cli 0.19.0 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/hammer-complete +28 -0
- data/config/cli_config.template.yml +2 -0
- data/config/hammer.completion +5 -0
- data/doc/commands_extension.md +12 -0
- data/doc/creating_commands.md +100 -0
- data/doc/installation.md +47 -4
- data/doc/release_notes.md +32 -5
- data/lib/hammer_cli.rb +1 -0
- data/lib/hammer_cli/abstract.rb +61 -4
- data/lib/hammer_cli/apipie/api_connection.rb +5 -1
- data/lib/hammer_cli/apipie/command.rb +3 -2
- data/lib/hammer_cli/apipie/option_builder.rb +15 -13
- data/lib/hammer_cli/apipie/option_definition.rb +9 -7
- data/lib/hammer_cli/bash.rb +2 -0
- data/lib/hammer_cli/bash/completion.rb +159 -0
- data/lib/hammer_cli/bash/prebuild_command.rb +21 -0
- data/lib/hammer_cli/command_extensions.rb +21 -1
- data/lib/hammer_cli/connection.rb +4 -0
- data/lib/hammer_cli/exception_handler.rb +11 -2
- data/lib/hammer_cli/full_help.rb +8 -1
- data/lib/hammer_cli/help/builder.rb +29 -3
- data/lib/hammer_cli/logger_watch.rb +1 -1
- data/lib/hammer_cli/main.rb +5 -3
- data/lib/hammer_cli/options/normalizers.rb +7 -3
- data/lib/hammer_cli/options/option_definition.rb +26 -6
- data/lib/hammer_cli/options/option_family.rb +114 -0
- data/lib/hammer_cli/options/predefined.rb +1 -1
- data/lib/hammer_cli/output.rb +1 -1
- data/lib/hammer_cli/output/adapter/abstract.rb +1 -5
- data/lib/hammer_cli/output/adapter/base.rb +1 -1
- data/lib/hammer_cli/output/adapter/csv.rb +3 -2
- data/lib/hammer_cli/output/adapter/json.rb +14 -3
- data/lib/hammer_cli/output/adapter/silent.rb +1 -1
- data/lib/hammer_cli/output/adapter/table.rb +30 -80
- data/lib/hammer_cli/output/adapter/yaml.rb +6 -3
- data/lib/hammer_cli/output/definition.rb +11 -56
- data/lib/hammer_cli/output/generators.rb +1 -0
- data/lib/hammer_cli/output/generators/table.rb +121 -0
- data/lib/hammer_cli/output/output.rb +2 -4
- data/lib/hammer_cli/settings.rb +2 -1
- data/lib/hammer_cli/subcommand.rb +25 -1
- data/lib/hammer_cli/testing/command_assertions.rb +2 -2
- data/lib/hammer_cli/utils.rb +22 -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/man/hammer.1.gz +0 -0
- data/test/unit/abstract_test.rb +23 -2
- data/test/unit/apipie/api_connection_test.rb +1 -0
- data/test/unit/apipie/option_builder_test.rb +8 -0
- data/test/unit/bash_test.rb +138 -0
- data/test/unit/command_extensions_test.rb +67 -49
- data/test/unit/exception_handler_test.rb +44 -0
- data/test/unit/help/builder_test.rb +22 -0
- data/test/unit/options/option_family_test.rb +48 -0
- data/test/unit/output/adapter/base_test.rb +58 -0
- data/test/unit/output/adapter/csv_test.rb +63 -1
- data/test/unit/output/adapter/json_test.rb +61 -0
- data/test/unit/output/adapter/table_test.rb +70 -1
- data/test/unit/output/adapter/yaml_test.rb +59 -0
- data/test/unit/output/definition_test.rb +7 -7
- data/test/unit/output/output_test.rb +3 -3
- metadata +83 -345
- data/hammer_cli_complete +0 -13
- data/test/reports/TEST-Fields-ContainerField-display-.xml +0 -7
- data/test/reports/TEST-Fields-ContainerField-display-blank-is-allowed.xml +0 -15
- data/test/reports/TEST-Fields-ContainerField-display-blank-is-not-allowed.xml +0 -15
- data/test/reports/TEST-Fields-ContainerField.xml +0 -7
- data/test/reports/TEST-Fields-Field-display-.xml +0 -7
- data/test/reports/TEST-Fields-Field-display-blank-is-allowed.xml +0 -11
- data/test/reports/TEST-Fields-Field-display-blank-is-not-allowed.xml +0 -11
- data/test/reports/TEST-Fields-Field-hide-blank-.xml +0 -11
- data/test/reports/TEST-Fields-Field-parameters.xml +0 -9
- data/test/reports/TEST-Fields-Field.xml +0 -13
- data/test/reports/TEST-HammerCLI-AbstractCommand-build-options.xml +0 -15
- data/test/reports/TEST-HammerCLI-AbstractCommand-exception-handler.xml +0 -13
- data/test/reports/TEST-HammerCLI-AbstractCommand-logging.xml +0 -21
- data/test/reports/TEST-HammerCLI-AbstractCommand-option-builder.xml +0 -11
- data/test/reports/TEST-HammerCLI-AbstractCommand-options.xml +0 -11
- data/test/reports/TEST-HammerCLI-AbstractCommand-output.xml +0 -19
- data/test/reports/TEST-HammerCLI-AbstractCommand-subcommand-behavior-remove-subcommand.xml +0 -11
- data/test/reports/TEST-HammerCLI-AbstractCommand-subcommand-behavior-subcommand-.xml +0 -13
- data/test/reports/TEST-HammerCLI-AbstractCommand-subcommand-behavior-subcommand.xml +0 -11
- data/test/reports/TEST-HammerCLI-AbstractCommand-subcommand-behavior.xml +0 -7
- data/test/reports/TEST-HammerCLI-AbstractCommand.xml +0 -11
- data/test/reports/TEST-HammerCLI-Apipie-Command-options.xml +0 -11
- data/test/reports/TEST-HammerCLI-Apipie-Command-resource-defined.xml +0 -9
- data/test/reports/TEST-HammerCLI-Apipie-Command-setting-resources.xml +0 -19
- data/test/reports/TEST-HammerCLI-Apipie-Command.xml +0 -9
- data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder-aliasing-resources.xml +0 -13
- data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder-filtering-options.xml +0 -15
- data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder-required-options.xml +0 -11
- data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder-setting-correct-normalizers.xml +0 -9
- data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder-with-hash-params.xml +0 -11
- data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder-with-one-simple-param.xml +0 -15
- data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder.xml +0 -7
- data/test/reports/TEST-HammerCLI-Completer-command-completion.xml +0 -29
- data/test/reports/TEST-HammerCLI-Completer-option-value-completion.xml +0 -17
- data/test/reports/TEST-HammerCLI-Completer-subcommand-completion.xml +0 -19
- data/test/reports/TEST-HammerCLI-Completer.xml +0 -7
- data/test/reports/TEST-HammerCLI-CompleterLine-line-complete.xml +0 -25
- data/test/reports/TEST-HammerCLI-CompleterLine-splitting-words.xml +0 -29
- data/test/reports/TEST-HammerCLI-CompleterLine.xml +0 -7
- data/test/reports/TEST-HammerCLI-CompleterWord-complete-.xml +0 -23
- data/test/reports/TEST-HammerCLI-CompleterWord-quote.xml +0 -15
- data/test/reports/TEST-HammerCLI-CompleterWord-quoted-.xml +0 -13
- data/test/reports/TEST-HammerCLI-CompleterWord.xml +0 -7
- data/test/reports/TEST-HammerCLI-Connection.xml +0 -21
- data/test/reports/TEST-HammerCLI-ExceptionHandler.xml +0 -21
- data/test/reports/TEST-HammerCLI-I18n.xml +0 -11
- data/test/reports/TEST-HammerCLI-MainCommand-loading-context-password.xml +0 -11
- data/test/reports/TEST-HammerCLI-MainCommand-loading-context-username.xml +0 -11
- data/test/reports/TEST-HammerCLI-MainCommand-loading-context-verbose.xml +0 -9
- data/test/reports/TEST-HammerCLI-MainCommand-loading-context.xml +0 -7
- data/test/reports/TEST-HammerCLI-MainCommand.xml +0 -7
- data/test/reports/TEST-HammerCLI-Modules-find-by-name.xml +0 -13
- data/test/reports/TEST-HammerCLI-Modules-load-a-module-module-not-found.xml +0 -13
- data/test/reports/TEST-HammerCLI-Modules-load-a-module-module-runtime-exception.xml +0 -13
- data/test/reports/TEST-HammerCLI-Modules-load-a-module-success.xml +0 -15
- data/test/reports/TEST-HammerCLI-Modules-load-a-module.xml +0 -7
- data/test/reports/TEST-HammerCLI-Modules-load-all-modules.xml +0 -9
- data/test/reports/TEST-HammerCLI-Modules-names.xml +0 -13
- data/test/reports/TEST-HammerCLI-Modules.xml +0 -7
- data/test/reports/TEST-HammerCLI-OptionBuilderContainer.0.xml +0 -7
- data/test/reports/TEST-HammerCLI-OptionBuilderContainer.xml +0 -11
- data/test/reports/TEST-HammerCLI-Options-Normalizers-abstract.xml +0 -9
- data/test/reports/TEST-HammerCLI-Options-Normalizers-bool.xml +0 -31
- data/test/reports/TEST-HammerCLI-Options-Normalizers-datetime.xml +0 -17
- data/test/reports/TEST-HammerCLI-Options-Normalizers-enum.xml +0 -15
- data/test/reports/TEST-HammerCLI-Options-Normalizers-enumlist.xml +0 -21
- data/test/reports/TEST-HammerCLI-Options-Normalizers-json-input.xml +0 -15
- data/test/reports/TEST-HammerCLI-Options-Normalizers-key-value-list.xml +0 -17
- data/test/reports/TEST-HammerCLI-Options-Normalizers-list.xml +0 -15
- data/test/reports/TEST-HammerCLI-Options-Normalizers.xml +0 -7
- data/test/reports/TEST-HammerCLI-Options-OptionDefinition-context.xml +0 -9
- data/test/reports/TEST-HammerCLI-Options-OptionDefinition-formatters.xml +0 -11
- data/test/reports/TEST-HammerCLI-Options-OptionDefinition.xml +0 -7
- data/test/reports/TEST-HammerCLI-Output-Adapter-Abstract-error-messages.xml +0 -15
- data/test/reports/TEST-HammerCLI-Output-Adapter-Abstract-messages.xml +0 -11
- data/test/reports/TEST-HammerCLI-Output-Adapter-Abstract-test-data-for-field.xml +0 -15
- data/test/reports/TEST-HammerCLI-Output-Adapter-Abstract.xml +0 -17
- data/test/reports/TEST-HammerCLI-Output-Adapter-Base-print-collection-show-ids.xml +0 -9
- data/test/reports/TEST-HammerCLI-Output-Adapter-Base-print-collection.xml +0 -27
- data/test/reports/TEST-HammerCLI-Output-Adapter-Base.xml +0 -7
- data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues-print-collection-formatters.xml +0 -11
- data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues-print-collection-handle-fields-with-collections.xml +0 -13
- data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues-print-collection-handle-fields-with-containers.xml +0 -11
- data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues-print-collection-handle-ids.xml +0 -11
- data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues-print-collection.xml +0 -11
- data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues-print-message.xml +0 -11
- data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues.xml +0 -7
- data/test/reports/TEST-HammerCLI-Output-Adapter-Table-print-collection-column-width.xml +0 -15
- data/test/reports/TEST-HammerCLI-Output-Adapter-Table-print-collection-formatters.xml +0 -11
- data/test/reports/TEST-HammerCLI-Output-Adapter-Table-print-collection-handle-ids.xml +0 -11
- data/test/reports/TEST-HammerCLI-Output-Adapter-Table-print-collection-sort-columns.xml +0 -9
- data/test/reports/TEST-HammerCLI-Output-Adapter-Table-print-collection.xml +0 -11
- data/test/reports/TEST-HammerCLI-Output-Adapter-Table.xml +0 -7
- data/test/reports/TEST-HammerCLI-Output-Definition-empty-.xml +0 -11
- data/test/reports/TEST-HammerCLI-Output-Definition.xml +0 -11
- data/test/reports/TEST-HammerCLI-Output-Dsl-collection.xml +0 -13
- data/test/reports/TEST-HammerCLI-Output-Dsl-custom-fields.xml +0 -11
- data/test/reports/TEST-HammerCLI-Output-Dsl-fields.xml +0 -15
- data/test/reports/TEST-HammerCLI-Output-Dsl-label.xml +0 -13
- data/test/reports/TEST-HammerCLI-Output-Dsl-path-definition.xml +0 -13
- data/test/reports/TEST-HammerCLI-Output-Dsl.xml +0 -9
- data/test/reports/TEST-HammerCLI-Output-FieldFilter.xml +0 -13
- data/test/reports/TEST-HammerCLI-Output-Formatters-BooleanFormatter.xml +0 -11
- data/test/reports/TEST-HammerCLI-Output-Formatters-ColorFormatter.xml +0 -9
- data/test/reports/TEST-HammerCLI-Output-Formatters-DateFormatter.xml +0 -11
- data/test/reports/TEST-HammerCLI-Output-Formatters-FieldFormatter.xml +0 -13
- data/test/reports/TEST-HammerCLI-Output-Formatters-FormatterContainer.xml +0 -13
- data/test/reports/TEST-HammerCLI-Output-Formatters-FormatterLibrary.xml +0 -11
- data/test/reports/TEST-HammerCLI-Output-Formatters-KeyValueFormatter.xml +0 -13
- data/test/reports/TEST-HammerCLI-Output-Formatters-ListFormatter.xml +0 -13
- data/test/reports/TEST-HammerCLI-Output-Formatters-LongTextFormatter.xml +0 -13
- data/test/reports/TEST-HammerCLI-Output-Output-adapters.xml +0 -17
- data/test/reports/TEST-HammerCLI-Output-Output-data.xml +0 -15
- data/test/reports/TEST-HammerCLI-Output-Output-formatters.xml +0 -9
- data/test/reports/TEST-HammerCLI-Output-Output-messages.xml +0 -19
- data/test/reports/TEST-HammerCLI-Output-Output.xml +0 -7
- data/test/reports/TEST-HammerCLI-Output-RecordCollection.xml +0 -13
- data/test/reports/TEST-HammerCLI-Settings-load-from-paths.xml +0 -15
- data/test/reports/TEST-HammerCLI-Settings.xml +0 -25
- data/test/reports/TEST-HammerCLI-ShellHistory-loading-old-history.xml +0 -11
- data/test/reports/TEST-HammerCLI-ShellHistory-saving-history.xml +0 -15
- data/test/reports/TEST-HammerCLI-ShellHistory.xml +0 -7
- data/test/reports/TEST-MiniTest-Spec.xml +0 -7
- data/test/reports/TEST-String-camelize.xml +0 -11
- data/test/reports/TEST-String-formatting.xml +0 -17
- data/test/reports/TEST-String-indent.xml +0 -11
- data/test/reports/TEST-String-interactive-.xml +0 -13
- data/test/reports/TEST-String.xml +0 -7
- data/test/reports/TEST-constraints-HammerCLI-Validator-AllConstraint-exist-.xml +0 -13
- data/test/reports/TEST-constraints-HammerCLI-Validator-AllConstraint.xml +0 -7
- data/test/reports/TEST-constraints-HammerCLI-Validator-AnyConstraint-exist-.xml +0 -13
- data/test/reports/TEST-constraints-HammerCLI-Validator-AnyConstraint.xml +0 -7
- data/test/reports/TEST-constraints-HammerCLI-Validator-BaseConstraint-exist-.xml +0 -9
- data/test/reports/TEST-constraints-HammerCLI-Validator-BaseConstraint-rejected.xml +0 -13
- data/test/reports/TEST-constraints-HammerCLI-Validator-BaseConstraint-required.xml +0 -13
- data/test/reports/TEST-constraints-HammerCLI-Validator-BaseConstraint.xml +0 -7
- data/test/reports/TEST-constraints.xml +0 -7
@@ -0,0 +1,138 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
+
|
3
|
+
describe HammerCLI::Bash::Completion do
|
4
|
+
describe '#complete' do
|
5
|
+
let(:dict) do
|
6
|
+
{
|
7
|
+
'host' => {
|
8
|
+
'create' => {
|
9
|
+
'--installed-products-attributes' => { type: :schema, schema: '"product_id=string\,product_name=string\,arch=string\,version=string, ... "' },
|
10
|
+
'--help' => { type: :flag },
|
11
|
+
'--build' => { type: :flag },
|
12
|
+
'--managed' => { type: :enum, values: %w[yes no] },
|
13
|
+
'--volume' => { type: :multienum, values: %w[first second third] },
|
14
|
+
'--config-group-ids' => { type: :list },
|
15
|
+
'--params' => { type: :key_value_list },
|
16
|
+
'--log' => { type: :file, filter: '.*\.log$' },
|
17
|
+
'--pool' => { type: :directory },
|
18
|
+
'-t' => { type: :value },
|
19
|
+
:params => [{ type: :directory }, { type: :value }, { type: :file }]
|
20
|
+
},
|
21
|
+
'--dry' => { type: :flag },
|
22
|
+
'--help' => { type: :flag },
|
23
|
+
},
|
24
|
+
'--interactive' => { type: :enum, values: %w[yes no] },
|
25
|
+
'--help' => { type: :flag },
|
26
|
+
'-h' => { type: :flag }
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
subject do
|
31
|
+
HammerCLI::Bash::Completion.new(JSON.load(dict.to_json))
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'returns options when no input given' do
|
35
|
+
result = subject.complete('').sort
|
36
|
+
result.must_equal ['host ', '--interactive ', '--help ', '-h '].sort
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'returns filtered options when partial input is given' do
|
40
|
+
result = subject.complete('-').sort
|
41
|
+
result.must_equal ['--help ', '-h ', '--interactive '].sort
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'returns filtered options when partial input is given' do
|
45
|
+
result = subject.complete('host')
|
46
|
+
result.must_equal ['host ']
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'returns options when subcommand is given' do
|
50
|
+
result = subject.complete('host ').sort
|
51
|
+
result.must_equal ['create ', '--help ', '--dry '].sort
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'returns no options when subcommand is wrong' do
|
55
|
+
result = subject.complete('unknown -h')
|
56
|
+
result.must_equal []
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'returns no options when there are no other params allowed' do
|
60
|
+
result = subject.complete('host create /tmp some /tmp extra')
|
61
|
+
result.must_equal []
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'return hint for option-value pair without value' do
|
65
|
+
result = subject.complete('host create -t ')
|
66
|
+
result.must_equal ['--->', 'Add option <value>']
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'return no options for option-value pair without complete value' do
|
70
|
+
result = subject.complete('host create -t x')
|
71
|
+
result.must_equal []
|
72
|
+
end
|
73
|
+
|
74
|
+
# multiple options in one subcommand
|
75
|
+
it 'allows mutiple options of the same subcommand' do
|
76
|
+
result = subject.complete('host create --build --he')
|
77
|
+
result.must_equal ['--help ']
|
78
|
+
end
|
79
|
+
|
80
|
+
# multiple options with values in one subcommand
|
81
|
+
it 'allows mutiple options with values of the same subcommand' do
|
82
|
+
result = subject.complete('host create -t value --he')
|
83
|
+
result.must_equal ['--help ']
|
84
|
+
end
|
85
|
+
|
86
|
+
# subcommand after options
|
87
|
+
it 'allows subcommand after options' do
|
88
|
+
result = subject.complete('host --dry crea')
|
89
|
+
result.must_equal ['create ']
|
90
|
+
end
|
91
|
+
|
92
|
+
describe 'completion by type' do
|
93
|
+
it 'completes :value' do
|
94
|
+
result = subject.complete('host create -t ')
|
95
|
+
result.must_equal ['--->', 'Add option <value>']
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'completes :flag' do
|
99
|
+
result = subject.complete('host --h')
|
100
|
+
result.must_equal ['--help ']
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'completes :schema' do
|
104
|
+
result = subject.complete('host create --installed-products-attributes ')
|
105
|
+
result.must_equal ["--->", 'Add value by following schema: "product_id=string\,product_name=string\,arch=string\,version=string, ... "']
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'completes :enum' do
|
109
|
+
result = subject.complete('host create --managed ')
|
110
|
+
result.must_equal ['yes ', 'no ']
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'completes :multienum' do
|
114
|
+
result = subject.complete('host create --volume ')
|
115
|
+
result.must_equal ['first', 'second', 'third']
|
116
|
+
|
117
|
+
result = subject.complete('host create --volume fir')
|
118
|
+
result.must_equal ['first']
|
119
|
+
|
120
|
+
result = subject.complete('host create --volume first,')
|
121
|
+
result.must_equal ['second', 'third']
|
122
|
+
|
123
|
+
result = subject.complete('host create --volume first,se')
|
124
|
+
result.must_equal ['first,second']
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'completes :list' do
|
128
|
+
result = subject.complete('host create --config-group-ids ')
|
129
|
+
result.must_equal ['--->', 'Add comma-separated list of values']
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'completes :key_value_list' do
|
133
|
+
result = subject.complete('host create --params ')
|
134
|
+
result.must_equal ['--->', 'Add comma-separated list of key=value']
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
@@ -23,6 +23,12 @@ describe HammerCLI::CommandExtensions do
|
|
23
23
|
|
24
24
|
class CmdExtensions < HammerCLI::CommandExtensions
|
25
25
|
option '--ext', 'EXT', 'ext'
|
26
|
+
option_family(
|
27
|
+
description: 'Test',
|
28
|
+
) do
|
29
|
+
parent '--test-one', '', ''
|
30
|
+
child '--test-two', '', ''
|
31
|
+
end
|
26
32
|
before_print do |data|
|
27
33
|
data['key'] = 'value'
|
28
34
|
end
|
@@ -64,49 +70,55 @@ describe HammerCLI::CommandExtensions do
|
|
64
70
|
|
65
71
|
it 'should extend help only' do
|
66
72
|
cmd.extend_with(CmdExtensions.new(only: :help))
|
67
|
-
cmd.new({}).help.must_match(/.*Section.*/)
|
68
|
-
cmd.new({}).help.must_match(/.*text.*/)
|
73
|
+
cmd.new('', {}).help.must_match(/.*Section.*/)
|
74
|
+
cmd.new('', {}).help.must_match(/.*text.*/)
|
69
75
|
end
|
70
76
|
|
71
77
|
it 'should extend params only' do
|
72
78
|
cmd.extend_with(CmdExtensions.new(only: :request_params))
|
73
|
-
cmd.new({}).extended_request[0].must_equal(thin: true)
|
74
|
-
cmd.new({}).extended_request[1].must_equal({})
|
75
|
-
cmd.new({}).extended_request[2].must_equal({})
|
79
|
+
cmd.new('', {}).extended_request[0].must_equal(thin: true)
|
80
|
+
cmd.new('', {}).extended_request[1].must_equal({})
|
81
|
+
cmd.new('', {}).extended_request[2].must_equal({})
|
76
82
|
end
|
77
83
|
|
78
84
|
it 'should extend headers only' do
|
79
85
|
cmd.extend_with(CmdExtensions.new(only: :request_headers))
|
80
|
-
cmd.new({}).extended_request[0].must_equal({})
|
81
|
-
cmd.new({}).extended_request[1].must_equal(ssl: true)
|
82
|
-
cmd.new({}).extended_request[2].must_equal({})
|
86
|
+
cmd.new('', {}).extended_request[0].must_equal({})
|
87
|
+
cmd.new('', {}).extended_request[1].must_equal(ssl: true)
|
88
|
+
cmd.new('', {}).extended_request[2].must_equal({})
|
83
89
|
end
|
84
90
|
|
85
91
|
it 'should extend options only' do
|
86
92
|
cmd.extend_with(CmdExtensions.new(only: :request_options))
|
87
|
-
cmd.new({}).extended_request[0].must_equal({})
|
88
|
-
cmd.new({}).extended_request[1].must_equal({})
|
89
|
-
cmd.new({}).extended_request[2].must_equal(with_authentication: true)
|
93
|
+
cmd.new('', {}).extended_request[0].must_equal({})
|
94
|
+
cmd.new('', {}).extended_request[1].must_equal({})
|
95
|
+
cmd.new('', {}).extended_request[2].must_equal(with_authentication: true)
|
90
96
|
end
|
91
97
|
|
92
98
|
it 'should extend params and options and headers' do
|
93
99
|
cmd.extend_with(CmdExtensions.new(only: :request))
|
94
|
-
cmd.new({}).extended_request[0].must_equal(thin: true)
|
95
|
-
cmd.new({}).extended_request[1].must_equal(ssl: true)
|
96
|
-
cmd.new({}).extended_request[2].must_equal(with_authentication: true)
|
100
|
+
cmd.new('', {}).extended_request[0].must_equal(thin: true)
|
101
|
+
cmd.new('', {}).extended_request[1].must_equal(ssl: true)
|
102
|
+
cmd.new('', {}).extended_request[2].must_equal(with_authentication: true)
|
97
103
|
end
|
98
104
|
|
99
105
|
it 'should extend data only' do
|
100
106
|
cmd.extend_with(CmdExtensions.new(only: :data))
|
101
|
-
cmd.new({}).help.wont_match(/.*Section.*/)
|
102
|
-
cmd.new({}).help.wont_match(/.*text.*/)
|
107
|
+
cmd.new('', {}).help.wont_match(/.*Section.*/)
|
108
|
+
cmd.new('', {}).help.wont_match(/.*text.*/)
|
103
109
|
cmd.output_definition.empty?.must_equal true
|
104
110
|
opt = cmd.find_option('--ext')
|
105
111
|
opt.is_a?(HammerCLI::Options::OptionDefinition).must_equal false
|
106
|
-
cmd.new({}).extended_request[0].must_equal({})
|
107
|
-
cmd.new({}).extended_request[1].must_equal({})
|
108
|
-
cmd.new({}).extended_request[2].must_equal({})
|
109
|
-
cmd.new({}).extended_data({}).must_equal('key' => 'value')
|
112
|
+
cmd.new('', {}).extended_request[0].must_equal({})
|
113
|
+
cmd.new('', {}).extended_request[1].must_equal({})
|
114
|
+
cmd.new('', {}).extended_request[2].must_equal({})
|
115
|
+
cmd.new('', {}).extended_data({}).must_equal('key' => 'value')
|
116
|
+
end
|
117
|
+
|
118
|
+
it 'should extend option family only' do
|
119
|
+
cmd.extend_with(CmdExtensions.new(only: :option_family))
|
120
|
+
cmd.output_definition.empty?.must_equal true
|
121
|
+
cmd.recognised_options.map(&:switches).flatten.must_equal ['--test-one', '--test-two', '-h', '--help']
|
110
122
|
end
|
111
123
|
end
|
112
124
|
|
@@ -116,9 +128,9 @@ describe HammerCLI::CommandExtensions do
|
|
116
128
|
opt = cmd.find_option('--ext')
|
117
129
|
opt.is_a?(HammerCLI::Options::OptionDefinition).must_equal false
|
118
130
|
cmd.output_definition.empty?.must_equal false
|
119
|
-
cmd.new({}).extended_request[0].must_equal(thin: true)
|
120
|
-
cmd.new({}).extended_request[1].must_equal(ssl: true)
|
121
|
-
cmd.new({}).extended_request[2].must_equal(with_authentication: true)
|
131
|
+
cmd.new('', {}).extended_request[0].must_equal(thin: true)
|
132
|
+
cmd.new('', {}).extended_request[1].must_equal(ssl: true)
|
133
|
+
cmd.new('', {}).extended_request[2].must_equal(with_authentication: true)
|
122
134
|
end
|
123
135
|
|
124
136
|
it 'should extend all except output' do
|
@@ -126,62 +138,68 @@ describe HammerCLI::CommandExtensions do
|
|
126
138
|
cmd.output_definition.empty?.must_equal true
|
127
139
|
opt = cmd.find_option('--ext')
|
128
140
|
opt.is_a?(HammerCLI::Options::OptionDefinition).must_equal true
|
129
|
-
cmd.new({}).extended_request[0].must_equal(thin: true)
|
130
|
-
cmd.new({}).extended_request[1].must_equal(ssl: true)
|
131
|
-
cmd.new({}).extended_request[2].must_equal(with_authentication: true)
|
141
|
+
cmd.new('', {}).extended_request[0].must_equal(thin: true)
|
142
|
+
cmd.new('', {}).extended_request[1].must_equal(ssl: true)
|
143
|
+
cmd.new('', {}).extended_request[2].must_equal(with_authentication: true)
|
132
144
|
end
|
133
145
|
|
134
146
|
it 'should extend all except help' do
|
135
147
|
cmd.extend_with(CmdExtensions.new(except: :help))
|
136
|
-
cmd.new({}).help.wont_match(/.*Section.*/)
|
137
|
-
cmd.new({}).help.wont_match(/.*text.*/)
|
148
|
+
cmd.new('', {}).help.wont_match(/.*Section.*/)
|
149
|
+
cmd.new('', {}).help.wont_match(/.*text.*/)
|
138
150
|
cmd.output_definition.empty?.must_equal false
|
139
151
|
opt = cmd.find_option('--ext')
|
140
152
|
opt.is_a?(HammerCLI::Options::OptionDefinition).must_equal true
|
141
|
-
cmd.new({}).extended_request[0].must_equal(thin: true)
|
142
|
-
cmd.new({}).extended_request[1].must_equal(ssl: true)
|
143
|
-
cmd.new({}).extended_request[2].must_equal(with_authentication: true)
|
153
|
+
cmd.new('', {}).extended_request[0].must_equal(thin: true)
|
154
|
+
cmd.new('', {}).extended_request[1].must_equal(ssl: true)
|
155
|
+
cmd.new('', {}).extended_request[2].must_equal(with_authentication: true)
|
144
156
|
end
|
145
157
|
|
146
158
|
it 'should extend all except params' do
|
147
159
|
cmd.extend_with(CmdExtensions.new(except: :request_params))
|
148
|
-
cmd.new({}).extended_request[0].must_equal({})
|
149
|
-
cmd.new({}).extended_request[1].must_equal(ssl: true)
|
150
|
-
cmd.new({}).extended_request[2].must_equal(with_authentication: true)
|
160
|
+
cmd.new('', {}).extended_request[0].must_equal({})
|
161
|
+
cmd.new('', {}).extended_request[1].must_equal(ssl: true)
|
162
|
+
cmd.new('', {}).extended_request[2].must_equal(with_authentication: true)
|
151
163
|
end
|
152
164
|
|
153
165
|
it 'should extend all except headers' do
|
154
166
|
cmd.extend_with(CmdExtensions.new(except: :request_headers))
|
155
|
-
cmd.new({}).extended_request[0].must_equal(thin: true)
|
156
|
-
cmd.new({}).extended_request[1].must_equal({})
|
157
|
-
cmd.new({}).extended_request[2].must_equal(with_authentication: true)
|
167
|
+
cmd.new('', {}).extended_request[0].must_equal(thin: true)
|
168
|
+
cmd.new('', {}).extended_request[1].must_equal({})
|
169
|
+
cmd.new('', {}).extended_request[2].must_equal(with_authentication: true)
|
158
170
|
end
|
159
171
|
|
160
172
|
it 'should extend all except options' do
|
161
173
|
cmd.extend_with(CmdExtensions.new(except: :request_options))
|
162
|
-
cmd.new({}).extended_request[0].must_equal(thin: true)
|
163
|
-
cmd.new({}).extended_request[1].must_equal(ssl: true)
|
164
|
-
cmd.new({}).extended_request[2].must_equal({})
|
174
|
+
cmd.new('', {}).extended_request[0].must_equal(thin: true)
|
175
|
+
cmd.new('', {}).extended_request[1].must_equal(ssl: true)
|
176
|
+
cmd.new('', {}).extended_request[2].must_equal({})
|
165
177
|
end
|
166
178
|
|
167
179
|
it 'should extend all except params and options and headers' do
|
168
180
|
cmd.extend_with(CmdExtensions.new(except: :request))
|
169
|
-
cmd.new({}).extended_request[0].must_equal({})
|
170
|
-
cmd.new({}).extended_request[1].must_equal({})
|
171
|
-
cmd.new({}).extended_request[2].must_equal({})
|
181
|
+
cmd.new('', {}).extended_request[0].must_equal({})
|
182
|
+
cmd.new('', {}).extended_request[1].must_equal({})
|
183
|
+
cmd.new('', {}).extended_request[2].must_equal({})
|
172
184
|
end
|
173
185
|
|
174
186
|
it 'should extend all except data' do
|
175
187
|
cmd.extend_with(CmdExtensions.new(except: :data))
|
176
|
-
cmd.new({}).help.must_match(/.*Section.*/)
|
177
|
-
cmd.new({}).help.must_match(/.*text.*/)
|
188
|
+
cmd.new('', {}).help.must_match(/.*Section.*/)
|
189
|
+
cmd.new('', {}).help.must_match(/.*text.*/)
|
178
190
|
cmd.output_definition.empty?.must_equal false
|
179
191
|
opt = cmd.find_option('--ext')
|
180
192
|
opt.is_a?(HammerCLI::Options::OptionDefinition).must_equal true
|
181
|
-
cmd.new({}).extended_request[0].must_equal(thin: true)
|
182
|
-
cmd.new({}).extended_request[1].must_equal(ssl: true)
|
183
|
-
cmd.new({}).extended_request[2].must_equal(with_authentication: true)
|
184
|
-
cmd.new({}).extended_data({}).must_equal({})
|
193
|
+
cmd.new('', {}).extended_request[0].must_equal(thin: true)
|
194
|
+
cmd.new('', {}).extended_request[1].must_equal(ssl: true)
|
195
|
+
cmd.new('', {}).extended_request[2].must_equal(with_authentication: true)
|
196
|
+
cmd.new('', {}).extended_data({}).must_equal({})
|
197
|
+
end
|
198
|
+
|
199
|
+
it 'should extend all except option family' do
|
200
|
+
cmd.extend_with(CmdExtensions.new(except: :option_family))
|
201
|
+
cmd.output_definition.empty?.must_equal false
|
202
|
+
cmd.recognised_options.map(&:switches).flatten.must_equal ['--ext', '-h', '--help']
|
185
203
|
end
|
186
204
|
end
|
187
205
|
|
@@ -55,4 +55,48 @@ describe HammerCLI::ExceptionHandler do
|
|
55
55
|
assert_match /ERROR Exception : (Resource )?Not Found/, @log_output.readline.strip
|
56
56
|
end
|
57
57
|
|
58
|
+
it "should print default prompts for standard missing arguments" do
|
59
|
+
params = %w[login mail]
|
60
|
+
heading = 'Could not create user:'
|
61
|
+
body = "Missing arguments for '--login', '--mail'."
|
62
|
+
ex = ApipieBindings::MissingArgumentsError.new(params)
|
63
|
+
output.expects(:print_error).with(heading, body)
|
64
|
+
handler.handle_exception(ex, heading: heading)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should print right prompts for nested missing arguments" do
|
68
|
+
params = %w[user[login] user[mail]]
|
69
|
+
heading = 'Could not create user:'
|
70
|
+
body = "Missing arguments for '--login', '--mail'."
|
71
|
+
ex = ApipieBindings::MissingArgumentsError.new(params)
|
72
|
+
output.expects(:print_error).with(heading, body)
|
73
|
+
handler.handle_exception(ex, heading: heading)
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should print simple prompts for even more nested arguments" do
|
77
|
+
params = %w[user[address][city] user[address][street]]
|
78
|
+
heading = 'Could not create user:'
|
79
|
+
body = "Missing arguments for '--address'."
|
80
|
+
ex = ApipieBindings::MissingArgumentsError.new(params)
|
81
|
+
output.expects(:print_error).with(heading, body)
|
82
|
+
handler.handle_exception(ex, heading: heading)
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should print simple prompts for even more different nested arguments" do
|
86
|
+
params = %w[user[address][city] user[address][street] user[nested][par1]]
|
87
|
+
heading = 'Could not create user:'
|
88
|
+
body = "Missing arguments for '--address', '--nested'."
|
89
|
+
ex = ApipieBindings::MissingArgumentsError.new(params)
|
90
|
+
output.expects(:print_error).with(heading, body)
|
91
|
+
handler.handle_exception(ex, heading: heading)
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should print default prompts for standard missing arguments" do
|
95
|
+
params = %w[opt_abc opt_a_b-c]
|
96
|
+
heading = 'Could not create user:'
|
97
|
+
body = "Missing arguments for '--opt-abc', '--opt-a-b-c'."
|
98
|
+
ex = ApipieBindings::MissingArgumentsError.new(params)
|
99
|
+
output.expects(:print_error).with(heading, body)
|
100
|
+
handler.handle_exception(ex, heading: heading)
|
101
|
+
end
|
58
102
|
end
|
@@ -69,4 +69,26 @@ describe HammerCLI::Help::Builder do
|
|
69
69
|
help.string.strip.must_equal expected_output
|
70
70
|
end
|
71
71
|
end
|
72
|
+
|
73
|
+
describe 'option family' do
|
74
|
+
let(:family) { Class.new(HammerCLI::Options::OptionFamily) }
|
75
|
+
|
76
|
+
it 'prints option families' do
|
77
|
+
fm1 = family.new
|
78
|
+
fm1.parent(['--option-zzz'], 'OPT', 'Some description')
|
79
|
+
fm1.child(['--option-aaa'], 'OPT', 'Some description')
|
80
|
+
fm2 = family.new
|
81
|
+
fm2.parent(['--option-bbb'], 'OPT', 'Some description')
|
82
|
+
fm2.child(['--option-yyy'], 'OPT', 'Some description')
|
83
|
+
|
84
|
+
options = fm1.all + fm2.all
|
85
|
+
help.add_list('Options', options)
|
86
|
+
|
87
|
+
help.string.strip.must_equal [
|
88
|
+
'Options:',
|
89
|
+
' --option[-yyy|-bbb] Some description',
|
90
|
+
' --option[-aaa|-zzz] Some description',
|
91
|
+
].join("\n")
|
92
|
+
end
|
93
|
+
end
|
72
94
|
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
|
3
|
+
describe HammerCLI::Options::OptionFamily do
|
4
|
+
let(:family) do
|
5
|
+
HammerCLI::Options::OptionFamily.new(
|
6
|
+
deprecated: { '--test-one' => 'Use --test-two instead' }
|
7
|
+
)
|
8
|
+
end
|
9
|
+
let(:first_option) { HammerCLI::Apipie::OptionDefinition.new("--test-one", '', '') }
|
10
|
+
let(:second_option) { HammerCLI::Apipie::OptionDefinition.new("--test-two", '', '') }
|
11
|
+
let(:third_option) { HammerCLI::Apipie::OptionDefinition.new("--test-three", '', '') }
|
12
|
+
let(:full_family) do
|
13
|
+
family.parent('--test-one', '', 'Test').family.child('--test-two', '', '').family
|
14
|
+
end
|
15
|
+
|
16
|
+
describe 'switch' do
|
17
|
+
it 'returns nil if family is empty' do
|
18
|
+
family.switch.must_be_nil
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'returns parent switch if family has no children' do
|
22
|
+
family.parent('--test-one', '', '')
|
23
|
+
family.switch.must_equal '--test-one'
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'returns switch based on members' do
|
27
|
+
full_family.switch.must_equal '--test[-two|-one]'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe 'description' do
|
32
|
+
it 'returns parent description if nothing passed to initializer' do
|
33
|
+
full_family.description.must_equal full_family.head.help[1]
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'returns description with deprecation message' do
|
37
|
+
full_family.description.must_equal 'Test (--test-one is deprecated: Use --test-two instead)'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe 'adopt' do
|
42
|
+
it 'appends an option to children' do
|
43
|
+
full_family.adopt(third_option)
|
44
|
+
full_family.children.size.must_equal 2
|
45
|
+
third_option.family.must_equal full_family
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|