hammer_cli 0.9.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (225) hide show
  1. checksums.yaml +4 -4
  2. data/bin/hammer +22 -1
  3. data/config/cli_config.template.yml +20 -0
  4. data/doc/release_notes.md +7 -0
  5. data/lib/hammer_cli/abstract.rb +12 -15
  6. data/lib/hammer_cli/apipie/api_connection.rb +3 -1
  7. data/lib/hammer_cli/ca_cert_fetcher.rb +67 -0
  8. data/lib/hammer_cli/defaults.rb +18 -10
  9. data/lib/hammer_cli/exception_handler.rb +44 -5
  10. data/lib/hammer_cli/main.rb +8 -0
  11. data/lib/hammer_cli/options/option_collector.rb +22 -0
  12. data/lib/hammer_cli/options/sources/command_line.rb +18 -0
  13. data/lib/hammer_cli/options/sources/saved_defaults.rb +31 -0
  14. data/lib/hammer_cli/output/adapter/table.rb +66 -87
  15. data/lib/hammer_cli/output/fields.rb +1 -1
  16. data/lib/hammer_cli/ssloptions.rb +65 -0
  17. data/lib/hammer_cli/version.rb +1 -1
  18. data/locale/ca/LC_MESSAGES/hammer-cli.mo +0 -0
  19. data/locale/de/LC_MESSAGES/hammer-cli.mo +0 -0
  20. data/locale/en/LC_MESSAGES/hammer-cli.mo +0 -0
  21. data/locale/en_GB/LC_MESSAGES/hammer-cli.mo +0 -0
  22. data/locale/es/LC_MESSAGES/hammer-cli.mo +0 -0
  23. data/locale/fr/LC_MESSAGES/hammer-cli.mo +0 -0
  24. data/locale/it/LC_MESSAGES/hammer-cli.mo +0 -0
  25. data/locale/ja/LC_MESSAGES/hammer-cli.mo +0 -0
  26. data/locale/ko/LC_MESSAGES/hammer-cli.mo +0 -0
  27. data/locale/pt_BR/LC_MESSAGES/hammer-cli.mo +0 -0
  28. data/locale/ru/LC_MESSAGES/hammer-cli.mo +0 -0
  29. data/locale/zh_CN/LC_MESSAGES/hammer-cli.mo +0 -0
  30. data/locale/zh_TW/LC_MESSAGES/hammer-cli.mo +0 -0
  31. data/man/hammer.1.gz +0 -0
  32. data/test/unit/abstract_test.rb +34 -0
  33. data/test/unit/apipie/api_connection_test.rb +3 -2
  34. data/test/unit/defaults_test.rb +15 -5
  35. data/test/unit/fixtures/defaults/defaults.yml +2 -0
  36. data/test/unit/options/option_collector_test.rb +29 -0
  37. data/test/unit/options/sources/command_line_test.rb +36 -0
  38. data/test/unit/options/sources/saved_defaults_test.rb +59 -0
  39. data/test/unit/output/adapter/table_test.rb +0 -27
  40. data/test/unit/{options → output}/field_filter_test.rb +0 -0
  41. data/test/unit/output/fields_test.rb +9 -6
  42. data/test/unit/validator_test.rb +0 -6
  43. metadata +60 -382
  44. data/lib/hammer_cli/table_print/column.rb +0 -19
  45. data/lib/hammer_cli/table_print/formatter.rb +0 -18
  46. data/locale/Makefile +0 -57
  47. data/locale/README.md +0 -18
  48. data/locale/ca/hammer-cli.edit.po +0 -445
  49. data/locale/ca/hammer-cli.po +0 -361
  50. data/locale/ca/hammer-cli.po.time_stamp +0 -0
  51. data/locale/de/hammer-cli.edit.po +0 -451
  52. data/locale/de/hammer-cli.po +0 -379
  53. data/locale/de/hammer-cli.po.time_stamp +0 -0
  54. data/locale/en/hammer-cli.edit.po +0 -443
  55. data/locale/en/hammer-cli.po +0 -355
  56. data/locale/en/hammer-cli.po.time_stamp +0 -0
  57. data/locale/en_GB/hammer-cli.edit.po +0 -445
  58. data/locale/en_GB/hammer-cli.po +0 -371
  59. data/locale/en_GB/hammer-cli.po.time_stamp +0 -0
  60. data/locale/es/hammer-cli.edit.po +0 -448
  61. data/locale/es/hammer-cli.po +0 -377
  62. data/locale/es/hammer-cli.po.time_stamp +0 -0
  63. data/locale/fr/hammer-cli.edit.po +0 -447
  64. data/locale/fr/hammer-cli.po +0 -374
  65. data/locale/fr/hammer-cli.po.time_stamp +0 -0
  66. data/locale/hammer-cli.pot +0 -461
  67. data/locale/it/hammer-cli.edit.po +0 -446
  68. data/locale/it/hammer-cli.po +0 -377
  69. data/locale/it/hammer-cli.po.time_stamp +0 -0
  70. data/locale/ja/hammer-cli.edit.po +0 -445
  71. data/locale/ja/hammer-cli.po +0 -363
  72. data/locale/ja/hammer-cli.po.time_stamp +0 -0
  73. data/locale/ko/hammer-cli.edit.po +0 -445
  74. data/locale/ko/hammer-cli.po +0 -364
  75. data/locale/ko/hammer-cli.po.time_stamp +0 -0
  76. data/locale/pt_BR/hammer-cli.edit.po +0 -449
  77. data/locale/pt_BR/hammer-cli.po +0 -374
  78. data/locale/pt_BR/hammer-cli.po.time_stamp +0 -0
  79. data/locale/ru/hammer-cli.edit.po +0 -448
  80. data/locale/ru/hammer-cli.po +0 -374
  81. data/locale/ru/hammer-cli.po.time_stamp +0 -0
  82. data/locale/zanata.xml +0 -28
  83. data/locale/zh_CN/hammer-cli.edit.po +0 -445
  84. data/locale/zh_CN/hammer-cli.po +0 -367
  85. data/locale/zh_CN/hammer-cli.po.time_stamp +0 -0
  86. data/locale/zh_TW/hammer-cli.edit.po +0 -445
  87. data/locale/zh_TW/hammer-cli.po +0 -364
  88. data/locale/zh_TW/hammer-cli.po.time_stamp +0 -0
  89. data/test/reports/TEST-Fields-ContainerField-display-.xml +0 -7
  90. data/test/reports/TEST-Fields-ContainerField-display-blank-is-allowed.xml +0 -15
  91. data/test/reports/TEST-Fields-ContainerField-display-blank-is-not-allowed.xml +0 -15
  92. data/test/reports/TEST-Fields-ContainerField.xml +0 -7
  93. data/test/reports/TEST-Fields-Field-display-.xml +0 -7
  94. data/test/reports/TEST-Fields-Field-display-blank-is-allowed.xml +0 -11
  95. data/test/reports/TEST-Fields-Field-display-blank-is-not-allowed.xml +0 -11
  96. data/test/reports/TEST-Fields-Field-hide-blank-.xml +0 -11
  97. data/test/reports/TEST-Fields-Field-parameters.xml +0 -9
  98. data/test/reports/TEST-Fields-Field.xml +0 -13
  99. data/test/reports/TEST-HammerCLI-AbstractCommand-build-options.xml +0 -15
  100. data/test/reports/TEST-HammerCLI-AbstractCommand-exception-handler.xml +0 -13
  101. data/test/reports/TEST-HammerCLI-AbstractCommand-logging.xml +0 -21
  102. data/test/reports/TEST-HammerCLI-AbstractCommand-option-builder.xml +0 -11
  103. data/test/reports/TEST-HammerCLI-AbstractCommand-options.xml +0 -11
  104. data/test/reports/TEST-HammerCLI-AbstractCommand-output.xml +0 -19
  105. data/test/reports/TEST-HammerCLI-AbstractCommand-subcommand-behavior-remove-subcommand.xml +0 -11
  106. data/test/reports/TEST-HammerCLI-AbstractCommand-subcommand-behavior-subcommand-.xml +0 -13
  107. data/test/reports/TEST-HammerCLI-AbstractCommand-subcommand-behavior-subcommand.xml +0 -11
  108. data/test/reports/TEST-HammerCLI-AbstractCommand-subcommand-behavior.xml +0 -7
  109. data/test/reports/TEST-HammerCLI-AbstractCommand.xml +0 -11
  110. data/test/reports/TEST-HammerCLI-Apipie-Command-options.xml +0 -11
  111. data/test/reports/TEST-HammerCLI-Apipie-Command-resource-defined.xml +0 -9
  112. data/test/reports/TEST-HammerCLI-Apipie-Command-setting-resources.xml +0 -19
  113. data/test/reports/TEST-HammerCLI-Apipie-Command.xml +0 -9
  114. data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder-aliasing-resources.xml +0 -13
  115. data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder-filtering-options.xml +0 -15
  116. data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder-required-options.xml +0 -11
  117. data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder-setting-correct-normalizers.xml +0 -9
  118. data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder-with-hash-params.xml +0 -11
  119. data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder-with-one-simple-param.xml +0 -15
  120. data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder.xml +0 -7
  121. data/test/reports/TEST-HammerCLI-Completer-command-completion.xml +0 -29
  122. data/test/reports/TEST-HammerCLI-Completer-option-value-completion.xml +0 -17
  123. data/test/reports/TEST-HammerCLI-Completer-subcommand-completion.xml +0 -19
  124. data/test/reports/TEST-HammerCLI-Completer.xml +0 -7
  125. data/test/reports/TEST-HammerCLI-CompleterLine-line-complete.xml +0 -25
  126. data/test/reports/TEST-HammerCLI-CompleterLine-splitting-words.xml +0 -29
  127. data/test/reports/TEST-HammerCLI-CompleterLine.xml +0 -7
  128. data/test/reports/TEST-HammerCLI-CompleterWord-complete-.xml +0 -23
  129. data/test/reports/TEST-HammerCLI-CompleterWord-quote.xml +0 -15
  130. data/test/reports/TEST-HammerCLI-CompleterWord-quoted-.xml +0 -13
  131. data/test/reports/TEST-HammerCLI-CompleterWord.xml +0 -7
  132. data/test/reports/TEST-HammerCLI-Connection.xml +0 -21
  133. data/test/reports/TEST-HammerCLI-ExceptionHandler.xml +0 -21
  134. data/test/reports/TEST-HammerCLI-I18n.xml +0 -11
  135. data/test/reports/TEST-HammerCLI-MainCommand-loading-context-password.xml +0 -11
  136. data/test/reports/TEST-HammerCLI-MainCommand-loading-context-username.xml +0 -11
  137. data/test/reports/TEST-HammerCLI-MainCommand-loading-context-verbose.xml +0 -9
  138. data/test/reports/TEST-HammerCLI-MainCommand-loading-context.xml +0 -7
  139. data/test/reports/TEST-HammerCLI-MainCommand.xml +0 -7
  140. data/test/reports/TEST-HammerCLI-Modules-find-by-name.xml +0 -13
  141. data/test/reports/TEST-HammerCLI-Modules-load-a-module-module-not-found.xml +0 -13
  142. data/test/reports/TEST-HammerCLI-Modules-load-a-module-module-runtime-exception.xml +0 -13
  143. data/test/reports/TEST-HammerCLI-Modules-load-a-module-success.xml +0 -15
  144. data/test/reports/TEST-HammerCLI-Modules-load-a-module.xml +0 -7
  145. data/test/reports/TEST-HammerCLI-Modules-load-all-modules.xml +0 -9
  146. data/test/reports/TEST-HammerCLI-Modules-names.xml +0 -13
  147. data/test/reports/TEST-HammerCLI-Modules.xml +0 -7
  148. data/test/reports/TEST-HammerCLI-OptionBuilderContainer.0.xml +0 -7
  149. data/test/reports/TEST-HammerCLI-OptionBuilderContainer.xml +0 -11
  150. data/test/reports/TEST-HammerCLI-Options-Normalizers-abstract.xml +0 -9
  151. data/test/reports/TEST-HammerCLI-Options-Normalizers-bool.xml +0 -31
  152. data/test/reports/TEST-HammerCLI-Options-Normalizers-datetime.xml +0 -17
  153. data/test/reports/TEST-HammerCLI-Options-Normalizers-enum.xml +0 -15
  154. data/test/reports/TEST-HammerCLI-Options-Normalizers-enumlist.xml +0 -21
  155. data/test/reports/TEST-HammerCLI-Options-Normalizers-json-input.xml +0 -15
  156. data/test/reports/TEST-HammerCLI-Options-Normalizers-key-value-list.xml +0 -17
  157. data/test/reports/TEST-HammerCLI-Options-Normalizers-list.xml +0 -15
  158. data/test/reports/TEST-HammerCLI-Options-Normalizers.xml +0 -7
  159. data/test/reports/TEST-HammerCLI-Options-OptionDefinition-context.xml +0 -9
  160. data/test/reports/TEST-HammerCLI-Options-OptionDefinition-formatters.xml +0 -11
  161. data/test/reports/TEST-HammerCLI-Options-OptionDefinition.xml +0 -7
  162. data/test/reports/TEST-HammerCLI-Output-Adapter-Abstract-error-messages.xml +0 -15
  163. data/test/reports/TEST-HammerCLI-Output-Adapter-Abstract-messages.xml +0 -11
  164. data/test/reports/TEST-HammerCLI-Output-Adapter-Abstract-test-data-for-field.xml +0 -15
  165. data/test/reports/TEST-HammerCLI-Output-Adapter-Abstract.xml +0 -17
  166. data/test/reports/TEST-HammerCLI-Output-Adapter-Base-print-collection-show-ids.xml +0 -9
  167. data/test/reports/TEST-HammerCLI-Output-Adapter-Base-print-collection.xml +0 -27
  168. data/test/reports/TEST-HammerCLI-Output-Adapter-Base.xml +0 -7
  169. data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues-print-collection-formatters.xml +0 -11
  170. data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues-print-collection-handle-fields-with-collections.xml +0 -13
  171. data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues-print-collection-handle-fields-with-containers.xml +0 -11
  172. data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues-print-collection-handle-ids.xml +0 -11
  173. data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues-print-collection.xml +0 -11
  174. data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues-print-message.xml +0 -11
  175. data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues.xml +0 -7
  176. data/test/reports/TEST-HammerCLI-Output-Adapter-Table-print-collection-column-width.xml +0 -15
  177. data/test/reports/TEST-HammerCLI-Output-Adapter-Table-print-collection-formatters.xml +0 -11
  178. data/test/reports/TEST-HammerCLI-Output-Adapter-Table-print-collection-handle-ids.xml +0 -11
  179. data/test/reports/TEST-HammerCLI-Output-Adapter-Table-print-collection-sort-columns.xml +0 -9
  180. data/test/reports/TEST-HammerCLI-Output-Adapter-Table-print-collection.xml +0 -11
  181. data/test/reports/TEST-HammerCLI-Output-Adapter-Table.xml +0 -7
  182. data/test/reports/TEST-HammerCLI-Output-Definition-empty-.xml +0 -11
  183. data/test/reports/TEST-HammerCLI-Output-Definition.xml +0 -11
  184. data/test/reports/TEST-HammerCLI-Output-Dsl-collection.xml +0 -13
  185. data/test/reports/TEST-HammerCLI-Output-Dsl-custom-fields.xml +0 -11
  186. data/test/reports/TEST-HammerCLI-Output-Dsl-fields.xml +0 -15
  187. data/test/reports/TEST-HammerCLI-Output-Dsl-label.xml +0 -13
  188. data/test/reports/TEST-HammerCLI-Output-Dsl-path-definition.xml +0 -13
  189. data/test/reports/TEST-HammerCLI-Output-Dsl.xml +0 -9
  190. data/test/reports/TEST-HammerCLI-Output-FieldFilter.xml +0 -13
  191. data/test/reports/TEST-HammerCLI-Output-Formatters-BooleanFormatter.xml +0 -11
  192. data/test/reports/TEST-HammerCLI-Output-Formatters-ColorFormatter.xml +0 -9
  193. data/test/reports/TEST-HammerCLI-Output-Formatters-DateFormatter.xml +0 -11
  194. data/test/reports/TEST-HammerCLI-Output-Formatters-FieldFormatter.xml +0 -13
  195. data/test/reports/TEST-HammerCLI-Output-Formatters-FormatterContainer.xml +0 -13
  196. data/test/reports/TEST-HammerCLI-Output-Formatters-FormatterLibrary.xml +0 -11
  197. data/test/reports/TEST-HammerCLI-Output-Formatters-KeyValueFormatter.xml +0 -13
  198. data/test/reports/TEST-HammerCLI-Output-Formatters-ListFormatter.xml +0 -13
  199. data/test/reports/TEST-HammerCLI-Output-Formatters-LongTextFormatter.xml +0 -13
  200. data/test/reports/TEST-HammerCLI-Output-Output-adapters.xml +0 -17
  201. data/test/reports/TEST-HammerCLI-Output-Output-data.xml +0 -15
  202. data/test/reports/TEST-HammerCLI-Output-Output-formatters.xml +0 -9
  203. data/test/reports/TEST-HammerCLI-Output-Output-messages.xml +0 -19
  204. data/test/reports/TEST-HammerCLI-Output-Output.xml +0 -7
  205. data/test/reports/TEST-HammerCLI-Output-RecordCollection.xml +0 -13
  206. data/test/reports/TEST-HammerCLI-Settings-load-from-paths.xml +0 -15
  207. data/test/reports/TEST-HammerCLI-Settings.xml +0 -25
  208. data/test/reports/TEST-HammerCLI-ShellHistory-loading-old-history.xml +0 -11
  209. data/test/reports/TEST-HammerCLI-ShellHistory-saving-history.xml +0 -15
  210. data/test/reports/TEST-HammerCLI-ShellHistory.xml +0 -7
  211. data/test/reports/TEST-MiniTest-Spec.xml +0 -7
  212. data/test/reports/TEST-String-camelize.xml +0 -11
  213. data/test/reports/TEST-String-formatting.xml +0 -17
  214. data/test/reports/TEST-String-indent.xml +0 -11
  215. data/test/reports/TEST-String-interactive-.xml +0 -13
  216. data/test/reports/TEST-String.xml +0 -7
  217. data/test/reports/TEST-constraints-HammerCLI-Validator-AllConstraint-exist-.xml +0 -13
  218. data/test/reports/TEST-constraints-HammerCLI-Validator-AllConstraint.xml +0 -7
  219. data/test/reports/TEST-constraints-HammerCLI-Validator-AnyConstraint-exist-.xml +0 -13
  220. data/test/reports/TEST-constraints-HammerCLI-Validator-AnyConstraint.xml +0 -7
  221. data/test/reports/TEST-constraints-HammerCLI-Validator-BaseConstraint-exist-.xml +0 -9
  222. data/test/reports/TEST-constraints-HammerCLI-Validator-BaseConstraint-rejected.xml +0 -13
  223. data/test/reports/TEST-constraints-HammerCLI-Validator-BaseConstraint-required.xml +0 -13
  224. data/test/reports/TEST-constraints-HammerCLI-Validator-BaseConstraint.xml +0 -7
  225. data/test/reports/TEST-constraints.xml +0 -7
