hammer_cli 0.11.0 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (203) hide show
  1. checksums.yaml +4 -4
  2. data/bin/hammer +4 -9
  3. data/config/cli_config.template.yml +12 -6
  4. data/doc/creating_commands.md +38 -0
  5. data/doc/i18n.md +33 -2
  6. data/doc/option_normalizers.md +2 -0
  7. data/doc/release_notes.md +18 -0
  8. data/lib/hammer_cli/abstract.rb +7 -2
  9. data/lib/hammer_cli/apipie/option_builder.rb +1 -1
  10. data/lib/hammer_cli/ca_cert_fetcher.rb +8 -8
  11. data/lib/hammer_cli/clamp.rb +9 -9
  12. data/lib/hammer_cli/context.rb +2 -1
  13. data/lib/hammer_cli/defaults.rb +12 -14
  14. data/lib/hammer_cli/defaults_commands.rb +2 -2
  15. data/lib/hammer_cli/exception_handler.rb +1 -1
  16. data/lib/hammer_cli/help/builder.rb +2 -1
  17. data/lib/hammer_cli/i18n/find_task.rb +41 -0
  18. data/lib/hammer_cli/i18n.rb +4 -0
  19. data/lib/hammer_cli/logger.rb +1 -1
  20. data/lib/hammer_cli/main.rb +12 -11
  21. data/lib/hammer_cli/modules.rb +5 -8
  22. data/lib/hammer_cli/options/normalizers.rb +15 -11
  23. data/lib/hammer_cli/options/option_collector.rb +17 -3
  24. data/lib/hammer_cli/options/option_definition.rb +36 -21
  25. data/lib/hammer_cli/output/adapter/csv.rb +1 -1
  26. data/lib/hammer_cli/output/adapter/table.rb +8 -6
  27. data/lib/hammer_cli/settings.rb +1 -6
  28. data/lib/hammer_cli/shell.rb +2 -2
  29. data/lib/hammer_cli/ssloptions.rb +5 -5
  30. data/lib/hammer_cli/subcommand.rb +51 -26
  31. data/lib/hammer_cli/testing/command_assertions.rb +2 -2
  32. data/lib/hammer_cli/testing/messages.rb +54 -0
  33. data/lib/hammer_cli/validator.rb +9 -9
  34. data/lib/hammer_cli/version.rb +1 -1
  35. data/locale/ca/LC_MESSAGES/hammer-cli.mo +0 -0
  36. data/locale/de/LC_MESSAGES/hammer-cli.mo +0 -0
  37. data/locale/en/LC_MESSAGES/hammer-cli.mo +0 -0
  38. data/locale/en_GB/LC_MESSAGES/hammer-cli.mo +0 -0
  39. data/locale/es/LC_MESSAGES/hammer-cli.mo +0 -0
  40. data/locale/fr/LC_MESSAGES/hammer-cli.mo +0 -0
  41. data/locale/it/LC_MESSAGES/hammer-cli.mo +0 -0
  42. data/locale/ja/LC_MESSAGES/hammer-cli.mo +0 -0
  43. data/locale/ko/LC_MESSAGES/hammer-cli.mo +0 -0
  44. data/locale/pt_BR/LC_MESSAGES/hammer-cli.mo +0 -0
  45. data/locale/ru/LC_MESSAGES/hammer-cli.mo +0 -0
  46. data/locale/zh_CN/LC_MESSAGES/hammer-cli.mo +0 -0
  47. data/locale/zh_TW/LC_MESSAGES/hammer-cli.mo +0 -0
  48. data/man/hammer.1.gz +0 -0
  49. data/test/functional/defaults_test.rb +3 -12
  50. data/test/functional/help_test.rb +1 -1
  51. data/test/functional/nil_values_test.rb +75 -0
  52. data/test/functional/test_helper.rb +10 -0
  53. data/test/reports/TEST-Fields-ContainerField-display-.xml +7 -0
  54. data/test/reports/TEST-Fields-ContainerField-display-blank-is-allowed.xml +15 -0
  55. data/test/reports/TEST-Fields-ContainerField-display-blank-is-not-allowed.xml +15 -0
  56. data/test/reports/TEST-Fields-ContainerField.xml +7 -0
  57. data/test/reports/TEST-Fields-Field-display-.xml +7 -0
  58. data/test/reports/TEST-Fields-Field-display-blank-is-allowed.xml +11 -0
  59. data/test/reports/TEST-Fields-Field-display-blank-is-not-allowed.xml +11 -0
  60. data/test/reports/TEST-Fields-Field-hide-blank-.xml +11 -0
  61. data/test/reports/TEST-Fields-Field-parameters.xml +9 -0
  62. data/test/reports/TEST-Fields-Field.xml +13 -0
  63. data/test/reports/TEST-HammerCLI-AbstractCommand-build-options.xml +15 -0
  64. data/test/reports/TEST-HammerCLI-AbstractCommand-exception-handler.xml +13 -0
  65. data/test/reports/TEST-HammerCLI-AbstractCommand-logging.xml +21 -0
  66. data/test/reports/TEST-HammerCLI-AbstractCommand-option-builder.xml +11 -0
  67. data/test/reports/TEST-HammerCLI-AbstractCommand-options.xml +11 -0
  68. data/test/reports/TEST-HammerCLI-AbstractCommand-output.xml +19 -0
  69. data/test/reports/TEST-HammerCLI-AbstractCommand-subcommand-behavior-remove-subcommand.xml +11 -0
  70. data/test/reports/TEST-HammerCLI-AbstractCommand-subcommand-behavior-subcommand-.xml +13 -0
  71. data/test/reports/TEST-HammerCLI-AbstractCommand-subcommand-behavior-subcommand.xml +11 -0
  72. data/test/reports/TEST-HammerCLI-AbstractCommand-subcommand-behavior.xml +7 -0
  73. data/test/reports/TEST-HammerCLI-AbstractCommand.xml +11 -0
  74. data/test/reports/TEST-HammerCLI-Apipie-Command-options.xml +11 -0
  75. data/test/reports/TEST-HammerCLI-Apipie-Command-resource-defined.xml +9 -0
  76. data/test/reports/TEST-HammerCLI-Apipie-Command-setting-resources.xml +19 -0
  77. data/test/reports/TEST-HammerCLI-Apipie-Command.xml +9 -0
  78. data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder-aliasing-resources.xml +13 -0
  79. data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder-filtering-options.xml +15 -0
  80. data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder-required-options.xml +11 -0
  81. data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder-setting-correct-normalizers.xml +9 -0
  82. data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder-with-hash-params.xml +11 -0
  83. data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder-with-one-simple-param.xml +15 -0
  84. data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder.xml +7 -0
  85. data/test/reports/TEST-HammerCLI-Completer-command-completion.xml +29 -0
  86. data/test/reports/TEST-HammerCLI-Completer-option-value-completion.xml +17 -0
  87. data/test/reports/TEST-HammerCLI-Completer-subcommand-completion.xml +19 -0
  88. data/test/reports/TEST-HammerCLI-Completer.xml +7 -0
  89. data/test/reports/TEST-HammerCLI-CompleterLine-line-complete.xml +25 -0
  90. data/test/reports/TEST-HammerCLI-CompleterLine-splitting-words.xml +29 -0
  91. data/test/reports/TEST-HammerCLI-CompleterLine.xml +7 -0
  92. data/test/reports/TEST-HammerCLI-CompleterWord-complete-.xml +23 -0
  93. data/test/reports/TEST-HammerCLI-CompleterWord-quote.xml +15 -0
  94. data/test/reports/TEST-HammerCLI-CompleterWord-quoted-.xml +13 -0
  95. data/test/reports/TEST-HammerCLI-CompleterWord.xml +7 -0
  96. data/test/reports/TEST-HammerCLI-Connection.xml +21 -0
  97. data/test/reports/TEST-HammerCLI-ExceptionHandler.xml +21 -0
  98. data/test/reports/TEST-HammerCLI-I18n.xml +11 -0
  99. data/test/reports/TEST-HammerCLI-MainCommand-loading-context-password.xml +11 -0
  100. data/test/reports/TEST-HammerCLI-MainCommand-loading-context-username.xml +11 -0
  101. data/test/reports/TEST-HammerCLI-MainCommand-loading-context-verbose.xml +9 -0
  102. data/test/reports/TEST-HammerCLI-MainCommand-loading-context.xml +7 -0
  103. data/test/reports/TEST-HammerCLI-MainCommand.xml +7 -0
  104. data/test/reports/TEST-HammerCLI-Modules-find-by-name.xml +13 -0
  105. data/test/reports/TEST-HammerCLI-Modules-load-a-module-module-not-found.xml +13 -0
  106. data/test/reports/TEST-HammerCLI-Modules-load-a-module-module-runtime-exception.xml +13 -0
  107. data/test/reports/TEST-HammerCLI-Modules-load-a-module-success.xml +15 -0
  108. data/test/reports/TEST-HammerCLI-Modules-load-a-module.xml +7 -0
  109. data/test/reports/TEST-HammerCLI-Modules-load-all-modules.xml +9 -0
  110. data/test/reports/TEST-HammerCLI-Modules-names.xml +13 -0
  111. data/test/reports/TEST-HammerCLI-Modules.xml +7 -0
  112. data/test/reports/TEST-HammerCLI-OptionBuilderContainer.0.xml +7 -0
  113. data/test/reports/TEST-HammerCLI-OptionBuilderContainer.xml +11 -0
  114. data/test/reports/TEST-HammerCLI-Options-Normalizers-abstract.xml +9 -0
  115. data/test/reports/TEST-HammerCLI-Options-Normalizers-bool.xml +31 -0
  116. data/test/reports/TEST-HammerCLI-Options-Normalizers-datetime.xml +17 -0
  117. data/test/reports/TEST-HammerCLI-Options-Normalizers-enum.xml +15 -0
  118. data/test/reports/TEST-HammerCLI-Options-Normalizers-enumlist.xml +21 -0
  119. data/test/reports/TEST-HammerCLI-Options-Normalizers-json-input.xml +15 -0
  120. data/test/reports/TEST-HammerCLI-Options-Normalizers-key-value-list.xml +17 -0
  121. data/test/reports/TEST-HammerCLI-Options-Normalizers-list.xml +15 -0
  122. data/test/reports/TEST-HammerCLI-Options-Normalizers.xml +7 -0
  123. data/test/reports/TEST-HammerCLI-Options-OptionDefinition-context.xml +9 -0
  124. data/test/reports/TEST-HammerCLI-Options-OptionDefinition-formatters.xml +11 -0
  125. data/test/reports/TEST-HammerCLI-Options-OptionDefinition.xml +7 -0
  126. data/test/reports/TEST-HammerCLI-Output-Adapter-Abstract-error-messages.xml +15 -0
  127. data/test/reports/TEST-HammerCLI-Output-Adapter-Abstract-messages.xml +11 -0
  128. data/test/reports/TEST-HammerCLI-Output-Adapter-Abstract-test-data-for-field.xml +15 -0
  129. data/test/reports/TEST-HammerCLI-Output-Adapter-Abstract.xml +17 -0
  130. data/test/reports/TEST-HammerCLI-Output-Adapter-Base-print-collection-show-ids.xml +9 -0
  131. data/test/reports/TEST-HammerCLI-Output-Adapter-Base-print-collection.xml +27 -0
  132. data/test/reports/TEST-HammerCLI-Output-Adapter-Base.xml +7 -0
  133. data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues-print-collection-formatters.xml +11 -0
  134. data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues-print-collection-handle-fields-with-collections.xml +13 -0
  135. data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues-print-collection-handle-fields-with-containers.xml +11 -0
  136. data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues-print-collection-handle-ids.xml +11 -0
  137. data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues-print-collection.xml +11 -0
  138. data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues-print-message.xml +11 -0
  139. data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues.xml +7 -0
  140. data/test/reports/TEST-HammerCLI-Output-Adapter-Table-print-collection-column-width.xml +15 -0
  141. data/test/reports/TEST-HammerCLI-Output-Adapter-Table-print-collection-formatters.xml +11 -0
  142. data/test/reports/TEST-HammerCLI-Output-Adapter-Table-print-collection-handle-ids.xml +11 -0
  143. data/test/reports/TEST-HammerCLI-Output-Adapter-Table-print-collection-sort-columns.xml +9 -0
  144. data/test/reports/TEST-HammerCLI-Output-Adapter-Table-print-collection.xml +11 -0
  145. data/test/reports/TEST-HammerCLI-Output-Adapter-Table.xml +7 -0
  146. data/test/reports/TEST-HammerCLI-Output-Definition-empty-.xml +11 -0
  147. data/test/reports/TEST-HammerCLI-Output-Definition.xml +11 -0
  148. data/test/reports/TEST-HammerCLI-Output-Dsl-collection.xml +13 -0
  149. data/test/reports/TEST-HammerCLI-Output-Dsl-custom-fields.xml +11 -0
  150. data/test/reports/TEST-HammerCLI-Output-Dsl-fields.xml +15 -0
  151. data/test/reports/TEST-HammerCLI-Output-Dsl-label.xml +13 -0
  152. data/test/reports/TEST-HammerCLI-Output-Dsl-path-definition.xml +13 -0
  153. data/test/reports/TEST-HammerCLI-Output-Dsl.xml +9 -0
  154. data/test/reports/TEST-HammerCLI-Output-FieldFilter.xml +13 -0
  155. data/test/reports/TEST-HammerCLI-Output-Formatters-BooleanFormatter.xml +11 -0
  156. data/test/reports/TEST-HammerCLI-Output-Formatters-ColorFormatter.xml +9 -0
  157. data/test/reports/TEST-HammerCLI-Output-Formatters-DateFormatter.xml +11 -0
  158. data/test/reports/TEST-HammerCLI-Output-Formatters-FieldFormatter.xml +13 -0
  159. data/test/reports/TEST-HammerCLI-Output-Formatters-FormatterContainer.xml +13 -0
  160. data/test/reports/TEST-HammerCLI-Output-Formatters-FormatterLibrary.xml +11 -0
  161. data/test/reports/TEST-HammerCLI-Output-Formatters-KeyValueFormatter.xml +13 -0
  162. data/test/reports/TEST-HammerCLI-Output-Formatters-ListFormatter.xml +13 -0
  163. data/test/reports/TEST-HammerCLI-Output-Formatters-LongTextFormatter.xml +13 -0
  164. data/test/reports/TEST-HammerCLI-Output-Output-adapters.xml +17 -0
  165. data/test/reports/TEST-HammerCLI-Output-Output-data.xml +15 -0
  166. data/test/reports/TEST-HammerCLI-Output-Output-formatters.xml +9 -0
  167. data/test/reports/TEST-HammerCLI-Output-Output-messages.xml +19 -0
  168. data/test/reports/TEST-HammerCLI-Output-Output.xml +7 -0
  169. data/test/reports/TEST-HammerCLI-Output-RecordCollection.xml +13 -0
  170. data/test/reports/TEST-HammerCLI-Settings-load-from-paths.xml +15 -0
  171. data/test/reports/TEST-HammerCLI-Settings.xml +25 -0
  172. data/test/reports/TEST-HammerCLI-ShellHistory-loading-old-history.xml +11 -0
  173. data/test/reports/TEST-HammerCLI-ShellHistory-saving-history.xml +15 -0
  174. data/test/reports/TEST-HammerCLI-ShellHistory.xml +7 -0
  175. data/test/reports/TEST-MiniTest-Spec.xml +7 -0
  176. data/test/reports/TEST-String-camelize.xml +11 -0
  177. data/test/reports/TEST-String-formatting.xml +17 -0
  178. data/test/reports/TEST-String-indent.xml +11 -0
  179. data/test/reports/TEST-String-interactive-.xml +13 -0
  180. data/test/reports/TEST-String.xml +7 -0
  181. data/test/reports/TEST-constraints-HammerCLI-Validator-AllConstraint-exist-.xml +13 -0
  182. data/test/reports/TEST-constraints-HammerCLI-Validator-AllConstraint.xml +7 -0
  183. data/test/reports/TEST-constraints-HammerCLI-Validator-AnyConstraint-exist-.xml +13 -0
  184. data/test/reports/TEST-constraints-HammerCLI-Validator-AnyConstraint.xml +7 -0
  185. data/test/reports/TEST-constraints-HammerCLI-Validator-BaseConstraint-exist-.xml +9 -0
  186. data/test/reports/TEST-constraints-HammerCLI-Validator-BaseConstraint-rejected.xml +13 -0
  187. data/test/reports/TEST-constraints-HammerCLI-Validator-BaseConstraint-required.xml +13 -0
  188. data/test/reports/TEST-constraints-HammerCLI-Validator-BaseConstraint.xml +7 -0
  189. data/test/reports/TEST-constraints.xml +7 -0
  190. data/test/unit/abstract_test.rb +10 -1
  191. data/test/unit/apipie/option_builder_test.rb +6 -0
  192. data/test/unit/defaults_test.rb +12 -5
  193. data/test/unit/exception_handler_test.rb +1 -1
  194. data/test/unit/fixtures/apipie/documented.json +10 -1
  195. data/test/unit/help/builder_test.rb +16 -1
  196. data/test/unit/messages_test.rb +7 -0
  197. data/test/unit/modules_test.rb +4 -15
  198. data/test/unit/options/normalizers_test.rb +21 -1
  199. data/test/unit/options/option_collector_test.rb +10 -4
  200. data/test/unit/output/adapter/csv_test.rb +29 -0
  201. data/test/unit/output/adapter/table_test.rb +27 -0
  202. data/test/unit/validator_test.rb +4 -4
  203. metadata +353 -53
