hammer_cli 0.18.1 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/doc/creating_commands.md +2 -8
- data/doc/developer_docs.md +2 -0
- data/doc/help_modification.md +35 -4
- data/doc/output.md +43 -0
- data/doc/release_notes.md +6 -2
- data/doc/review_checklist.md +17 -0
- data/lib/hammer_cli/help/definition.rb +1 -0
- data/lib/hammer_cli/help/definition/abstract_item.rb +2 -1
- data/lib/hammer_cli/help/definition/list.rb +5 -2
- data/lib/hammer_cli/help/definition/note.rb +30 -0
- data/lib/hammer_cli/help/definition/section.rb +0 -1
- data/lib/hammer_cli/help/definition/text.rb +3 -1
- data/lib/hammer_cli/help/text_builder.rb +7 -2
- data/lib/hammer_cli/main.rb +2 -2
- data/lib/hammer_cli/output/adapter/abstract.rb +9 -3
- data/lib/hammer_cli/output/adapter/base.rb +4 -2
- data/lib/hammer_cli/output/adapter/csv.rb +4 -2
- data/lib/hammer_cli/output/adapter/table.rb +4 -2
- data/lib/hammer_cli/output/adapter/tree_structure.rb +4 -4
- data/lib/hammer_cli/output/fields.rb +3 -0
- data/lib/hammer_cli/output/formatters.rb +77 -27
- data/lib/hammer_cli/output/utils.rb +12 -1
- data/lib/hammer_cli/version.rb +1 -1
- data/locale/ca/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/de/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/en/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/en_GB/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/es/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/fr/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/it/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/ja/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/ko/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/pt_BR/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/ru/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/zh_CN/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/zh_TW/LC_MESSAGES/hammer-cli.mo +0 -0
- data/man/hammer.1.gz +0 -0
- data/test/reports/TEST-Fields-ContainerField-display-.xml +7 -0
- data/test/reports/TEST-Fields-ContainerField-display-blank-is-allowed.xml +15 -0
- data/test/reports/TEST-Fields-ContainerField-display-blank-is-not-allowed.xml +15 -0
- data/test/reports/TEST-Fields-ContainerField.xml +7 -0
- data/test/reports/TEST-Fields-Field-display-.xml +7 -0
- data/test/reports/TEST-Fields-Field-display-blank-is-allowed.xml +11 -0
- data/test/reports/TEST-Fields-Field-display-blank-is-not-allowed.xml +11 -0
- data/test/reports/TEST-Fields-Field-hide-blank-.xml +11 -0
- data/test/reports/TEST-Fields-Field-parameters.xml +9 -0
- data/test/reports/TEST-Fields-Field.xml +13 -0
- data/test/reports/TEST-HammerCLI-AbstractCommand-build-options.xml +15 -0
- data/test/reports/TEST-HammerCLI-AbstractCommand-exception-handler.xml +13 -0
- data/test/reports/TEST-HammerCLI-AbstractCommand-logging.xml +21 -0
- data/test/reports/TEST-HammerCLI-AbstractCommand-option-builder.xml +11 -0
- data/test/reports/TEST-HammerCLI-AbstractCommand-options.xml +11 -0
- data/test/reports/TEST-HammerCLI-AbstractCommand-output.xml +19 -0
- data/test/reports/TEST-HammerCLI-AbstractCommand-subcommand-behavior-remove-subcommand.xml +11 -0
- data/test/reports/TEST-HammerCLI-AbstractCommand-subcommand-behavior-subcommand-.xml +13 -0
- data/test/reports/TEST-HammerCLI-AbstractCommand-subcommand-behavior-subcommand.xml +11 -0
- data/test/reports/TEST-HammerCLI-AbstractCommand-subcommand-behavior.xml +7 -0
- data/test/reports/TEST-HammerCLI-AbstractCommand.xml +11 -0
- data/test/reports/TEST-HammerCLI-Apipie-Command-options.xml +11 -0
- data/test/reports/TEST-HammerCLI-Apipie-Command-resource-defined.xml +9 -0
- data/test/reports/TEST-HammerCLI-Apipie-Command-setting-resources.xml +19 -0
- data/test/reports/TEST-HammerCLI-Apipie-Command.xml +9 -0
- data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder-aliasing-resources.xml +13 -0
- data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder-filtering-options.xml +15 -0
- data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder-required-options.xml +11 -0
- data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder-setting-correct-normalizers.xml +9 -0
- data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder-with-hash-params.xml +11 -0
- data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder-with-one-simple-param.xml +15 -0
- data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder.xml +7 -0
- data/test/reports/TEST-HammerCLI-Completer-command-completion.xml +29 -0
- data/test/reports/TEST-HammerCLI-Completer-option-value-completion.xml +17 -0
- data/test/reports/TEST-HammerCLI-Completer-subcommand-completion.xml +19 -0
- data/test/reports/TEST-HammerCLI-Completer.xml +7 -0
- data/test/reports/TEST-HammerCLI-CompleterLine-line-complete.xml +25 -0
- data/test/reports/TEST-HammerCLI-CompleterLine-splitting-words.xml +29 -0
- data/test/reports/TEST-HammerCLI-CompleterLine.xml +7 -0
- data/test/reports/TEST-HammerCLI-CompleterWord-complete-.xml +23 -0
- data/test/reports/TEST-HammerCLI-CompleterWord-quote.xml +15 -0
- data/test/reports/TEST-HammerCLI-CompleterWord-quoted-.xml +13 -0
- data/test/reports/TEST-HammerCLI-CompleterWord.xml +7 -0
- data/test/reports/TEST-HammerCLI-Connection.xml +21 -0
- data/test/reports/TEST-HammerCLI-ExceptionHandler.xml +21 -0
- data/test/reports/TEST-HammerCLI-I18n.xml +11 -0
- data/test/reports/TEST-HammerCLI-MainCommand-loading-context-password.xml +11 -0
- data/test/reports/TEST-HammerCLI-MainCommand-loading-context-username.xml +11 -0
- data/test/reports/TEST-HammerCLI-MainCommand-loading-context-verbose.xml +9 -0
- data/test/reports/TEST-HammerCLI-MainCommand-loading-context.xml +7 -0
- data/test/reports/TEST-HammerCLI-MainCommand.xml +7 -0
- data/test/reports/TEST-HammerCLI-Modules-find-by-name.xml +13 -0
- data/test/reports/TEST-HammerCLI-Modules-load-a-module-module-not-found.xml +13 -0
- data/test/reports/TEST-HammerCLI-Modules-load-a-module-module-runtime-exception.xml +13 -0
- data/test/reports/TEST-HammerCLI-Modules-load-a-module-success.xml +15 -0
- data/test/reports/TEST-HammerCLI-Modules-load-a-module.xml +7 -0
- data/test/reports/TEST-HammerCLI-Modules-load-all-modules.xml +9 -0
- data/test/reports/TEST-HammerCLI-Modules-names.xml +13 -0
- data/test/reports/TEST-HammerCLI-Modules.xml +7 -0
- data/test/reports/TEST-HammerCLI-OptionBuilderContainer.0.xml +7 -0
- data/test/reports/TEST-HammerCLI-OptionBuilderContainer.xml +11 -0
- data/test/reports/TEST-HammerCLI-Options-Normalizers-abstract.xml +9 -0
- data/test/reports/TEST-HammerCLI-Options-Normalizers-bool.xml +31 -0
- data/test/reports/TEST-HammerCLI-Options-Normalizers-datetime.xml +17 -0
- data/test/reports/TEST-HammerCLI-Options-Normalizers-enum.xml +15 -0
- data/test/reports/TEST-HammerCLI-Options-Normalizers-enumlist.xml +21 -0
- data/test/reports/TEST-HammerCLI-Options-Normalizers-json-input.xml +15 -0
- data/test/reports/TEST-HammerCLI-Options-Normalizers-key-value-list.xml +17 -0
- data/test/reports/TEST-HammerCLI-Options-Normalizers-list.xml +15 -0
- data/test/reports/TEST-HammerCLI-Options-Normalizers.xml +7 -0
- data/test/reports/TEST-HammerCLI-Options-OptionDefinition-context.xml +9 -0
- data/test/reports/TEST-HammerCLI-Options-OptionDefinition-formatters.xml +11 -0
- data/test/reports/TEST-HammerCLI-Options-OptionDefinition.xml +7 -0
- data/test/reports/TEST-HammerCLI-Output-Adapter-Abstract-error-messages.xml +15 -0
- data/test/reports/TEST-HammerCLI-Output-Adapter-Abstract-messages.xml +11 -0
- data/test/reports/TEST-HammerCLI-Output-Adapter-Abstract-test-data-for-field.xml +15 -0
- data/test/reports/TEST-HammerCLI-Output-Adapter-Abstract.xml +17 -0
- data/test/reports/TEST-HammerCLI-Output-Adapter-Base-print-collection-show-ids.xml +9 -0
- data/test/reports/TEST-HammerCLI-Output-Adapter-Base-print-collection.xml +27 -0
- data/test/reports/TEST-HammerCLI-Output-Adapter-Base.xml +7 -0
- data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues-print-collection-formatters.xml +11 -0
- data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues-print-collection-handle-fields-with-collections.xml +13 -0
- data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues-print-collection-handle-fields-with-containers.xml +11 -0
- data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues-print-collection-handle-ids.xml +11 -0
- data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues-print-collection.xml +11 -0
- data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues-print-message.xml +11 -0
- data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues.xml +7 -0
- data/test/reports/TEST-HammerCLI-Output-Adapter-Table-print-collection-column-width.xml +15 -0
- data/test/reports/TEST-HammerCLI-Output-Adapter-Table-print-collection-formatters.xml +11 -0
- data/test/reports/TEST-HammerCLI-Output-Adapter-Table-print-collection-handle-ids.xml +11 -0
- data/test/reports/TEST-HammerCLI-Output-Adapter-Table-print-collection-sort-columns.xml +9 -0
- data/test/reports/TEST-HammerCLI-Output-Adapter-Table-print-collection.xml +11 -0
- data/test/reports/TEST-HammerCLI-Output-Adapter-Table.xml +7 -0
- data/test/reports/TEST-HammerCLI-Output-Definition-empty-.xml +11 -0
- data/test/reports/TEST-HammerCLI-Output-Definition.xml +11 -0
- data/test/reports/TEST-HammerCLI-Output-Dsl-collection.xml +13 -0
- data/test/reports/TEST-HammerCLI-Output-Dsl-custom-fields.xml +11 -0
- data/test/reports/TEST-HammerCLI-Output-Dsl-fields.xml +15 -0
- data/test/reports/TEST-HammerCLI-Output-Dsl-label.xml +13 -0
- data/test/reports/TEST-HammerCLI-Output-Dsl-path-definition.xml +13 -0
- data/test/reports/TEST-HammerCLI-Output-Dsl.xml +9 -0
- data/test/reports/TEST-HammerCLI-Output-FieldFilter.xml +13 -0
- data/test/reports/TEST-HammerCLI-Output-Formatters-BooleanFormatter.xml +11 -0
- data/test/reports/TEST-HammerCLI-Output-Formatters-ColorFormatter.xml +9 -0
- data/test/reports/TEST-HammerCLI-Output-Formatters-DateFormatter.xml +11 -0
- data/test/reports/TEST-HammerCLI-Output-Formatters-FieldFormatter.xml +13 -0
- data/test/reports/TEST-HammerCLI-Output-Formatters-FormatterContainer.xml +13 -0
- data/test/reports/TEST-HammerCLI-Output-Formatters-FormatterLibrary.xml +11 -0
- data/test/reports/TEST-HammerCLI-Output-Formatters-KeyValueFormatter.xml +13 -0
- data/test/reports/TEST-HammerCLI-Output-Formatters-ListFormatter.xml +13 -0
- data/test/reports/TEST-HammerCLI-Output-Formatters-LongTextFormatter.xml +13 -0
- data/test/reports/TEST-HammerCLI-Output-Output-adapters.xml +17 -0
- data/test/reports/TEST-HammerCLI-Output-Output-data.xml +15 -0
- data/test/reports/TEST-HammerCLI-Output-Output-formatters.xml +9 -0
- data/test/reports/TEST-HammerCLI-Output-Output-messages.xml +19 -0
- data/test/reports/TEST-HammerCLI-Output-Output.xml +7 -0
- data/test/reports/TEST-HammerCLI-Output-RecordCollection.xml +13 -0
- data/test/reports/TEST-HammerCLI-Settings-load-from-paths.xml +15 -0
- data/test/reports/TEST-HammerCLI-Settings.xml +25 -0
- data/test/reports/TEST-HammerCLI-ShellHistory-loading-old-history.xml +11 -0
- data/test/reports/TEST-HammerCLI-ShellHistory-saving-history.xml +15 -0
- data/test/reports/TEST-HammerCLI-ShellHistory.xml +7 -0
- data/test/reports/TEST-MiniTest-Spec.xml +7 -0
- data/test/reports/TEST-String-camelize.xml +11 -0
- data/test/reports/TEST-String-formatting.xml +17 -0
- data/test/reports/TEST-String-indent.xml +11 -0
- data/test/reports/TEST-String-interactive-.xml +13 -0
- data/test/reports/TEST-String.xml +7 -0
- data/test/reports/TEST-constraints-HammerCLI-Validator-AllConstraint-exist-.xml +13 -0
- data/test/reports/TEST-constraints-HammerCLI-Validator-AllConstraint.xml +7 -0
- data/test/reports/TEST-constraints-HammerCLI-Validator-AnyConstraint-exist-.xml +13 -0
- data/test/reports/TEST-constraints-HammerCLI-Validator-AnyConstraint.xml +7 -0
- data/test/reports/TEST-constraints-HammerCLI-Validator-BaseConstraint-exist-.xml +9 -0
- data/test/reports/TEST-constraints-HammerCLI-Validator-BaseConstraint-rejected.xml +13 -0
- data/test/reports/TEST-constraints-HammerCLI-Validator-BaseConstraint-required.xml +13 -0
- data/test/reports/TEST-constraints-HammerCLI-Validator-BaseConstraint.xml +7 -0
- data/test/reports/TEST-constraints.xml +7 -0
- data/test/unit/help/definition/list_test.rb +12 -0
- data/test/unit/help/definition/note_test.rb +18 -0
- data/test/unit/help/definition/text_test.rb +5 -0
- data/test/unit/output/adapter/abstract_test.rb +9 -9
- data/test/unit/output/formatters_test.rb +49 -6
- metadata +348 -67
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 257e54094a8995f71d00dbe29299e84801b68404271de7baaad58b6a9207fe93
|
|
4
|
+
data.tar.gz: f14b2acba71f1a4ad5a237f7dc6da746a23245ba30c504e689bf5a319e5e86b2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 559d6704483f5dd8bb2f27ba7c0f8d3c4212033297168fad4cdea0696ee4cd31f8421f1e79cd758b9f4228ff45d2c41751f7509091de0f92ab86a1dab4d97649
|
|
7
|
+
data.tar.gz: 2396627dc3f2b9d97dca8b0501dc2260b6c02d4a59fbf64e2fbfcdf625d913703dd02d47557193d575156f5a2b1270c81c57ff8caae08345675567d063ecc892
|
data/doc/creating_commands.md
CHANGED
|
@@ -477,13 +477,7 @@ directly with `puts` in Hammer. The reason is we separate definition
|
|
|
477
477
|
of the output from its interpretation. Hammer uses so called _output adapters_
|
|
478
478
|
that can modify the output format.
|
|
479
479
|
|
|
480
|
-
|
|
481
|
-
* __base__ - simple output, structured records
|
|
482
|
-
* __table__ - records printed in tables, ideal for printing lists of records
|
|
483
|
-
* __csv__ - comma separated output, ideal for scripting and grepping
|
|
484
|
-
* __silent__ - no output, used for testing
|
|
485
|
-
|
|
486
|
-
The detailed documentation on creating adapters is coming soon.
|
|
480
|
+
The detailed documentation on adapters and related things is [here](output.md#adapters).
|
|
487
481
|
|
|
488
482
|
#### Printing messages
|
|
489
483
|
Very simple, just call
|
|
@@ -496,7 +490,7 @@ Typical usage of a CLI is interaction with some API. In many cases it's listing
|
|
|
496
490
|
some records returned by the API.
|
|
497
491
|
|
|
498
492
|
Hammer comes with support for selecting and formatting of hash record fields.
|
|
499
|
-
You first create
|
|
493
|
+
You first create an _output definition_ that you apply to your data. The result
|
|
500
494
|
is a collection of fields, each having its type. The collection is then passed to an
|
|
501
495
|
_output adapter_ which handles the actual formatting and printing.
|
|
502
496
|
|
data/doc/developer_docs.md
CHANGED
|
@@ -8,6 +8,7 @@ before creating hammer specific plugins.
|
|
|
8
8
|
Contents:
|
|
9
9
|
- [Writing a plugin](writing_a_plugin.md#writing-your-own-hammer-plugin)
|
|
10
10
|
- [Creating commands](creating_commands.md#create-your-first-command)
|
|
11
|
+
- [Output adapters, formatters, etc](output.md#output)
|
|
11
12
|
- [Help modification](help_modification.md#modify-an-existing-help)
|
|
12
13
|
- [Commands modification](commands_modification.md#modify-an-existing-command)
|
|
13
14
|
- [Command extensions](commands_extension.md#extend-an-existing-command)
|
|
@@ -16,6 +17,7 @@ Contents:
|
|
|
16
17
|
- [Development tips](development_tips.md#development-tips)
|
|
17
18
|
- [Option normalizers](option_normalizers.md#option-normalizers)
|
|
18
19
|
- [Internationalization](i18n.md#internationalization)
|
|
20
|
+
- [PR review checklist](review_checklist.md)
|
|
19
21
|
|
|
20
22
|
Links:
|
|
21
23
|
- slides from tutorial at Config Management Camp 2015: [Hacking with hammer](https://tstrachota.fedorapeople.org/slides/hacking_with_hammer/)
|
data/doc/help_modification.md
CHANGED
|
@@ -1,6 +1,38 @@
|
|
|
1
|
-
Modify an existing help
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# Modify an existing help
|
|
2
|
+
|
|
3
|
+
### Help items
|
|
4
|
+
Before modifying help, it's good to know which help items are available to use.
|
|
5
|
+
There is a list with currently available items:
|
|
6
|
+
```ruby
|
|
7
|
+
Command.extend_help do |h|
|
|
8
|
+
# Add a simple text to the help output.
|
|
9
|
+
# content - String - text to be shown
|
|
10
|
+
# options - Hash - options (id:, richtext:)
|
|
11
|
+
h.text(content, options = {})
|
|
12
|
+
# Add a notification to the help output (LABEL: content).
|
|
13
|
+
# content - String - text to be shown
|
|
14
|
+
# options - Hash - options (same as #text, label:)
|
|
15
|
+
h.note(content, options = {})
|
|
16
|
+
# Add a list of items to the help output.
|
|
17
|
+
# items - Array - array of items to be shown. Each item can be either string
|
|
18
|
+
# or an array of ['Key', 'Value', bold: true/false].
|
|
19
|
+
# Item options are optional.
|
|
20
|
+
# Example: h.list(['a', 'b', 'c']) => "a\n b\n c\n"
|
|
21
|
+
# h.list([['a', 'b', bold: true], ['c', 'd']]) => "a b\nc d\n"
|
|
22
|
+
# options - Hash - same as #text
|
|
23
|
+
h.list(items, options = {})
|
|
24
|
+
# Add a section to the help output.
|
|
25
|
+
# label - String - Section header
|
|
26
|
+
# options - Hash - same as #text
|
|
27
|
+
# block - block with section definition (may include lists/texts/etc.)
|
|
28
|
+
h.section(label, options = {}) { |h| ... }
|
|
29
|
+
end
|
|
30
|
+
```
|
|
31
|
+
Every `Section`, `List` and simple `Text` is _help item_ defined as `HammerCLI::Help::AbstractItem`, so everything might have its own ID now for easier addressing.
|
|
32
|
+
|
|
33
|
+
### Help modification
|
|
34
|
+
|
|
35
|
+
Each command might have its own help definition. This definition is composed of various [_help items_](#Help-items), which might contain their own definitions.
|
|
4
36
|
|
|
5
37
|
Let's say `hammer host create -h` help string has the following structure:
|
|
6
38
|
```
|
|
@@ -32,7 +64,6 @@ hammer host create -h
|
|
|
32
64
|
| | | +-- Section
|
|
33
65
|
| | | | +-- List
|
|
34
66
|
```
|
|
35
|
-
Every `Section`, `List` and simple `Text` is _help item_ defined as `HammerCLI::Help::AbstractItem`, so everything might have its own ID now for easier addressing.
|
|
36
67
|
|
|
37
68
|
To modify the structure above, you might use the following:
|
|
38
69
|
```ruby
|
data/doc/output.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
Output
|
|
2
|
+
------------------------------
|
|
3
|
+
|
|
4
|
+
### Adapters
|
|
5
|
+
Output adapter is responsible for rendering the output in a specific way using
|
|
6
|
+
__formatters__ (see below).
|
|
7
|
+
Hammer comes with following adapters:
|
|
8
|
+
* __base__ - simple output, structured records
|
|
9
|
+
* __table__ - records printed in tables, ideal for printing lists of records
|
|
10
|
+
* __csv__ - comma separated output, ideal for scripting and grepping
|
|
11
|
+
* __yaml__ - YAML output
|
|
12
|
+
* __json__ - JSON output
|
|
13
|
+
* __silent__ - no output, used for testing
|
|
14
|
+
|
|
15
|
+
### Formatters
|
|
16
|
+
Formatter is a bit of code that can modify a representation of a field during
|
|
17
|
+
output rendering. Formatter is registered for specific field type. Each field
|
|
18
|
+
type can have multiple formatters.
|
|
19
|
+
* __ColorFormatter__ - colors data with a specific color
|
|
20
|
+
* __DateFormatter__ - formats a date string with `%Y/%m/%d %H:%M:%S` style
|
|
21
|
+
* __ListFormatter__ - formats an array of data with csv style
|
|
22
|
+
* __KeyValueFormatter__ - formats a hash with `key => value` style
|
|
23
|
+
* __BooleanFormatter__ - converts `1/0`/`true/false`/`""` to `"yes"`/`"no"`
|
|
24
|
+
* __LongTextFormatter__ - adds a new line at the start of the data string
|
|
25
|
+
* __InlineTextFormatter__ - removes all new lines from data string
|
|
26
|
+
* __MultilineTextFormatter__ - splits a long data string to fixed size chunks
|
|
27
|
+
with indentation
|
|
28
|
+
|
|
29
|
+
### Formatter/Adapter features
|
|
30
|
+
Currently used formatter (or adapter) features are of two kinds.
|
|
31
|
+
The first one help us to align by structure of the output:
|
|
32
|
+
* __:serialized__ - means the fields are serialized into a string (__table__, __csv__, __base__ adapters)
|
|
33
|
+
* __:structured__ - means the output is structured (__yaml__, __json__ adapters)
|
|
34
|
+
* __:inline__ - means that the value will be rendered into single line without newlines (__table__, __csv__ adapters)
|
|
35
|
+
* __:multiline__ - means that the properly indented value will be printed over multiple lines (__base__ adapter)
|
|
36
|
+
|
|
37
|
+
The other kind serves to distinguish the cases where we can use the xterm colors
|
|
38
|
+
to improve the output:
|
|
39
|
+
* __:rich_text__ - means we can use the xterm colors (__table__, __base__ adapters)
|
|
40
|
+
* __:plain_text__ - unused yet
|
|
41
|
+
|
|
42
|
+
All the features the formatter has need to match (be present in) the adapter's
|
|
43
|
+
features. Otherwise the formatter won't apply.
|
data/doc/release_notes.md
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
Release notes
|
|
2
2
|
=============
|
|
3
|
-
### 0.
|
|
4
|
-
* Allow schema building for custom options ([PR #316](https://github.com/
|
|
3
|
+
### 0.19.0 (2019-10-26)
|
|
4
|
+
* Allow schema building for custom options ([PR #316](https://github.com/Apipie/apipie-bindings/pull/316)), [#27899](http://projects.theforeman.org/issues/27899)
|
|
5
|
+
* New lines in text attr dont break output ([PR #300](https://github.com/Apipie/apipie-bindings/pull/300)), [#25878](http://projects.theforeman.org/issues/25878)
|
|
6
|
+
* Added error to wrong --output ([PR #315](https://github.com/Apipie/apipie-bindings/pull/315)), [#21590](http://projects.theforeman.org/issues/21590)
|
|
7
|
+
* Pr review checklist ([PR #305](https://github.com/Apipie/apipie-bindings/pull/305)), [#26950](http://projects.theforeman.org/issues/26950)
|
|
8
|
+
* List items in help with customization ([PR #309](https://github.com/Apipie/apipie-bindings/pull/309)), [#27237](http://projects.theforeman.org/issues/27237)
|
|
5
9
|
|
|
6
10
|
### 0.18.0 (2019-08-01)
|
|
7
11
|
* Unsure minimal label length ([PR #310](https://github.com/theforeman/hammer-cli/pull/310)) ([#26960](http://projects.theforeman.org/issues/26960))
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
PR review Checklist
|
|
2
|
+
-------------------
|
|
3
|
+
Before the PR in hammer project is merged the reviewer should check the following things:
|
|
4
|
+
- [ ] Related issue exists
|
|
5
|
+
- [ ] Commit message is in correct format
|
|
6
|
+
- [ ] The patch fixes the problem described in the issue
|
|
7
|
+
- [ ] UX is consistent across commands
|
|
8
|
+
- [ ] The fix is in the right repo hammer core/hammer plugin/API
|
|
9
|
+
- [ ] It doesn't break compatibility for users
|
|
10
|
+
- [ ] It doesn't break compatibility for hammer plugins (even hammer-cli-foreman is extended by plugins)
|
|
11
|
+
- [ ] Strings are translated and the translations are properly formated
|
|
12
|
+
- [ ] The code is readable and understandable
|
|
13
|
+
- [ ] The code style is consistent with already existing
|
|
14
|
+
- [ ] Docs updated if changing documented patterns or adding new ones
|
|
15
|
+
- [ ] Tests for the new functionality/fix are added
|
|
16
|
+
- [ ] Automated tests are green
|
|
17
|
+
- [ ] Note if multiple commits needs squash on merge
|
|
@@ -3,12 +3,13 @@ module HammerCLI
|
|
|
3
3
|
class AbstractItem
|
|
4
4
|
INDENT_STEP = 2
|
|
5
5
|
|
|
6
|
-
attr_reader :id
|
|
6
|
+
attr_reader :id, :richtext
|
|
7
7
|
attr_accessor :definition
|
|
8
8
|
|
|
9
9
|
def initialize(options = {})
|
|
10
10
|
@id = options[:id]
|
|
11
11
|
@indentation = options[:indentation]
|
|
12
|
+
@richtext = options[:richtext] || false
|
|
12
13
|
end
|
|
13
14
|
|
|
14
15
|
def build_string
|
|
@@ -36,9 +36,12 @@ module HammerCLI
|
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
def format_item(item)
|
|
39
|
-
col1, col2 = item
|
|
39
|
+
col1, col2, options = item
|
|
40
|
+
options ||= {}
|
|
41
|
+
col1 = HighLine.color(col1.to_s, :bold) if options[:bold]
|
|
40
42
|
col2 = indent(col2.to_s, ' ' * @indent_size).lstrip
|
|
41
|
-
|
|
43
|
+
padding = col1.length - HammerCLI::Output::Utils.real_length(col1)
|
|
44
|
+
line = "%-#{@indent_size + padding}s%s" % [col1, col2]
|
|
42
45
|
line.strip!
|
|
43
46
|
line
|
|
44
47
|
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
module HammerCLI
|
|
2
|
+
module Help
|
|
3
|
+
class Note < Text
|
|
4
|
+
def initialize(text, options = {})
|
|
5
|
+
@label = options[:label] || _('NOTE')
|
|
6
|
+
super
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def build_string
|
|
10
|
+
@text
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
protected
|
|
14
|
+
|
|
15
|
+
def build_definition(content)
|
|
16
|
+
@text = heading + ' '
|
|
17
|
+
@text += content.to_s
|
|
18
|
+
@definition = Definition.new([self])
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
def heading
|
|
24
|
+
@label += ':'
|
|
25
|
+
@label = HighLine.color(@label, :bold) if @richtext
|
|
26
|
+
@label
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -18,9 +18,14 @@ module HammerCLI
|
|
|
18
18
|
@definition << HammerCLI::Help::Text.new(content, options)
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
-
def
|
|
21
|
+
def note(content, options = {})
|
|
22
|
+
@definition << HammerCLI::Help::Note.new(content, options)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def list(items, options = {}, &block)
|
|
22
26
|
return if items.empty?
|
|
23
|
-
|
|
27
|
+
|
|
28
|
+
@definition << HammerCLI::Help::List.new(items, options, &block)
|
|
24
29
|
end
|
|
25
30
|
|
|
26
31
|
def section(label, options = {}, &block)
|
data/lib/hammer_cli/main.rb
CHANGED
|
@@ -47,8 +47,8 @@ module HammerCLI
|
|
|
47
47
|
:context_target => :interactive
|
|
48
48
|
option ["--no-headers"], :flag, _("Hide headers from output")
|
|
49
49
|
option ["--csv"], :flag, _("Output as CSV (same as --output=csv)")
|
|
50
|
-
option ["--output"], "ADAPTER", _("Set output format
|
|
51
|
-
|
|
50
|
+
option ["--output"], "ADAPTER", _("Set output format"),
|
|
51
|
+
format: HammerCLI::Options::Normalizers::Enum.new(HammerCLI::Output::Output.adapters.keys.map(&:to_s)),
|
|
52
52
|
:context_target => :adapter
|
|
53
53
|
option ["--output-file"], "OUTPUT_FILE", _("Path to custom output file") do |filename|
|
|
54
54
|
begin
|
|
@@ -3,7 +3,13 @@ module HammerCLI::Output::Adapter
|
|
|
3
3
|
class Abstract
|
|
4
4
|
|
|
5
5
|
def tags
|
|
6
|
-
[]
|
|
6
|
+
%i[]
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def features
|
|
10
|
+
return %i[] if tags.empty?
|
|
11
|
+
|
|
12
|
+
tags.map { |t| HammerCLI::Output::Utils.tag_to_feature(t) }
|
|
7
13
|
end
|
|
8
14
|
|
|
9
15
|
def initialize(context={}, formatters={}, filters = {})
|
|
@@ -101,9 +107,9 @@ module HammerCLI::Output::Adapter
|
|
|
101
107
|
formatters_map ||= {}
|
|
102
108
|
formatters_map.inject({}) do |map, (type, formatter_list)|
|
|
103
109
|
# remove incompatible formatters
|
|
104
|
-
filtered = formatter_list.select { |f| f.match?(
|
|
110
|
+
filtered = formatter_list.select { |f| f.match?(features) }
|
|
105
111
|
# put serializers first
|
|
106
|
-
map[type] = filtered.sort_by { |f| f.
|
|
112
|
+
map[type] = filtered.sort_by { |f| f.required_features.include?(:serialized) ? 0 : 1 }
|
|
107
113
|
map
|
|
108
114
|
end
|
|
109
115
|
end
|
|
@@ -4,8 +4,10 @@ module HammerCLI::Output::Adapter
|
|
|
4
4
|
GROUP_INDENT = " "*4
|
|
5
5
|
LABEL_DIVIDER = ": "
|
|
6
6
|
|
|
7
|
-
def
|
|
8
|
-
[
|
|
7
|
+
def features
|
|
8
|
+
return %i[serialized rich_text multiline] if tags.empty?
|
|
9
|
+
|
|
10
|
+
tags.map { |t| HammerCLI::Output::Utils.tag_to_feature(t) }
|
|
9
11
|
end
|
|
10
12
|
|
|
11
13
|
def print_record(fields, record)
|
|
@@ -131,8 +131,10 @@ module HammerCLI::Output::Adapter
|
|
|
131
131
|
@paginate_by_default = false
|
|
132
132
|
end
|
|
133
133
|
|
|
134
|
-
def
|
|
135
|
-
[
|
|
134
|
+
def features
|
|
135
|
+
return %i[serialized inline] if tags.empty?
|
|
136
|
+
|
|
137
|
+
tags.map { |t| HammerCLI::Output::Utils.tag_to_feature(t) }
|
|
136
138
|
end
|
|
137
139
|
|
|
138
140
|
def row_data(fields, collection)
|
|
@@ -12,8 +12,10 @@ module HammerCLI::Output::Adapter
|
|
|
12
12
|
LINE_SEPARATOR = '-|-'
|
|
13
13
|
COLUMN_SEPARATOR = ' | '
|
|
14
14
|
|
|
15
|
-
def
|
|
16
|
-
[
|
|
15
|
+
def features
|
|
16
|
+
return %i[rich_text serialized inline] if tags.empty?
|
|
17
|
+
|
|
18
|
+
tags.map { |t| HammerCLI::Output::Utils.tag_to_feature(t) }
|
|
17
19
|
end
|
|
18
20
|
|
|
19
21
|
def print_record(fields, record)
|
|
@@ -5,10 +5,10 @@ module HammerCLI::Output::Adapter
|
|
|
5
5
|
@paginate_by_default = false
|
|
6
6
|
end
|
|
7
7
|
|
|
8
|
-
def
|
|
9
|
-
[
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
def features
|
|
9
|
+
return %i[structured] if tags.empty?
|
|
10
|
+
|
|
11
|
+
tags.map { |t| HammerCLI::Output::Utils.tag_to_feature(t) }
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
def prepare_collection(fields, collection)
|
|
@@ -24,28 +24,37 @@ module HammerCLI::Output
|
|
|
24
24
|
end
|
|
25
25
|
end
|
|
26
26
|
|
|
27
|
-
# Tags:
|
|
28
|
-
# All the tags the formatter has, needs to be present in the addapter.
|
|
29
|
-
# Otherwise the formatter won't apply. Formatters with :flat tag are used first
|
|
30
|
-
# as we expect them to serialize the value.
|
|
31
|
-
#
|
|
32
|
-
# - by format: :flat x :data
|
|
33
|
-
# - by output: :file X :screen
|
|
34
|
-
|
|
35
27
|
# abstract formatter
|
|
36
28
|
class FieldFormatter
|
|
37
|
-
|
|
38
29
|
def tags
|
|
39
|
-
[]
|
|
30
|
+
%i[]
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def required_features
|
|
34
|
+
return %i[] if tags.empty?
|
|
35
|
+
|
|
36
|
+
tags.map { |t| HammerCLI::Output::Utils.tag_to_feature(t) }
|
|
40
37
|
end
|
|
41
38
|
|
|
42
|
-
def match?(
|
|
43
|
-
|
|
39
|
+
def match?(features)
|
|
40
|
+
required_features & features == required_features
|
|
44
41
|
end
|
|
45
42
|
|
|
46
43
|
def format(data, field_params={})
|
|
47
44
|
data
|
|
48
45
|
end
|
|
46
|
+
|
|
47
|
+
def self.inherited(subclass)
|
|
48
|
+
subclass.define_singleton_method(:method_added) do |method_name|
|
|
49
|
+
if method_name == :tags
|
|
50
|
+
warn(
|
|
51
|
+
_('Method %{tags} for field formatters and output adapters is deprecated. Please use %{feat} or %{req_feat} instead.') % {
|
|
52
|
+
tags: 'tags', feat: 'features', req_feat: 'required_features'
|
|
53
|
+
}
|
|
54
|
+
)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
49
58
|
end
|
|
50
59
|
|
|
51
60
|
class FormatterContainer < FieldFormatter
|
|
@@ -69,8 +78,10 @@ module HammerCLI::Output
|
|
|
69
78
|
@color = color
|
|
70
79
|
end
|
|
71
80
|
|
|
72
|
-
def
|
|
73
|
-
[
|
|
81
|
+
def required_features
|
|
82
|
+
return %i[rich_text serialized] if tags.empty?
|
|
83
|
+
|
|
84
|
+
tags.map { |t| HammerCLI::Output::Utils.tag_to_feature(t) }
|
|
74
85
|
end
|
|
75
86
|
|
|
76
87
|
def format(data, field_params={})
|
|
@@ -80,8 +91,10 @@ module HammerCLI::Output
|
|
|
80
91
|
|
|
81
92
|
class DateFormatter < FieldFormatter
|
|
82
93
|
|
|
83
|
-
def
|
|
84
|
-
[
|
|
94
|
+
def required_features
|
|
95
|
+
return %i[serialized] if tags.empty?
|
|
96
|
+
|
|
97
|
+
tags.map { |t| HammerCLI::Output::Utils.tag_to_feature(t) }
|
|
85
98
|
end
|
|
86
99
|
|
|
87
100
|
def format(string_date, field_params={})
|
|
@@ -95,8 +108,10 @@ module HammerCLI::Output
|
|
|
95
108
|
class ListFormatter < FieldFormatter
|
|
96
109
|
INDENT = " "
|
|
97
110
|
|
|
98
|
-
def
|
|
99
|
-
[
|
|
111
|
+
def required_features
|
|
112
|
+
return %i[serialized] if tags.empty?
|
|
113
|
+
|
|
114
|
+
tags.map { |t| HammerCLI::Output::Utils.tag_to_feature(t) }
|
|
100
115
|
end
|
|
101
116
|
|
|
102
117
|
def format(list, field_params={})
|
|
@@ -117,8 +132,10 @@ module HammerCLI::Output
|
|
|
117
132
|
|
|
118
133
|
class KeyValueFormatter < FieldFormatter
|
|
119
134
|
|
|
120
|
-
def
|
|
121
|
-
[
|
|
135
|
+
def required_features
|
|
136
|
+
return %i[rich_text serialized] if tags.empty?
|
|
137
|
+
|
|
138
|
+
tags.map { |t| HammerCLI::Output::Utils.tag_to_feature(t) }
|
|
122
139
|
end
|
|
123
140
|
|
|
124
141
|
def format(params, field_params={})
|
|
@@ -140,8 +157,10 @@ module HammerCLI::Output
|
|
|
140
157
|
@indent = options[:indent].nil? ? true : options[:indent]
|
|
141
158
|
end
|
|
142
159
|
|
|
143
|
-
def
|
|
144
|
-
[
|
|
160
|
+
def required_features
|
|
161
|
+
return %i[rich_text] if tags.empty?
|
|
162
|
+
|
|
163
|
+
tags.map { |t| HammerCLI::Output::Utils.tag_to_feature(t) }
|
|
145
164
|
end
|
|
146
165
|
|
|
147
166
|
def format(text, field_params={})
|
|
@@ -150,10 +169,42 @@ module HammerCLI::Output
|
|
|
150
169
|
end
|
|
151
170
|
end
|
|
152
171
|
|
|
172
|
+
class InlineTextFormatter < FieldFormatter
|
|
173
|
+
def required_features
|
|
174
|
+
return %i[serialized inline] if tags.empty?
|
|
175
|
+
|
|
176
|
+
tags.map { |t| HammerCLI::Output::Utils.tag_to_feature(t) }
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
def format(text, _field_params = {})
|
|
180
|
+
text.to_s.tr("\r\n", ' ')
|
|
181
|
+
end
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
class MultilineTextFormatter < FieldFormatter
|
|
185
|
+
INDENT = ' '.freeze
|
|
186
|
+
MAX_WIDTH = 120
|
|
187
|
+
MIN_WIDTH = 60
|
|
188
|
+
|
|
189
|
+
def required_features
|
|
190
|
+
return %i[serialized multiline rich_text] if tags.empty?
|
|
191
|
+
|
|
192
|
+
tags.map { |t| HammerCLI::Output::Utils.tag_to_feature(t) }
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
def format(text, field_params = {})
|
|
196
|
+
width = [[field_params.fetch(:width, 0), MIN_WIDTH].max, MAX_WIDTH].min
|
|
197
|
+
text.to_s.chars.each_slice(width).map(&:join).join("\n")
|
|
198
|
+
.indent_with(INDENT).prepend("\n")
|
|
199
|
+
end
|
|
200
|
+
end
|
|
201
|
+
|
|
153
202
|
class BooleanFormatter < FieldFormatter
|
|
154
203
|
|
|
155
|
-
def
|
|
156
|
-
[
|
|
204
|
+
def required_features
|
|
205
|
+
return %i[serialized rich_text] if tags.empty?
|
|
206
|
+
|
|
207
|
+
tags.map { |t| HammerCLI::Output::Utils.tag_to_feature(t) }
|
|
157
208
|
end
|
|
158
209
|
|
|
159
210
|
def format(value, field_params={})
|
|
@@ -165,10 +216,9 @@ module HammerCLI::Output
|
|
|
165
216
|
HammerCLI::Output::Output.register_formatter(ListFormatter.new, :List)
|
|
166
217
|
HammerCLI::Output::Output.register_formatter(KeyValueFormatter.new, :KeyValue)
|
|
167
218
|
HammerCLI::Output::Output.register_formatter(LongTextFormatter.new, :LongText)
|
|
219
|
+
HammerCLI::Output::Output.register_formatter(InlineTextFormatter.new, :Text)
|
|
220
|
+
HammerCLI::Output::Output.register_formatter(MultilineTextFormatter.new, :Text)
|
|
168
221
|
HammerCLI::Output::Output.register_formatter(BooleanFormatter.new, :Boolean)
|
|
169
222
|
|
|
170
223
|
end
|
|
171
224
|
end
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|