@@ -0,0 +1,65 @@
1
+ module HammerCLI
2
+ class SSLOptions
3
+ def initialize(settings = HammerCLI::Settings, logger = Logging.logger['SSLoptions'])
4
+ @settings = settings
5
+ @logger = logger
6
+ end
7
+
8
+ def self.get_options(settings = HammerCLI::Settings, logger = Logging.logger['SSLoptions'])
9
+ self.new(settings, logger).get_options
10
+ end
11
+
12
+ def get_options
13
+ ssl_options = {}
14
+ for sslopt in [:ssl_ca_file, :ssl_ca_path, :verify_ssl] do
15
+ ssloptval = read_ssl_option(sslopt)
16
+ ssl_options[sslopt] = ssloptval unless ssloptval.nil?
17
+ end
18
+ ssl_options.merge!(cert_key_options)
19
+
20
+ # enable ssl verification
21
+ ssl_options[:verify_ssl] = true if ssl_options[:verify_ssl].nil?
22
+ @logger.debug("SSL options: #{ApipieBindings::Utils::inspect_data(ssl_options)}")
23
+ ssl_options
24
+ end
25
+
26
+ protected
27
+
28
+ def read_ssl_option(key)
29
+ @settings.get(:_params, key).nil? ? @settings.get(:ssl, key) : @settings.get(:_params, key)
30
+ end
31
+
32
+ def cert_key_options
33
+ options = {
34
+ :ssl_client_cert => read_certificate(read_ssl_option(:ssl_client_cert)),
35
+ :ssl_client_key => read_key(read_ssl_option(:ssl_client_key))
36
+ }
37
+
38
+ if options[:ssl_client_cert] && options[:ssl_client_key]
39
+ options
40
+ elsif options[:ssl_client_cert] || options[:ssl_client_key]
41
+ if options[:ssl_client_cert]
42
+ warn _("SSL client certificate is set but the key is not")
43
+ elsif options[:ssl_client_key]
44
+ warn _("SSL client key is set but the certificate is not")
45
+ end
46
+ warn _("SSL client authentication disabled")
47
+ {}
48
+ else
49
+ {}
50
+ end
51
+ end
52
+
53
+ def read_certificate(path)
54
+ OpenSSL::X509::Certificate.new(File.read(path)) unless path.nil?
55
+ rescue SystemCallError => e
56
+ warn _("Could't read SSL client certificate %s") % path
57
+ end
58
+
59
+ def read_key(path)
60
+ OpenSSL::PKey::RSA.new(File.read(path)) unless path.nil?
61
+ rescue SystemCallError => e
62
+ warn _("Could't read SSL client key %s") % path
63
+ end
64
+ end
65
+ end
@@ -1,5 +1,5 @@
1
1
  module HammerCLI