@@ -0,0 +1,11 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="HammerCLI::ShellHistory::loading old history" tests="2" time="0.000591805" failures="0" errors="0" skipped="0" assertions="2">
3
+ <testcase name="test_0001_skips loading if the file does not exist" time="0.000228018" assertions="1">
4
+ </testcase>
5
+ <testcase name="test_0002_preseeds readline's history" time="0.000185292" assertions="1">
6
+ </testcase>
7
+ <system-out>
8
+ </system-out>
9
+ <system-err>
10
+ </system-err>
11
+ </testsuite>
@@ -0,0 +1,15 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="HammerCLI::ShellHistory::saving history" tests="4" time="0.000956469" failures="0" errors="0" skipped="0" assertions="4">
3
+ <testcase name="test_0001_creates history file if it does not exist" time="0.00022899" assertions="1">
4
+ </testcase>
5
+ <testcase name="test_0003_appends to readline's history" time="0.000185984" assertions="1">
6
+ </testcase>
7
+ <testcase name="test_0002_appends history to the given file" time="0.000169983" assertions="1">
8
+ </testcase>
9
+ <testcase name="test_0004_doesn't save exit command" time="0.000154798" assertions="1">
10
+ </testcase>
11
+ <system-out>
12
+ </system-out>
13
+ <system-err>
14
+ </system-err>
15
+ </testsuite>
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="HammerCLI::ShellHistory" tests="0" time="0.000162977" failures="0" errors="0" skipped="0" assertions="0">
3
+ <system-out>
4
+ </system-out>
5
+ <system-err>
6
+ </system-err>
7
+ </testsuite>
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="MiniTest::Spec" tests="0" time="0.000174231" failures="0" errors="0" skipped="0" assertions="0">
3
+ <system-out>
4
+ </system-out>
5
+ <system-err>
6
+ </system-err>
7
+ </testsuite>
@@ -0,0 +1,11 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="String::camelize" tests="2" time="0.000337952" failures="0" errors="0" skipped="0" assertions="2">
3
+ <testcase name="test_0001_should camelize string with underscores" time="0.0001091" assertions="1">
4
+ </testcase>
5
+ <testcase name="test_0002_should not camelize string with dashes" time="5.1678e-05" assertions="1">
6
+ </testcase>
7
+ <system-out>
8
+ </system-out>
9
+ <system-err>
10
+ </system-err>
11
+ </testsuite>
@@ -0,0 +1,17 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="String::formatting" tests="5" time="0.00052804" failures="0" errors="0" skipped="0" assertions="5">
3
+ <testcase name="test_0003_should replace named parameters" time="0.000120653" assertions="1">
4
+ </testcase>
5
+ <testcase name="test_0002_should replace positional parameters" time="5.0694e-05" assertions="1">
6
+ </testcase>
7
+ <testcase name="test_0004_should replace named parameters with string keys" time="5.4219e-05" assertions="1">
8
+ </testcase>
9
+ <testcase name="test_0005_should replace named parameters marked with curly brackets" time="5.3821e-05" assertions="1">
10
+ </testcase>
11
+ <testcase name="test_0001_should not fail without expected parameters" time="5.197e-05" assertions="1">
12
+ </testcase>
13
+ <system-out>
14
+ </system-out>
15
+ <system-err>
16
+ </system-err>
17
+ </testsuite>
@@ -0,0 +1,11 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="String::indent" tests="2" time="0.000342954" failures="0" errors="0" skipped="0" assertions="2">
3
+ <testcase name="test_0002_indents multi line string" time="0.000108296" assertions="1">
4
+ </testcase>
5
+ <testcase name="test_0001_indents single line string" time="4.4031e-05" assertions="1">
6
+ </testcase>
7
+ <system-out>
8
+ </system-out>
9
+ <system-err>
10
+ </system-err>
11
+ </testsuite>
@@ -0,0 +1,13 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="String::interactive?" tests="3" time="0.001375686" failures="0" errors="0" skipped="0" assertions="3">
3
+ <testcase name="test_0001_should be true when called in tty" time="0.00042329" assertions="1">
4
+ </testcase>
5
+ <testcase name="test_0002_should by false when cli arg set" time="0.000403856" assertions="1">
6
+ </testcase>
7
+ <testcase name="test_0003_should by false when turned off in cfg" time="0.000364321" assertions="1">
8
+ </testcase>
9
+ <system-out>
10
+ </system-out>
11
+ <system-err>
12
+ </system-err>
13
+ </testsuite>
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="String" tests="0" time="0.000181729" failures="0" errors="0" skipped="0" assertions="0">
3
+ <system-out>
4
+ </system-out>
5
+ <system-err>
6
+ </system-err>
7
+ </testsuite>
@@ -0,0 +1,13 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="constraints::HammerCLI::Validator::AllConstraint::exist?" tests="3" time="0.000590622" failures="0" errors="0" skipped="0" assertions="3">
3
+ <testcase name="test_0002_should return true when all the options exist" time="0.000196018" assertions="1">
4
+ </testcase>
5
+ <testcase name="test_0001_should return true when no options are passed" time="0.000113036" assertions="1">
6
+ </testcase>
7
+ <testcase name="test_0003_should return false when one of the options is missing" time="9.6605e-05" assertions="1">
8
+ </testcase>
9
+ <system-out>
10
+ </system-out>
11
+ <system-err>
12
+ </system-err>
13
+ </testsuite>
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="constraints::HammerCLI::Validator::AllConstraint" tests="0" time="0.00015489" failures="0" errors="0" skipped="0" assertions="0">
3
+ <system-out>
4
+ </system-out>
5
+ <system-err>
6
+ </system-err>
7
+ </testsuite>
@@ -0,0 +1,13 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="constraints::HammerCLI::Validator::AnyConstraint::exist?" tests="3" time="0.000586351" failures="0" errors="0" skipped="0" assertions="3">
3
+ <testcase name="test_0002_should return true when one of the options exist" time="0.000170553" assertions="1">
4
+ </testcase>
5
+ <testcase name="test_0001_should return true when no options are passed" time="0.000112862" assertions="1">
6
+ </testcase>
7
+ <testcase name="test_0003_should return false when all the options are missing" time="0.000111747" assertions="1">
8
+ </testcase>
9
+ <system-out>
10
+ </system-out>
11
+ <system-err>
12
+ </system-err>
13
+ </testsuite>
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="constraints::HammerCLI::Validator::AnyConstraint" tests="0" time="0.00017756" failures="0" errors="0" skipped="0" assertions="0">
3
+ <system-out>
4
+ </system-out>
5
+ <system-err>
6
+ </system-err>
7
+ </testsuite>
@@ -0,0 +1,9 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="constraints::HammerCLI::Validator::BaseConstraint::exist?" tests="1" time="0.000343672" failures="0" errors="0" skipped="0" assertions="1">
3
+ <testcase name="test_0001_throws not implemented error" time="0.000171895" assertions="1">
4
+ </testcase>
5
+ <system-out>
6
+ </system-out>
7
+ <system-err>
8
+ </system-err>
9
+ </testsuite>
@@ -0,0 +1,13 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="constraints::HammerCLI::Validator::BaseConstraint::rejected" tests="3" time="0.001188178" failures="0" errors="0" skipped="0" assertions="3">
3
+ <testcase name="test_0003_should return nil when exist? returns true" time="0.000339906" assertions="1">
4
+ </testcase>
5
+ <testcase name="test_0002_should raise exception with a message" time="0.000330188" assertions="1">
6
+ </testcase>
7
+ <testcase name="test_0001_should raise exception when exist? returns true" time="0.000327038" assertions="1">
8
+ </testcase>
9
+ <system-out>
10
+ </system-out>
11
+ <system-err>
12
+ </system-err>
13
+ </testsuite>
@@ -0,0 +1,13 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="constraints::HammerCLI::Validator::BaseConstraint::required" tests="3" time="0.001221194" failures="0" errors="0" skipped="0" assertions="2">
3
+ <testcase name="test_0003_should return nil when exist? returns true" time="0.000335162" assertions="1">
4
+ </testcase>
5
+ <testcase name="test_0001_should raise exception when exist? returns true" time="0.000327945" assertions="1">
6
+ </testcase>
7
+ <testcase name="test_0002_should raise exception with a message" time="0.000337518" assertions="0">
8
+ </testcase>
9
+ <system-out>
10
+ </system-out>
11
+ <system-err>
12
+ </system-err>
13
+ </testsuite>
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="constraints::HammerCLI::Validator::BaseConstraint" tests="0" time="0.000163178" failures="0" errors="0" skipped="0" assertions="0">
3
+ <system-out>
4
+ </system-out>
5
+ <system-err>
6
+ </system-err>
7
+ </testsuite>
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="constraints" tests="0" time="0.000161677" failures="0" errors="0" skipped="0" assertions="0">
3
+ <system-out>
4
+ </system-out>
5
+ <system-err>
6
+ </system-err>
7
+ </testsuite>
@@ -1,7 +1,6 @@
1
1
  require File.join(File.dirname(__FILE__), 'test_helper')
