hammer_cli 0.19.0 → 2.1.1

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.
Files changed (213) hide show
  1. checksums.yaml +4 -4
  2. data/bin/hammer-complete +28 -0
  3. data/config/cli_config.template.yml +2 -0
  4. data/config/hammer.completion +5 -0
  5. data/doc/commands_extension.md +12 -0
  6. data/doc/creating_commands.md +100 -0
  7. data/doc/installation.md +47 -4
  8. data/doc/release_notes.md +32 -5
  9. data/lib/hammer_cli.rb +1 -0
  10. data/lib/hammer_cli/abstract.rb +61 -4
  11. data/lib/hammer_cli/apipie/api_connection.rb +5 -1
  12. data/lib/hammer_cli/apipie/command.rb +3 -2
  13. data/lib/hammer_cli/apipie/option_builder.rb +15 -13
  14. data/lib/hammer_cli/apipie/option_definition.rb +9 -7
  15. data/lib/hammer_cli/bash.rb +2 -0
  16. data/lib/hammer_cli/bash/completion.rb +159 -0
  17. data/lib/hammer_cli/bash/prebuild_command.rb +21 -0
  18. data/lib/hammer_cli/command_extensions.rb +21 -1
  19. data/lib/hammer_cli/connection.rb +4 -0
  20. data/lib/hammer_cli/exception_handler.rb +11 -2
  21. data/lib/hammer_cli/full_help.rb +8 -1
  22. data/lib/hammer_cli/help/builder.rb +29 -3
  23. data/lib/hammer_cli/logger_watch.rb +1 -1
  24. data/lib/hammer_cli/main.rb +5 -3
  25. data/lib/hammer_cli/options/normalizers.rb +7 -3
  26. data/lib/hammer_cli/options/option_definition.rb +26 -6
  27. data/lib/hammer_cli/options/option_family.rb +114 -0
  28. data/lib/hammer_cli/options/predefined.rb +1 -1
  29. data/lib/hammer_cli/output.rb +1 -1
  30. data/lib/hammer_cli/output/adapter/abstract.rb +1 -5
  31. data/lib/hammer_cli/output/adapter/base.rb +1 -1
  32. data/lib/hammer_cli/output/adapter/csv.rb +3 -2
  33. data/lib/hammer_cli/output/adapter/json.rb +14 -3
  34. data/lib/hammer_cli/output/adapter/silent.rb +1 -1
  35. data/lib/hammer_cli/output/adapter/table.rb +30 -80
  36. data/lib/hammer_cli/output/adapter/yaml.rb +6 -3
  37. data/lib/hammer_cli/output/definition.rb +11 -56
  38. data/lib/hammer_cli/output/generators.rb +1 -0
  39. data/lib/hammer_cli/output/generators/table.rb +121 -0
  40. data/lib/hammer_cli/output/output.rb +2 -4
  41. data/lib/hammer_cli/settings.rb +2 -1
  42. data/lib/hammer_cli/subcommand.rb +25 -1
  43. data/lib/hammer_cli/testing/command_assertions.rb +2 -2
  44. data/lib/hammer_cli/utils.rb +22 -0
  45. data/lib/hammer_cli/version.rb +1 -1
  46. data/locale/ca/LC_MESSAGES/hammer-cli.mo +0 -0
  47. data/locale/de/LC_MESSAGES/hammer-cli.mo +0 -0
  48. data/locale/en/LC_MESSAGES/hammer-cli.mo +0 -0
  49. data/locale/en_GB/LC_MESSAGES/hammer-cli.mo +0 -0
  50. data/locale/es/LC_MESSAGES/hammer-cli.mo +0 -0
  51. data/locale/fr/LC_MESSAGES/hammer-cli.mo +0 -0
  52. data/locale/it/LC_MESSAGES/hammer-cli.mo +0 -0
  53. data/locale/ja/LC_MESSAGES/hammer-cli.mo +0 -0
  54. data/locale/ko/LC_MESSAGES/hammer-cli.mo +0 -0
  55. data/locale/pt_BR/LC_MESSAGES/hammer-cli.mo +0 -0
  56. data/locale/ru/LC_MESSAGES/hammer-cli.mo +0 -0
  57. data/locale/zh_CN/LC_MESSAGES/hammer-cli.mo +0 -0
  58. data/locale/zh_TW/LC_MESSAGES/hammer-cli.mo +0 -0
  59. data/man/hammer.1.gz +0 -0
  60. data/test/unit/abstract_test.rb +23 -2
  61. data/test/unit/apipie/api_connection_test.rb +1 -0
  62. data/test/unit/apipie/option_builder_test.rb +8 -0
  63. data/test/unit/bash_test.rb +138 -0
  64. data/test/unit/command_extensions_test.rb +67 -49
  65. data/test/unit/exception_handler_test.rb +44 -0
  66. data/test/unit/help/builder_test.rb +22 -0
  67. data/test/unit/options/option_family_test.rb +48 -0
  68. data/test/unit/output/adapter/base_test.rb +58 -0
  69. data/test/unit/output/adapter/csv_test.rb +63 -1
  70. data/test/unit/output/adapter/json_test.rb +61 -0
  71. data/test/unit/output/adapter/table_test.rb +70 -1
  72. data/test/unit/output/adapter/yaml_test.rb +59 -0
  73. data/test/unit/output/definition_test.rb +7 -7
  74. data/test/unit/output/output_test.rb +3 -3
  75. metadata +83 -345
  76. data/hammer_cli_complete +0 -13
  77. data/test/reports/TEST-Fields-ContainerField-display-.xml +0 -7
  78. data/test/reports/TEST-Fields-ContainerField-display-blank-is-allowed.xml +0 -15
  79. data/test/reports/TEST-Fields-ContainerField-display-blank-is-not-allowed.xml +0 -15
  80. data/test/reports/TEST-Fields-ContainerField.xml +0 -7
  81. data/test/reports/TEST-Fields-Field-display-.xml +0 -7
  82. data/test/reports/TEST-Fields-Field-display-blank-is-allowed.xml +0 -11
  83. data/test/reports/TEST-Fields-Field-display-blank-is-not-allowed.xml +0 -11
  84. data/test/reports/TEST-Fields-Field-hide-blank-.xml +0 -11
  85. data/test/reports/TEST-Fields-Field-parameters.xml +0 -9
  86. data/test/reports/TEST-Fields-Field.xml +0 -13
  87. data/test/reports/TEST-HammerCLI-AbstractCommand-build-options.xml +0 -15
  88. data/test/reports/TEST-HammerCLI-AbstractCommand-exception-handler.xml +0 -13
  89. data/test/reports/TEST-HammerCLI-AbstractCommand-logging.xml +0 -21
  90. data/test/reports/TEST-HammerCLI-AbstractCommand-option-builder.xml +0 -11
  91. data/test/reports/TEST-HammerCLI-AbstractCommand-options.xml +0 -11
  92. data/test/reports/TEST-HammerCLI-AbstractCommand-output.xml +0 -19
  93. data/test/reports/TEST-HammerCLI-AbstractCommand-subcommand-behavior-remove-subcommand.xml +0 -11
  94. data/test/reports/TEST-HammerCLI-AbstractCommand-subcommand-behavior-subcommand-.xml +0 -13
  95. data/test/reports/TEST-HammerCLI-AbstractCommand-subcommand-behavior-subcommand.xml +0 -11
  96. data/test/reports/TEST-HammerCLI-AbstractCommand-subcommand-behavior.xml +0 -7
  97. data/test/reports/TEST-HammerCLI-AbstractCommand.xml +0 -11
  98. data/test/reports/TEST-HammerCLI-Apipie-Command-options.xml +0 -11
  99. data/test/reports/TEST-HammerCLI-Apipie-Command-resource-defined.xml +0 -9
  100. data/test/reports/TEST-HammerCLI-Apipie-Command-setting-resources.xml +0 -19
  101. data/test/reports/TEST-HammerCLI-Apipie-Command.xml +0 -9
  102. data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder-aliasing-resources.xml +0 -13
  103. data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder-filtering-options.xml +0 -15
  104. data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder-required-options.xml +0 -11
  105. data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder-setting-correct-normalizers.xml +0 -9
  106. data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder-with-hash-params.xml +0 -11
  107. data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder-with-one-simple-param.xml +0 -15
  108. data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder.xml +0 -7
  109. data/test/reports/TEST-HammerCLI-Completer-command-completion.xml +0 -29
  110. data/test/reports/TEST-HammerCLI-Completer-option-value-completion.xml +0 -17
  111. data/test/reports/TEST-HammerCLI-Completer-subcommand-completion.xml +0 -19
  112. data/test/reports/TEST-HammerCLI-Completer.xml +0 -7
  113. data/test/reports/TEST-HammerCLI-CompleterLine-line-complete.xml +0 -25
  114. data/test/reports/TEST-HammerCLI-CompleterLine-splitting-words.xml +0 -29
  115. data/test/reports/TEST-HammerCLI-CompleterLine.xml +0 -7
  116. data/test/reports/TEST-HammerCLI-CompleterWord-complete-.xml +0 -23
  117. data/test/reports/TEST-HammerCLI-CompleterWord-quote.xml +0 -15
  118. data/test/reports/TEST-HammerCLI-CompleterWord-quoted-.xml +0 -13
  119. data/test/reports/TEST-HammerCLI-CompleterWord.xml +0 -7
  120. data/test/reports/TEST-HammerCLI-Connection.xml +0 -21
  121. data/test/reports/TEST-HammerCLI-ExceptionHandler.xml +0 -21
  122. data/test/reports/TEST-HammerCLI-I18n.xml +0 -11
  123. data/test/reports/TEST-HammerCLI-MainCommand-loading-context-password.xml +0 -11
  124. data/test/reports/TEST-HammerCLI-MainCommand-loading-context-username.xml +0 -11
  125. data/test/reports/TEST-HammerCLI-MainCommand-loading-context-verbose.xml +0 -9
  126. data/test/reports/TEST-HammerCLI-MainCommand-loading-context.xml +0 -7
  127. data/test/reports/TEST-HammerCLI-MainCommand.xml +0 -7
  128. data/test/reports/TEST-HammerCLI-Modules-find-by-name.xml +0 -13
  129. data/test/reports/TEST-HammerCLI-Modules-load-a-module-module-not-found.xml +0 -13
  130. data/test/reports/TEST-HammerCLI-Modules-load-a-module-module-runtime-exception.xml +0 -13
  131. data/test/reports/TEST-HammerCLI-Modules-load-a-module-success.xml +0 -15
  132. data/test/reports/TEST-HammerCLI-Modules-load-a-module.xml +0 -7
  133. data/test/reports/TEST-HammerCLI-Modules-load-all-modules.xml +0 -9
  134. data/test/reports/TEST-HammerCLI-Modules-names.xml +0 -13
  135. data/test/reports/TEST-HammerCLI-Modules.xml +0 -7
  136. data/test/reports/TEST-HammerCLI-OptionBuilderContainer.0.xml +0 -7
  137. data/test/reports/TEST-HammerCLI-OptionBuilderContainer.xml +0 -11
  138. data/test/reports/TEST-HammerCLI-Options-Normalizers-abstract.xml +0 -9
  139. data/test/reports/TEST-HammerCLI-Options-Normalizers-bool.xml +0 -31
  140. data/test/reports/TEST-HammerCLI-Options-Normalizers-datetime.xml +0 -17
  141. data/test/reports/TEST-HammerCLI-Options-Normalizers-enum.xml +0 -15
  142. data/test/reports/TEST-HammerCLI-Options-Normalizers-enumlist.xml +0 -21
  143. data/test/reports/TEST-HammerCLI-Options-Normalizers-json-input.xml +0 -15
  144. data/test/reports/TEST-HammerCLI-Options-Normalizers-key-value-list.xml +0 -17
  145. data/test/reports/TEST-HammerCLI-Options-Normalizers-list.xml +0 -15
  146. data/test/reports/TEST-HammerCLI-Options-Normalizers.xml +0 -7
  147. data/test/reports/TEST-HammerCLI-Options-OptionDefinition-context.xml +0 -9
  148. data/test/reports/TEST-HammerCLI-Options-OptionDefinition-formatters.xml +0 -11
  149. data/test/reports/TEST-HammerCLI-Options-OptionDefinition.xml +0 -7
  150. data/test/reports/TEST-HammerCLI-Output-Adapter-Abstract-error-messages.xml +0 -15
  151. data/test/reports/TEST-HammerCLI-Output-Adapter-Abstract-messages.xml +0 -11
  152. data/test/reports/TEST-HammerCLI-Output-Adapter-Abstract-test-data-for-field.xml +0 -15
  153. data/test/reports/TEST-HammerCLI-Output-Adapter-Abstract.xml +0 -17
  154. data/test/reports/TEST-HammerCLI-Output-Adapter-Base-print-collection-show-ids.xml +0 -9
  155. data/test/reports/TEST-HammerCLI-Output-Adapter-Base-print-collection.xml +0 -27
  156. data/test/reports/TEST-HammerCLI-Output-Adapter-Base.xml +0 -7
  157. data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues-print-collection-formatters.xml +0 -11
  158. data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues-print-collection-handle-fields-with-collections.xml +0 -13
  159. data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues-print-collection-handle-fields-with-containers.xml +0 -11
  160. data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues-print-collection-handle-ids.xml +0 -11
  161. data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues-print-collection.xml +0 -11
  162. data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues-print-message.xml +0 -11
  163. data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues.xml +0 -7
  164. data/test/reports/TEST-HammerCLI-Output-Adapter-Table-print-collection-column-width.xml +0 -15
  165. data/test/reports/TEST-HammerCLI-Output-Adapter-Table-print-collection-formatters.xml +0 -11
  166. data/test/reports/TEST-HammerCLI-Output-Adapter-Table-print-collection-handle-ids.xml +0 -11
  167. data/test/reports/TEST-HammerCLI-Output-Adapter-Table-print-collection-sort-columns.xml +0 -9
  168. data/test/reports/TEST-HammerCLI-Output-Adapter-Table-print-collection.xml +0 -11
  169. data/test/reports/TEST-HammerCLI-Output-Adapter-Table.xml +0 -7
  170. data/test/reports/TEST-HammerCLI-Output-Definition-empty-.xml +0 -11
  171. data/test/reports/TEST-HammerCLI-Output-Definition.xml +0 -11
  172. data/test/reports/TEST-HammerCLI-Output-Dsl-collection.xml +0 -13
  173. data/test/reports/TEST-HammerCLI-Output-Dsl-custom-fields.xml +0 -11
  174. data/test/reports/TEST-HammerCLI-Output-Dsl-fields.xml +0 -15
  175. data/test/reports/TEST-HammerCLI-Output-Dsl-label.xml +0 -13
  176. data/test/reports/TEST-HammerCLI-Output-Dsl-path-definition.xml +0 -13
  177. data/test/reports/TEST-HammerCLI-Output-Dsl.xml +0 -9
  178. data/test/reports/TEST-HammerCLI-Output-FieldFilter.xml +0 -13
  179. data/test/reports/TEST-HammerCLI-Output-Formatters-BooleanFormatter.xml +0 -11
  180. data/test/reports/TEST-HammerCLI-Output-Formatters-ColorFormatter.xml +0 -9
  181. data/test/reports/TEST-HammerCLI-Output-Formatters-DateFormatter.xml +0 -11
  182. data/test/reports/TEST-HammerCLI-Output-Formatters-FieldFormatter.xml +0 -13
  183. data/test/reports/TEST-HammerCLI-Output-Formatters-FormatterContainer.xml +0 -13
  184. data/test/reports/TEST-HammerCLI-Output-Formatters-FormatterLibrary.xml +0 -11
  185. data/test/reports/TEST-HammerCLI-Output-Formatters-KeyValueFormatter.xml +0 -13
  186. data/test/reports/TEST-HammerCLI-Output-Formatters-ListFormatter.xml +0 -13
  187. data/test/reports/TEST-HammerCLI-Output-Formatters-LongTextFormatter.xml +0 -13
  188. data/test/reports/TEST-HammerCLI-Output-Output-adapters.xml +0 -17
  189. data/test/reports/TEST-HammerCLI-Output-Output-data.xml +0 -15
  190. data/test/reports/TEST-HammerCLI-Output-Output-formatters.xml +0 -9
  191. data/test/reports/TEST-HammerCLI-Output-Output-messages.xml +0 -19
  192. data/test/reports/TEST-HammerCLI-Output-Output.xml +0 -7
  193. data/test/reports/TEST-HammerCLI-Output-RecordCollection.xml +0 -13
  194. data/test/reports/TEST-HammerCLI-Settings-load-from-paths.xml +0 -15
  195. data/test/reports/TEST-HammerCLI-Settings.xml +0 -25
  196. data/test/reports/TEST-HammerCLI-ShellHistory-loading-old-history.xml +0 -11
  197. data/test/reports/TEST-HammerCLI-ShellHistory-saving-history.xml +0 -15
  198. data/test/reports/TEST-HammerCLI-ShellHistory.xml +0 -7
  199. data/test/reports/TEST-MiniTest-Spec.xml +0 -7
  200. data/test/reports/TEST-String-camelize.xml +0 -11
  201. data/test/reports/TEST-String-formatting.xml +0 -17
  202. data/test/reports/TEST-String-indent.xml +0 -11
  203. data/test/reports/TEST-String-interactive-.xml +0 -13
  204. data/test/reports/TEST-String.xml +0 -7
  205. data/test/reports/TEST-constraints-HammerCLI-Validator-AllConstraint-exist-.xml +0 -13
  206. data/test/reports/TEST-constraints-HammerCLI-Validator-AllConstraint.xml +0 -7
  207. data/test/reports/TEST-constraints-HammerCLI-Validator-AnyConstraint-exist-.xml +0 -13
  208. data/test/reports/TEST-constraints-HammerCLI-Validator-AnyConstraint.xml +0 -7
  209. data/test/reports/TEST-constraints-HammerCLI-Validator-BaseConstraint-exist-.xml +0 -9
  210. data/test/reports/TEST-constraints-HammerCLI-Validator-BaseConstraint-rejected.xml +0 -13
  211. data/test/reports/TEST-constraints-HammerCLI-Validator-BaseConstraint-required.xml +0 -13
  212. data/test/reports/TEST-constraints-HammerCLI-Validator-BaseConstraint.xml +0 -7
  213. 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