2
2
  def self.version
3
- @version ||= Gem::Version.new '0.9.0'
3
+ @version ||= Gem::Version.new '0.10.0'
4
4
  end
5
5
  end
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
data/man/hammer.1.gz CHANGED
Binary file
@@ -351,6 +351,40 @@ describe HammerCLI::AbstractCommand do
351
351
 
352
352
  end
353
353
 
354
+ describe 'defaults' do
355
+ class TestDefaultsCmd < HammerCLI::AbstractCommand
356
+ option '--test', 'TEST', '', :attribute_name => :different_attr_name
357
+ option ['--test-multi1', '--test-multi2'], 'TEST_MULTI', '', :attribute_name => :multiple_switches_option
358
+
359
+ def options
360
+ super
361
+ end
362
+ end
363
+
364
+ before do
365
+ @defaults = mock()
366
+ @defaults.stubs(:get_defaults).returns(nil)
367
+ @cmd = TestDefaultsCmd.new("", { :defaults => @defaults })
368
+ end
369
+
370
+ it 'provides default value for an option flag' do
371
+ @defaults.expects(:get_defaults).with('--test').returns(2)
372
+ assert_equal({'different_attr_name' => 2}, @cmd.options)
373
+ end
374
+
375
+ it 'prefers values from command line' do
376
+ @defaults.stubs(:get_defaults).with('--test').returns(2)
377
+ @cmd.run(['--test=1'])
378
+ assert_equal({'different_attr_name' => '1'}, @cmd.options)
379
+ end
380
+
381
+ it 'iterates over multiple switches of an option' do
382
+ @defaults.expects(:get_defaults).with('--test-multi1').returns(nil)
383
+ @defaults.expects(:get_defaults).with('--test-multi2').returns(3)
384
+ assert_equal({'multiple_switches_option' => 3}, @cmd.options)
385
+ end
386
+ end
387
+
354
388
  it "should inherit command_name" do
