hammer_cli 0.2.0 → 0.3.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.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/bin/hammer +16 -9
  3. data/doc/creating_commands.md +20 -0
  4. data/doc/release_notes.md +7 -0
  5. data/lib/hammer_cli/apipie/option_builder.rb +4 -0
  6. data/lib/hammer_cli/options/normalizers.rb +25 -2
  7. data/lib/hammer_cli/options/option_definition.rb +12 -0
  8. data/lib/hammer_cli/version.rb +1 -1
  9. data/locale/de/LC_MESSAGES/hammer-cli.mo +0 -0
  10. data/locale/de/hammer-cli.edit.po +8 -7
  11. data/locale/de/hammer-cli.po +19 -4
  12. data/locale/en/LC_MESSAGES/hammer-cli.mo +0 -0
  13. data/locale/en/hammer-cli.edit.po +87 -72
  14. data/locale/en/hammer-cli.po +15 -3
  15. data/locale/en_GB/LC_MESSAGES/hammer-cli.mo +0 -0
  16. data/locale/en_GB/hammer-cli.po +15 -3
  17. data/locale/es/LC_MESSAGES/hammer-cli.mo +0 -0
  18. data/locale/es/hammer-cli.po +19 -4
  19. data/locale/fr/LC_MESSAGES/hammer-cli.mo +0 -0
  20. data/locale/fr/hammer-cli.po +19 -4
  21. data/locale/hammer-cli.pot +140 -124
  22. data/locale/it/LC_MESSAGES/hammer-cli.mo +0 -0
  23. data/locale/it/hammer-cli.po +19 -4
  24. data/locale/ja/LC_MESSAGES/hammer-cli.mo +0 -0
  25. data/locale/ja/hammer-cli.po +19 -4
  26. data/locale/ko/LC_MESSAGES/hammer-cli.mo +0 -0
  27. data/locale/ko/hammer-cli.po +19 -4
  28. data/locale/pt_BR/LC_MESSAGES/hammer-cli.mo +0 -0
  29. data/locale/pt_BR/hammer-cli.po +19 -4
  30. data/locale/ru/LC_MESSAGES/hammer-cli.mo +0 -0
  31. data/locale/ru/hammer-cli.edit.po +12 -11
  32. data/locale/ru/hammer-cli.po +19 -4
  33. data/locale/zh_CN/LC_MESSAGES/hammer-cli.mo +0 -0
  34. data/locale/zh_CN/hammer-cli.po +19 -4
  35. data/locale/zh_TW/LC_MESSAGES/hammer-cli.mo +0 -0
  36. data/locale/zh_TW/hammer-cli.po +19 -4
  37. data/test/unit/apipie/option_builder_test.rb +10 -1
  38. data/test/unit/fixtures/apipie/documented.json +18 -0
  39. data/test/unit/options/normalizers_test.rb +13 -2
  40. data/test/unit/options/option_definition_test.rb +30 -0
  41. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9027b34462e30b995c85afac2a0c61eb4dee544f
4
- data.tar.gz: 51aeab33dc28f1242992eccc6feca4a5a5895411
3
+ metadata.gz: 7da6a9e45a6760f38b354282567dcddad5b4d004
4
+ data.tar.gz: 7bda2b5e6eb146a1b747b83101a9b536645f23d1
5
5
  SHA512:
6
- metadata.gz: 61d84ed050de0079e88d80ae2f4a4b94e136f061d1a041c631ebe043ec4ff776b4a63713ce415ebd2b15d87aaf86a243a895610baa0d04c89d8385c625b59e44
7
- data.tar.gz: 42882c180f2e21aad6cf99a8a784d8e9be6439caa6a82e77dc7007227861c95fae4715cdbe52de2dfdae46c54b4e9cc56aa7d3419f6bcde505c2ff770b302759
6
+ metadata.gz: 5f0ae742b4500cd823de4d92be2b6b95149dd4e281adfcb232ef68111817e7b9dab27267799a562b32910b038389f64dc2922a62c609fd8ef8ce619cd82c5543
7
+ data.tar.gz: 1c9619bd4fc7f3bc8b6b83aba7b8550f567226569afc2407e55493211afa27087b6f3a93b2e2aa287a5402482bcf39bdfd6637e8c323574ed186c971da0596bc
data/bin/hammer CHANGED
@@ -9,19 +9,26 @@ HighLine.color_scheme = HighLine::SampleColorScheme.new
9
9
  require 'hammer_cli/i18n'
10
10
 
11
11
  require 'hammer_cli/options/normalizers'
12
- # create fake command instance to use some global args before we start
12
+ # Create fake command instance to use some global args before we start.
13
+ # Option descriptions are never displayed and thus do not require translation.
13
14
  class PreParser < Clamp::Command