2
2
  require 'tempfile'
3
3
 
4
-
5
4
  describe HammerCLI::AbstractCommand do
6
5
 
7
6
  context "output" do
@@ -285,6 +284,16 @@ describe HammerCLI::AbstractCommand do
285
284
 
286
285
  end
287
286
 
287
+ describe "#options" do
288
+ class TestOptionSourceCommand < HammerCLI::AbstractCommand;end
289
+
290
+ it "allows overriding option sources in a command" do
291
+ cmd = TestOptionSourceCommand.new('')
292
+ cmd.expects(:option_sources).returns([])
293
+ cmd.send(:all_options)
294
+ end
295
+ end
296
+
288
297
  describe "option builder" do
289
298
 
290
299
  it "uses builder container as default" do
@@ -97,6 +97,12 @@ describe HammerCLI::Apipie::OptionBuilder do
97
97
  numeric_option = options.find {|o| o.attribute_name == HammerCLI.option_accessor_name("numeric_param") }
98
98
  numeric_option.value_formatter.class.must_equal HammerCLI::Options::Normalizers::Number
99
99
  end
100
+
101
+ it "should set number normalizer for integer" do
102
+ integer_option = options.find {|o| o.attribute_name == HammerCLI.option_accessor_name("integer_param") }
103
+ integer_option.value_formatter.class.must_equal HammerCLI::Options::Normalizers::Number
104
+ end
105
+
100
106
  end