355
389
  class CmdName1 < HammerCLI::AbstractCommand
356
390
  command_name 'cmd'
@@ -7,9 +7,10 @@ describe HammerCLI::Apipie::ApiConnection do
7
7
 
8
8
  let(:empty_params) {{}}
9
9
 
10
- def api_stub(params = {})
10
+ def api_stub(params = {}, options = {})
11
11
  api_stub = stub()
12
- ApipieBindings::API.expects(:new).with(params).returns(api_stub)
12
+ options[:verify_ssl] = true if options[:verify_ssl].nil?
13
+ ApipieBindings::API.expects(:new).with(params, options).returns(api_stub)
13
14
  api_stub
14
15
  end
15
16
 
@@ -29,6 +29,12 @@ describe HammerCLI::Defaults do
29
29
  assert_equal 3, defaults_result[:defaults][:location_id][:value]
30
30
  assert_equal nil, defaults_result[:defaults][:'location-id']
31
31
  end
32
+
33
+ it "should update underscored default with option syntax when dashed default is set" do
34
+ defaults_result = @defaults.add_defaults_to_conf({"--location-id"=> 3}, nil)
35
+ assert_equal 3, defaults_result[:defaults][:'location-id'][:value]
36
+ assert_equal nil, defaults_result[:defaults][:location_id]
37
+ end
32
38
  end