14
- option ["-v", "--verbose"], :flag, _("be verbose")
15
- option ["-d", "--debug"], :flag, _("show debugging output")
16
- option ["-c", "--config"], "CFG_FILE", _("path to custom config file")
17
- option ["-u", "--username"], "USERNAME", _("username to access the remote system")
18
- option ["-p", "--password"], "PASSWORD", _("password to access the remote system")
19
- option ["-s", "--server"], "SERVER", _("remote system address")
20
- option ["-r", "--reload-cache"], :flag, _("force reload of Apipie cache")
21
- option ["--interactive"], "INTERACTIVE", _("Explicitly turn interactive mode on/off") do |value|
15
+ option ["-v", "--verbose"], :flag, "be verbose"
16
+ option ["-d", "--debug"], :flag, "show debugging output"
17
+ option ["-c", "--config"], "CFG_FILE", "path to custom config file"
18
+ option ["-u", "--username"], "USERNAME", "username to access the remote system"
19
+ option ["-p", "--password"], "PASSWORD", "password to access the remote system"
20
+ option ["-s", "--server"], "SERVER", "remote system address"
21
+ option ["-r", "--reload-cache"], :flag, "force reload of Apipie cache"
22
+ option ["--interactive"], "INTERACTIVE", "Explicitly turn interactive mode on/off" do |value|
22
23
  bool_normalizer = HammerCLI::Options::Normalizers::Bool.new
23
24
  bool_normalizer.format(value)
24
25
  end
26
+ option ["--version"], :flag, "show version"
27
+ option ["--show-ids"], :flag, "Show ids of associated resources"
28
+ option ["--csv"], :flag, "Output as CSV (same as --output=csv)"
29
+ option ["--output"], "ADAPTER", "Set output format"
30
+ option ["--csv-separator"], "SEPARATOR", "Character to separate the values"
31
+ option ["--autocomplete"], "LINE", "Get list of possible endings"
25
32
  end
26
33
 
27
34
  preparser = PreParser.new File.basename($0), {}
@@ -129,6 +129,26 @@ $ hammer hello --name 'Foreman'
129
129
  Hello Foreman!