101
107
 
102
108
 
@@ -13,12 +13,19 @@ describe HammerCLI::Defaults do
13
13
  describe '#add_defaults_to_conf' do
14
14
  it "Should add a default param to defaults file, without a provider" do
15
15
  defaults_result = @defaults.add_defaults_to_conf({"organization_id"=> 3}, nil)
16
- assert_equal 3, defaults_result[:defaults][:organization_id][:value]
16
+ assert_equal '3', defaults_result[:defaults][:organization_id][:value]
17
+ end
18
+
19
+ it "adds values from hammer shell" do
20
+ key = HammerCLI::CompleterWord.new("organization_id")
21
+ value = HammerCLI::CompleterWord.new("3")
22
+ defaults_result = @defaults.add_defaults_to_conf({ key => value }, nil)
23
+ assert_equal '3', defaults_result[:defaults][:organization_id][:value]
17
24
  end
18
25
 
19
26
  it "Should update dashed default when underscored default is set" do
20
27
  defaults_result = @defaults.add_defaults_to_conf({"location-id"=> 3}, nil)
21
- assert_equal 3, defaults_result[:defaults][:'location-id'][:value]
28
+ assert_equal '3', defaults_result[:defaults][:'location-id'][:value]
22
29
  assert_equal nil, defaults_result[:defaults][:location_id]