33
39
 
34
40
  it "Should add a default param to defaults file, with provider" do
@@ -70,8 +76,12 @@ describe HammerCLI::Defaults do
70
76
 
71
77
 
72
78
  describe '#get_defaults' do
73
- it "should get the default param, without provider" do
74
- assert_equal 2, @defaults.get_defaults("location_id")
79
+ it "should get the default param" do
80
+ assert_equal 2, @defaults.get_defaults("--location-id")
81
+ end
82
+
83
+ it "should get the default param for short flag" do
84
+ assert_equal 'F', @defaults.get_defaults("-f")
75
85
  end
76
86
 
77
87
  it "should get the default param, with provider" do
@@ -79,14 +89,14 @@ describe HammerCLI::Defaults do
79
89
  fake_provider.stubs(:provider_name).returns(:foreman)
80
90
  fake_provider.expects(:get_defaults).with(:organization_id).returns(3)
81
91
  @defaults.register_provider(fake_provider)
82
- assert_equal 3, @defaults.get_defaults("organization_id")
92
+ assert_equal 3, @defaults.get_defaults("--organization-id")
83
93
  end
84
94
 
85
95
  context 'dashed params' do
86
96
  let(:filepath) { File.join(File.dirname(__FILE__), '/fixtures/defaults/defaults_dashed.yml') }