130
130
  ```
131
131
 
132
+ #### Deprecated options
133
+ To mark an option as deprecated use the `:deprecated` option as follows:
134
+ ```ruby
135
+ option '--name', "NAME", "Name of the person you want to greet",
136
+ :deprecated => _('Use --alias instead')
137
+ ```
138
+ It will ensure user is warned when deprecated option is used:
139
+ ```
140
+ $ hammer hello --name 'Foreman'
141
+ Warning: Option --name is deprecated. Use --alias instead
142
+ Hello Foreman!
143
+ ```
144
+
145
+ In cases when you want to deprecate just one of more possible switches use the extended syntax:
146
+ ```ruby
147
+ option ['--alias','--name'], "NAME", "Name of the person you want to greet",
148
+ :deprecated => { '--name' => _('Use --alias instead') }
149
+ ```
150
+
151
+
132
152
  ### Option builders
133
153
  Hammer commands offer option builders that can be used for automatic option generation.
134
154
  See [documentation page](option_builders.md#option-builders) dedicated to this topic for more details.
data/doc/release_notes.md CHANGED
@@ -1,6 +1,13 @@
1
1
  Release notes
2
2
  =============
3
3
 
4
+ ### 0.3.0 (2015-07-29)
5
+ * Add normalizer converting id parameter values to numbers ([#11137](http://projects.theforeman.org/issues/11137))
6
+ * Set Enum normalizer on enumerated values ([#11033](http://projects.theforeman.org/issues/11033))
7
+ * Add missing options to preparser ([#10902](http://projects.theforeman.org/issues/10902))
8
+ * Added support for deprecated options ([#10564](http://projects.theforeman.org/issues/10564))
9
+
10
+
4
11
  ### 0.2.0 (2015-04-23)
5
12
  * Rubygem locale pined to version >= 2.0.6 ([#10154](http://projects.theforeman.org/issues/10154))
6
13
  * Restricted logging version as in 2.0.0 ruby 1.8.7 support was dropped
@@ -68,6 +68,10 @@ module HammerCLI::Apipie
68
68
  opts[:format] = HammerCLI::Options::Normalizers::List.new
69
69
  elsif param.expected_type == 'boolean' || param.validator =~ /Boolean/i
70
70
  opts[:format] = HammerCLI::Options::Normalizers::Bool.new
71
+ elsif param.validator =~ /Must be one of: (.*)\./
72
+ opts[:format] = HammerCLI::Options::Normalizers::Enum.new($1.split(/,\ ?/))
73
+ elsif param.expected_type == 'number' || param.validator =~ /Number/i
74
+ opts[:format] = HammerCLI::Options::Normalizers::Number.new
71
75
  end
72
76
  opts[:attribute_name] = HammerCLI.option_accessor_name(param.name)
73
77
  opts[:referenced_resource] = resource_name(param)
@@ -79,6 +79,23 @@ module HammerCLI
79
79
  end
80
80
 
81
81
 
82
+ class Number < AbstractNormalizer
83
+
84
+ def format(val)
85
+ if numeric?(val)
86
+ val.to_i
87
+ else
88
+ raise ArgumentError, _("numeric value is required")
89
+ end
90
+ end
91
+
92
+ def numeric?(val)
93
+ Integer(val) != nil rescue false
94
+ end
95
+
96
+ end
97
+
98
+
82
99
  class Bool < AbstractNormalizer
83
100
 
84
101
  def description
@@ -138,20 +155,26 @@ module HammerCLI
138
155
 
139
156
 
140
157
  class Enum < AbstractNormalizer
158
+ attr_reader :allowed_values
141
159
 
142
160
  def initialize(allowed_values)
143
161
  @allowed_values = allowed_values
144
162
  end
145
163
 
146
164
  def description
147
- _("One of %s") % quoted_values
165
+ _("Possible value(s): %s") % quoted_values
148
166
  end
149
167
 
150
168
  def format(value)
151
169
  if @allowed_values.include? value
152
170
  value
153
171
  else
154
- raise ArgumentError, _("value must be one of '%s'") % quoted_values
172
+ if allowed_values.count == 1
173
+ msg = _("value must be %s") % quoted_values
174
+ else
175
+ msg = _("value must be one of %s") % quoted_values
176
+ end
177
+ raise ArgumentError, msg
155
178
  end
156
179
  end
157
180
 
@@ -20,10 +20,12 @@ module HammerCLI
20
20
 
21
21
  attr_accessor :value_formatter
22
22
  attr_accessor :context_target
23
+ attr_accessor :deprecated_switches
23
24
 
24
25
  def initialize(switches, type, description, options = {})
25
26
  self.value_formatter = options.delete(:format)
26
27
  self.context_target = options.delete(:context_target)
28
+ self.deprecated_switches = options.delete(:deprecated)
27
29
  super
28
30
  end
29
31
 
@@ -50,6 +52,16 @@ module HammerCLI
50
52
  rhs.empty? ? " " : rhs
51
53
  end
52
54
 
55
+ def handles?(switch)
56
+ message = _("Warning: Option #{switch} is deprecated. %s")
57
+ if deprecated_switches.class <= String && switches.include?(switch)
58
+ warn(message % deprecated_switches)
59
+ elsif deprecated_switches.class <= Hash && deprecated_switches.keys.include?(switch)
60
+ warn(message % deprecated_switches[switch])
61
+ end
62
+ super(switch)
63
+ end
64
+
53
65
  def format_description
54
66
  if value_formatter.nil?
55
67
  ""
@@ -1,5 +1,5 @@
1
1
  module HammerCLI
2
2
  def self.version
3
- @version ||= Gem::Version.new '0.2.0'
3
+ @version ||= Gem::Version.new '0.3.0'
4
4
  end
5
5
  end
Binary file
@@ -3,6 +3,7 @@
3
3
  # This file is distributed under the same license as the hammer-cli package.
4
4
  #
5
5
  # Translators:
6
+ # Christina Gurski <Gurski_christina@yahoo.de>, 2015
6
7
  # Dominic Cleal <dcleal@redhat.com>, 2014
7
8
  # Ettore Atalan <atalanttore@googlemail.com>, 2014
8
9
  # simon11 <simon.stieger.98@live.de>, 2014
@@ -13,8 +14,8 @@ msgstr ""
13
14
  "Project-Id-Version: Foreman\n"
14
15
  "Report-Msgid-Bugs-To: \n"
15
16
  "POT-Creation-Date: 2014-12-10 13:50+0100\n"
16
- "PO-Revision-Date: 2015-03-09 14:42+0000\n"
17
- "Last-Translator: Lukáš Zapletal\n"
17
+ "PO-Revision-Date: 2015-06-27 20:10+0000\n"
18
+ "Last-Translator: Christina Gurski <Gurski_christina@yahoo.de>\n"
18
19
  "Language-Team: German (http://www.transifex.com/projects/p/foreman/language/de/)\n"
19
20
  "MIME-Version: 1.0\n"
20
21
  "Content-Type: text/plain; charset=UTF-8\n"
@@ -136,7 +137,7 @@ msgstr "Debugausgabe anzeigen"
136
137
 
137
138
  #: lib/hammer_cli/main.rb:9
138
139
  msgid "force reload of Apipie cache"
139
- msgstr ""
140
+ msgstr "Neuladen des Apipie-Caches erzwingen"
140
141
 
141
142
  #: lib/hammer_cli/main.rb:11
142
143
  msgid "path to custom config file"
@@ -200,7 +201,7 @@ msgstr "Warnung: Beim Laden von Modul %s ist ein Fehler aufgetreten"
200
201
 
201
202
  #: lib/hammer_cli/modules.rb:87
202
203
  msgid "Error: Some of the required modules are disabled in configuration: %s "
203
- msgstr ""
204
+ msgstr "Fehler: Einige der erforderlichen Module sind in der Konfiguration deaktiviert: %s"
204
205
 
205
206
  #: lib/hammer_cli/exception_handler.rb:62
206
207
  msgid "Error: %s"
@@ -230,11 +231,11 @@ msgstr "ist der Server nicht verfügbar?"
230
231
  msgid ""
231
232
  "was '%s' run on the server when using apipie cache? (typical production "
232
233
  "settings)"
233
- msgstr ""
234
+ msgstr "Wurde '%s' auf dem Server ausgeführt, während Apipe-Cache in Verwendung war? (typische Produktionseinstellungen)"
234
235
 
235
236
  #: lib/hammer_cli/exception_handler.rb:101
236
237
  msgid "Missing arguments for %s"
237
- msgstr ""
238
+ msgstr "Argumente für %s nicht vorhanden"
238
239
 
239
240
  #: lib/hammer_cli/validator.rb:41
240
241
  msgid "Unknown option name '%s'"
@@ -300,4 +301,4 @@ msgstr "Interaktive Shell"
300
301
  msgid ""
301
302
  "can't replace subcommand %<name>s (%<existing_class>s) with %<name>s "
302
303
  "(%<new_class>s)"
303
- msgstr ""
304
+ msgstr "Unterbefehl %<name>s (%<existing_class>s) kann nicht durch %<name>s (%<new_class>s) ersetzt werden"
@@ -10,7 +10,7 @@
10
10
  # Ulrich Habel <rhaen@pkgbox.de>, 2014
11
11
  msgid ""
12
12
  msgstr ""
13
- "Project-Id-Version: hammer-cli 0.2.0\n"
13
+ "Project-Id-Version: hammer-cli 0.3.0\n"
14
14
  "Report-Msgid-Bugs-To: \n"
15
15
  "PO-Revision-Date: 2014-09-16 16:54+0000\n"
16
16
  "Last-Translator: Dominic Cleal <dcleal@redhat.com>\n"
@@ -105,6 +105,10 @@ msgstr "Adresse des entfernten Systems"
105
105
  msgid "show version"
106
106
  msgstr "Version anzeigen"
107
107
 
108
+ #, fuzzy
109
+ msgid "unknown version"
110
+ msgstr "Version anzeigen"
111
+
108
112
  msgid "Show ids of associated resources"
109
113
  msgstr "IDs zugehöriger Ressourcen anzeigen"
110
114
 
@@ -145,6 +149,9 @@ msgstr "Wert muss als kommagetrennte Liste mit Schlüssel-Wert-Paaren definiert
145
149
  msgid "Comma separated list of values."
146
150
  msgstr "Kommagetrennte Liste von Werten."
147
151
 
152
+ msgid "numeric value is required"
153
+ msgstr ""
154
+
148
155
  msgid "One of true/false, yes/no, 1/0."
149
156
  msgstr "Eines von true/false, yes/no, 1/0."
150
157
 
@@ -154,10 +161,15 @@ msgstr "Gültige Werte sind true/false, yes/no, 1/0"
154
161
  msgid "Unable to parse JSON input"
155
162
  msgstr "JSON Eingabe nicht lesbar"
156
163
 
157
- msgid "One of %s"
158
- msgstr "Einer von %s"
164
+ msgid "Possible value(s): %s"
165
+ msgstr ""
159
166
 
160
- msgid "value must be one of '%s'"
167
+ #, fuzzy
168
+ msgid "value must be %s"
169
+ msgstr "Gültige Werte sind \"%s\""
170
+
171
+ #, fuzzy
172
+ msgid "value must be one of %s"
161
173
  msgstr "Gültige Werte sind \"%s\""
162
174
 
163
175
  msgid "Date and time in YYYY-MM-DD HH:MM:SS or ISO 8601 format"
@@ -172,6 +184,9 @@ msgstr "Eine Kombination (kommagetrennte Liste) aus \"%s\""
172
184
  msgid "value must be a combination of '%s'"
173
185
  msgstr "Wert muss eine Kombination aus \"%s\" sein"
174
186
 
187
+ msgid "\"Warning: Option #{switch} is deprecated. %s\""
188
+ msgstr ""
189
+
175
190
  msgid "Can be specified multiple times. "
176
191
  msgstr "Kann mehrfach angegeben werden."
177
192
 
Binary file