23
30
  end
24
31
 
@@ -26,20 +33,20 @@ describe HammerCLI::Defaults do
26
33
  let(:filepath) { File.join(File.dirname(__FILE__), '/fixtures/defaults/defaults_dashed.yml') }
27
34
  it "Should update underscored default when dashed default is set" do
28
35
  defaults_result = @defaults.add_defaults_to_conf({"location_id"=> 3}, nil)
29
- assert_equal 3, defaults_result[:defaults][:location_id][:value]
36
+ assert_equal '3', defaults_result[:defaults][:location_id][:value]
30
37
  assert_equal nil, defaults_result[:defaults][:'location-id']
31
38
  end
32
39
 
33
40
  it "should update underscored default with option syntax when dashed default is set" do
34
41
  defaults_result = @defaults.add_defaults_to_conf({"--location-id"=> 3}, nil)
35
- assert_equal 3, defaults_result[:defaults][:'location-id'][:value]
42
+ assert_equal '3', defaults_result[:defaults][:'location-id'][:value]
36
43
  assert_equal nil, defaults_result[:defaults][:location_id]
37
44
  end
38
45
  end
39
46
 
40
47
  it "Should add a default param to defaults file, with provider" do
41
48
  defaults_result = @defaults.add_defaults_to_conf({"location_id"=>nil}, :foreman)