87
97
 
88
98
  it "should get the default param, without provider" do
89
- assert_equal 2, @defaults.get_defaults("location_id")
99
+ assert_equal 2, @defaults.get_defaults("--location-id")
90
100
  end
91
101
 
92
102
  it "should get the default param, with provider" do
@@ -94,7 +104,7 @@ describe HammerCLI::Defaults do
94
104
  fake_provider.stubs(:provider_name).returns(:foreman)
95
105
  fake_provider.expects(:get_defaults).with(:organization_id).returns(3)
96
106
  @defaults.register_provider(fake_provider)
97
- assert_equal 3, @defaults.get_defaults("organization_id")
107
+ assert_equal 3, @defaults.get_defaults("--organization-id")
98
108
  end
99
109
  end
100
110
  end
@@ -4,3 +4,5 @@
4
4
  :provider: 'foreman'
5
5
  :location_id:
6
6
  :value: 2
7
+ :f:
8
+ :value: 'F'
@@ -0,0 +1,29 @@
1
+ require_relative '../test_helper'
2
+
3
+ describe HammerCLI::Options::OptionCollector do
4
+ before do
5
+ recognised_options = [mock, mock]
6
+ source1_result = {:option1 => 1, :option2 => nil}
7
+ source2_result = source1_result.merge({:option3 => 3})
8
+
9
+ source1 = mock
10
+ source1.expects(:get_options).with(recognised_options, {}).returns(source1_result)
11
+
12
+ source2 = mock
13
+ source2.expects(:get_options).with(recognised_options, source1_result).returns(source2_result)
14
+
15
+ @collector = HammerCLI::Options::OptionCollector.new(recognised_options, [source1, source2])
16
+ end
17
+
18
+ describe '#options' do
19
+ it 'returns options without nil values' do
20
+ assert_equal({:option1 => 1, :option3 => 3}, @collector.options)
21
+ end
22
+ end
23
+
24
+ describe '#all_options' do
25
+ it 'returns all options' do
26
+ assert_equal({:option1 => 1, :option2 => nil, :option3 => 3}, @collector.all_options)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,36 @@
1
+ require_relative '../../test_helper'
2
+
3
+ describe HammerCLI::Options::Sources::CommandLine do
4
+
5
+ before do
6
+ @cmd = mock
7
+
8
+ @defined_options = [
9
+ stub(:read_method => :option_organization_id, :attribute_name => :organization_id),
10
+ stub(:read_method => :option_location_id, :attribute_name => :location_id)
11
+ ]
12
+
13
+ @source = HammerCLI::Options::Sources::CommandLine.new(@cmd)
14
+ end
15
+
16
+ describe '#get_options' do
17
+ it 'reads options from the command' do
18
+ @cmd.expects(:option_organization_id).returns(2)
19
+ @cmd.expects(:option_location_id).returns(3)
20
+
21
+ current_result = { :help => true }
22
+ expected_result = { :help => true, :organization_id => 2, :location_id => 3 }
23
+
24
+ assert_equal(expected_result, @source.get_options(@defined_options, current_result))
25
+ end
26
+
27
+ it 'keeps options that are already set' do
28
+ @cmd.expects(:option_location_id).returns(3)
29
+
30
+ current_result = { :help => true, :organization_id => 1 }
31
+ expected_result = { :help => true, :organization_id => 1, :location_id => 3 }
32
+
33
+ assert_equal(expected_result, @source.get_options(@defined_options, current_result))
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,59 @@
1
+ require_relative '../../test_helper'
2
+
3
+ describe HammerCLI::Options::Sources::SavedDefaults do
4
+ before do
5
+ @defaults = mock
6
+ @logger = stub
7
+ @logger.stubs(:info)
8
+
9
+ @defined_options = [
10
+ stub(:attribute_name => :different_attr_name, :switches => ['--test']),
11
+ stub(:attribute_name => :multiple_switches_option, :switches => ['--test-multi1', '--test-multi2'])
12
+ ]
13
+
14
+ @source = HammerCLI::Options::Sources::SavedDefaults.new(@defaults, @logger)
15
+ end
16
+
17
+ describe '#get_options' do
18
+ it 'logs message about loaded default value' do
19
+ @defaults.expects(:get_defaults).with('--test').returns(1)
20
+ @defaults.expects(:get_defaults).with('--test-multi1').returns(:first_value)
21
+
22
+ current_result = {}
23
+ expected_result = {
24
+ :different_attr_name => 1,
25
+ :multiple_switches_option => :first_value
26
+ }
27
+
28
+ @logger.expects(:info).with('Custom default value 1 was used for attribute --test')
29
+ @logger.expects(:info).with('Custom default value first_value was used for attribute --test-multi1')
30
+ @source.get_options(@defined_options, current_result)
31
+ end
32
+
33
+ it 'reads values for all switches' do
34
+ @defaults.expects(:get_defaults).with('--test').returns(1)
35
+ @defaults.expects(:get_defaults).with('--test-multi1').returns(nil)
36
+ @defaults.expects(:get_defaults).with('--test-multi2').returns(:second_value)
37
+
38
+ current_result = {}
39
+ expected_result = {
40
+ :different_attr_name => 1,
41
+ :multiple_switches_option => :second_value
42
+ }
43
+
44
+ assert_equal(expected_result, @source.get_options(@defined_options, current_result))
45
+ end
46
+
47
+ it 'keeps options that are already set' do
48
+ @defaults.expects(:get_defaults).with('--test-multi1').returns(2)
49
+
50
+ current_result = {:different_attr_name => :existing_value}
51
+ expected_result = {
52
+ :different_attr_name => :existing_value,
53
+ :multiple_switches_option => 2
54
+ }
55
+
56
+ assert_equal(expected_result, @source.get_options(@defined_options, current_result))
57
+ end
58
+ end
59
+ end
@@ -322,33 +322,6 @@ describe HammerCLI::Output::Adapter::Table do
322
322
  end