42
- assert_equal :foreman, defaults_result[:defaults][:location_id][:provider]
49
+ assert_equal 'foreman', defaults_result[:defaults][:location_id][:provider]
43
50
  end
44
51
  end
45
52
 
@@ -36,7 +36,7 @@ describe HammerCLI::ExceptionHandler do
36
36
  end
37
37
 
38
38
  it "should handle usage error" do
39
- output.expects(:print_error).with(heading, "Error: wrong_usage\n\nSee: 'command_name --help'")
39
+ output.expects(:print_error).with(heading, "Error: wrong_usage\n\nSee: 'command_name --help'.")
40
40
  handler.handle_exception(Clamp::UsageError.new('wrong_usage', cmd), :heading => heading)
41
41
 
42
42
  end
@@ -162,7 +162,16 @@
162
162
  "allow_null": false,
163
163
  "full_name": "documented[numeric_param]",
164
164
  "validator": "Must be Number",
165
- "expected_type": "number",
165
+ "expected_type": "numeric",
166
+ "description": "",
167
+ "required": false
168
+ },
169
+ {
170
+ "name": "integer_param",
171
+ "allow_null": false,
172
+ "full_name": "documented[numeric_param]",
173
+ "validator": "Integer",
174
+ "expected_type": "numeric",
166
175
  "description": "",
167
176
  "required": false
168
177
  }
@@ -23,6 +23,22 @@ describe HammerCLI::Help::Builder do
23
23
  end
24
24
  end
25
25
 
26
+ describe 'adding an option with lower case description' do
27
+ it 'capitalizes the description' do
28
+ options = [
29
+ Clamp::Option::Definition.new(['--alpha-option'], 'OPT_ALPHA', 'alpha description'),
30
+ Clamp::Option::Definition.new(['--beta-option'], 'OPT_BETA', 'BETA description')
31
+ ]
32
+ help.add_list('Options',options)
33
+
34
+ help.string.strip.must_equal [
35
+ 'Options:',
36
+ ' --alpha-option OPT_ALPHA Alpha description',
37
+ ' --beta-option OPT_BETA BETA description'
38
+ ].join("\n")
39
+ end
40
+ end
41
+
26
42
  describe 'adding text' do
27
43
  let(:content_1) {[
28
44
  'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
@@ -54,4 +70,3 @@ describe HammerCLI::Help::Builder do
54
70
  end
55
71
  end
56
72
  end
57
-
@@ -0,0 +1,7 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+ require 'hammer_cli/testing/messages'
3
+
4
+ include HammerCLI::Testing::Messages
5
+ describe "message formatting" do
6
+ check_all_command_messages(HammerCLI::MainCommand)
7
+ end
@@ -35,16 +35,6 @@ describe HammerCLI::Modules do
35
35
  HammerCLI::Settings.clear
36
36
  HammerCLI::Modules.names.must_equal []
37
37
  end
38
-
39
- it "must work with old modules config" do
40
- HammerCLI::Settings.clear
41
- HammerCLI::Settings.load({
42
- :tom => {},
43
- :modules => ['hammer_cli_tom', 'hammer_cli_jerry'],
44
- })
45
- HammerCLI::Modules.names.must_equal ["hammer_cli_jerry", "hammer_cli_tom"]
46
- end
47
-
48
38
  end
49
39
 
50
40
  describe "find by name" do
@@ -95,7 +85,7 @@ describe HammerCLI::Modules do
95
85
  it "must log module's name and version" do
96
86
  HammerCLI::Modules.expects(:require_module).with("hammer_cli_tom")
97
87
  HammerCLI::Modules.load("hammer_cli_tom")
98
- @log_output.readline.strip.must_equal "INFO Modules : Extension module hammer_cli_tom (0.0.1) loaded"
88
+ @log_output.readline.strip.must_equal "INFO Modules : Extension module hammer_cli_tom (0.0.1) loaded."
99
89
  end
100
90
 
101
91
  it "must return true when load succeeds" do
@@ -110,7 +100,7 @@ describe HammerCLI::Modules do
110
100
  describe "module not found" do
111
101
  before :each do
112
102
  HammerCLI::Modules.stubs(:require_module).raises(LoadError)
113
- @error_msg = "ERROR Modules : Error while loading module hammer_cli_tom"
103
+ @error_msg = "ERROR Modules : Error while loading module hammer_cli_tom."
114
104
  end
115
105
 
116
106
  it "must log an error if the load! fails" do
@@ -137,8 +127,8 @@ describe HammerCLI::Modules do
137
127
  describe "module runtime exception" do
138
128
  before :each do
139
129
  HammerCLI::Modules.stubs(:require_module).raises(RuntimeError)
140
- @error_msg = "ERROR Modules : Error while loading module hammer_cli_tom"
141
- @warning_msg = "Warning: An error occured while loading module hammer_cli_tom"
130
+ @error_msg = "ERROR Modules : Error while loading module hammer_cli_tom."
131
+ @warning_msg = "Warning: An error occured while loading module hammer_cli_tom."
142
132
  end
143
133
 
144
134
  it "must log an error if the load! fails" do
@@ -167,4 +157,3 @@ describe HammerCLI::Modules do
167
157
  end
168
158
 
169
159
  end
170
-
@@ -3,7 +3,6 @@ require File.join(File.dirname(__FILE__), '../test_helper')
3
3
 
4
4
  describe HammerCLI::Options::Normalizers do
5
5
 
6
-
7
6
  describe 'abstract' do
8
7
 
9
8
  let(:formatter) { HammerCLI::Options::Normalizers::AbstractNormalizer.new }
@@ -14,6 +13,27 @@ describe HammerCLI::Options::Normalizers do
14
13
 
15
14
  end
16
15
 
16
+ describe 'default' do
17
+
18
+ let(:formatter) { HammerCLI::Options::Normalizers::Default.new }
19
+
20
+ it "should not change any value" do
21
+ formatter.format('value').must_equal 'value'
22
+ end
23
+
24
+ it "should not change nil value" do
25
+ formatter.format(nil).must_be_nil
26
+ end
27
+
28
+ it "has empty description" do
29
+ formatter.description.must_equal ''
30
+ end
31
+
32
+ it "has empty completion" do
33
+ formatter.complete('test').must_equal []
34
+ end
35
+ end
36
+
17
37
  describe 'list' do
18
38
 
19
39
  let(:formatter) { HammerCLI::Options::Normalizers::List.new }
@@ -3,7 +3,7 @@ require_relative '../test_helper'
3
3
  describe HammerCLI::Options::OptionCollector do
4
4
  before do
5
5
  recognised_options = [mock, mock]
6
- source1_result = {:option1 => 1, :option2 => nil}
6
+ source1_result = {:option1 => 1, :option2 => nil, :option4 => HammerCLI::NilValue}
7
7
  source2_result = source1_result.merge({:option3 => 3})
8
8
 
9
9
  source1 = mock
@@ -16,14 +16,20 @@ describe HammerCLI::Options::OptionCollector do
16
16
  end
17
17
 
18
18
  describe '#options' do
19
- it 'returns options without nil values' do
20
- assert_equal({:option1 => 1, :option3 => 3}, @collector.options)
19
+ it 'returns options without nil values but with NIL values' do
20
+ assert_equal({:option1 => 1, :option3 => 3, :option4 => nil}, @collector.options)
21
21
  end
22
22
  end
23
23
 
24
24
  describe '#all_options' do
25
25
  it 'returns all options' do
26
- assert_equal({:option1 => 1, :option2 => nil, :option3 => 3}, @collector.all_options)
26
+ assert_equal({:option1 => 1, :option2 => nil, :option3 => 3, :option4 => nil}, @collector.all_options)
27
+ end
28
+ end
29
+
30
+ describe '#all_options_raw' do
31
+ it 'returns all options with NIL values untranslated' do
32
+ assert_equal({:option1 => 1, :option2 => nil, :option3 => 3, :option4 => HammerCLI::NilValue}, @collector.all_options_raw)
27
33
  end
28
34
  end
29
35
  end
@@ -55,6 +55,35 @@ describe HammerCLI::Output::Adapter::CSValues do
55
55
  end
56
56
  end
57
57
 
58
+ context "handle headers" do
59
+ let(:empty_data) { HammerCLI::Output::RecordCollection.new [] }
60
+
61
+ it "should print headers by default" do
62
+ out, err = capture_io { adapter.print_collection(fields, data) }
63
+ out.must_match(/.*Name.*/)
64
+ end
65
+
66
+ it "should print headers by default even if there is no data" do
67
+ out, err = capture_io { adapter.print_collection(fields, empty_data) }
68
+ out.must_match(/.*Name.*/)
69
+ end
70
+
71
+ it "should print data only when --no-headers is set" do
72
+ expected_output = [
73
+ "John Doe,2000",
74
+ "",
75
+ ].join("\n")
76
+ adapter = HammerCLI::Output::Adapter::CSValues.new( { :no_headers => true } )
77
+ proc { adapter.print_collection(fields, data) }.must_output(expected_output)
78
+ end
79
+
80
+ it "should print nothing when --no-headers is set but no data" do
81
+ expected_output = "\n"
82
+ adapter = HammerCLI::Output::Adapter::CSValues.new( { :no_headers => true } )
83
+ proc { adapter.print_collection(fields, empty_data) }.must_output(expected_output)
84
+ end
85
+ end
86
+
58
87
  context "handle fields with containers" do
59
88
  let(:demographics) {
60
89
  Fields::Label.new(:path => [], :label => "Demographics") do
@@ -96,6 +96,33 @@ describe HammerCLI::Output::Adapter::Table do
96
96
  end
97
97
  end
98
98
 
99
+ context "handle headers" do
100
+ it "should print headers by default" do
101
+ out, err = capture_io { adapter.print_collection(fields, data) }
102
+ out.must_match(/.*NAME.*/)
103
+ end
104
+
105
+ it "should print headers by default even if there is no data" do
106
+ out, err = capture_io { adapter.print_collection(fields, empty_data) }
107
+ out.must_match(/.*NAME.*/)
108
+ end
109
+
110
+ it "should print data only when --no-headers is set" do
111
+ expected_output = [
112
+ "John Doe",
113
+ "",
114
+ ].join("\n")
115
+ adapter = HammerCLI::Output::Adapter::Table.new( { :no_headers => true } )
116
+ proc { adapter.print_collection(fields, data) }.must_output(expected_output)
117
+ end
118
+
119
+ it "should print nothing when --no-headers is set but no data" do
120
+ expected_output = ""
121
+ adapter = HammerCLI::Output::Adapter::Table.new( { :no_headers => true } )
122
+ proc { adapter.print_collection(fields, empty_data) }.must_output(expected_output)
123
+ end
124
+ end
125
+
99
126
  context "column width" do
100
127
 
101
128
  it "calculates correct width of two-column characters" do
@@ -145,7 +145,7 @@ describe "constraints" do
145
145
  it "raises exception when the option is present" do
146
146
  constraint = cls.new(options, :option_a)
147
147
  e = proc{ constraint.rejected }.must_raise HammerCLI::Validator::ValidationError
148
- e.message.must_equal "You can't set option --option-a"
148
+ e.message.must_equal "You can't set option --option-a."
149
149
  end
150
150
  end
151
151
 
@@ -158,7 +158,7 @@ describe "constraints" do
158
158
  it "raises exception when the option is present" do
159
159
  constraint = cls.new(options, :option_unset_d)
160
160
  e = proc{ constraint.required }.must_raise HammerCLI::Validator::ValidationError
161
- e.message.must_equal 'Option --option-unset-d is required'
161
+ e.message.must_equal 'Option --option-unset-d is required.'
162
162
  end
163
163
  end
164
164
 
@@ -257,13 +257,13 @@ describe "constraints" do
257
257
  it "raises exception when none of the options is present" do
258
258
  constraint = cls.new(options, [:option_unset_d, :option_unset_e])
259
259
  e = proc{ constraint.required }.must_raise HammerCLI::Validator::ValidationError
260
- e.message.must_equal 'One of options --option-unset-d, --option-unset-e is required'
260
+ e.message.must_equal 'One of options --option-unset-d, --option-unset-e is required.'
261
261
  end
262
262
 
263
263
  it "raises exception when more than one of the options is present" do
264
264
  constraint = cls.new(options, [:option_a, :option_b])
265
265
  e = proc{ constraint.required }.must_raise HammerCLI::Validator::ValidationError
266
- e.message.must_equal 'Only one of options --option-a, --option-b can be set'
266
+ e.message.must_equal 'Only one of options --option-a, --option-b can be set.'
267
267
  end
268
268
  end
269
269
  end