323
323
 
324
324
  end
325
-
326
- context "sort_columns" do
327
- let(:fields) {
328
- [field_firstname, field_lastname]
329
- }
330
-
331
- it "should sort output" do
332
-
333
- table_print_output = [
334
- "LASTNAME | FIRSTNAME",
335
- "---------|----------",
336
- "Doe | John "
337
- ].join("\n")
338
-
339
- expected_output = [
340
- "----------|---------",
341
- "FIRSTNAME | LASTNAME",
342
- "----------|---------",
343
- "John | Doe ",
344
- "----------|---------",
345
- ""
346
- ].join("\n")
347
-
348
- TablePrint::Printer.any_instance.stubs(:table_print).returns(table_print_output)
349
- proc { adapter.print_collection(fields, data) }.must_output(expected_output)
350
- end
351
- end
352
325
  end
353
326
 
354
327
  end
File without changes
@@ -166,22 +166,25 @@ describe Fields::Label do
166
166
  end
167
167
  end
168
168
 
169
- it "returns true when all the keys are present" do
169
+ it "returns true when all subfields are displayed" do
170
170
  field.display?({:a => 1, :b => 2}).must_equal true
171
171
  end
172
172
 
173
- it "returns true when some of the keys are present" do
173
+ it "returns true when at least one or the subfields is displayed" do
174
174
  field.display?({:a => 1}).must_equal true
175
175
  end
176
176
 
177
- it "returns false when there are some displayed subfields" do
178
- field.display?({}).must_equal false
177
+ it "returns false when none of the subfieldsis displayed" do
178
+ field.display?({:c => 3}).must_equal false
179
179
  end
180
180
 
181
- it "returns false the hash does not contain the required keys" do
182
- field.display?({:c => 3}).must_equal false
181
+ it "returns false when the value is empty hash" do
182
+ field.display?({}).must_equal false
183
183
  end
184
184
 
185
+ it "returns false when the value is nil" do
186
+ field.display?(nil).must_equal false
187
+ end
185
188
  end
186
189
 
187
190
  end
@@ -1,11 +1,5 @@
1
1
  require File.join(File.dirname(__FILE__), 'test_helper')
2
2
 
3
-
4
- # describe HammerCLI::OptionValidator do
5
-
6
-
7
- # end
8
-
9
3
  describe "constraints" do
10
4
 
11
5
  class FakeCmd < Clamp::Command