arg-parser 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ODcwNmFlYTFmYzRkMDE2NzRkYzVjMmIyZjEzOGZiMDZmNWYxODRjNQ==
4
+ YjVkYzMxZDYxNTUzZjdlOTEwMjY3MThiYzNmYTc1OTQ4ZWQ4MjkxZQ==
5
5
  data.tar.gz: !binary |-
6
- NzNlZjg3MmI1YTVkNjY1NmNmOThhYWIyM2I3YjJmMzgzZDgzMTViZg==
6
+ ZWI1MTc5MDc3ZDE0YjZhZmJiODFlZDBjN2Q0OTFmMjY3ODQ4YzMxZQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZmY0MThmOTJiM2UwNmVlODEwZWFkNjczNWZlNmYwNzA4NThkNGMwOGNkYTdj
10
- OWNlY2ZlZGVlYzMwNTNhMDM2OTJhM2RmNDIzOTFhZmVmNzdhOTBiZmY4M2Qw
11
- N2I5YjdiNjhhNDdlYWI4ZjJiNTNmYzM3YjM1ZDJiZTYzMGM3NWU=
9
+ ZWQ1ZmIzODNlMDI4YjFlZDcwODQ2MDIzODI4MmMyMTg3OTE2MjA4NTZjZmYz
10
+ OTlkMzQ2NTBmM2YxNzFjOWZmMTM5NjZjM2RmZTZiYzU5MzQ2M2Y0NjVhMGMw
11
+ ZDM2Zjk4MmVkODBmMjM1YWUxNGMyODllOTgxYmRlYWMwMjMxMGY=
12
12
  data.tar.gz: !binary |-
13
- ZWNlNThjZGRiZGM3YjY4ZGQ2N2FkODFiN2E4YzMyMGRkNDY2MDhmMzRkNGJl
14
- NTNkMzZkMzU0Y2ZkN2VkMmM3YjBhMWU5MDI0ZDE1YTBiN2JiNzIzYzQ1MmYz
15
- MDhmYTk0NjYwMzI4ODU4MWY4NDU0ODJlMDgxMzZmZTU3YjE5NWY=
13
+ NWMwOTk4NDU1NGQwNDNmMTc4Zjc2MGJhZGM4YmE3OWM1MDZmM2RkODQ1ZjU2
14
+ OTdkOGQxYmJiNDFjZGU3MGRmMzc3MzFhOTA2MDc0MTU3YzRhMjA3NTY2YmY4
15
+ NmJlYzdiZGVkYjc0MDY1ZTdjMTJhYjIxZTFkOTUwNWRmMWY4Mjk=
data/README.md CHANGED
@@ -31,7 +31,12 @@ class MyClass
31
31
  EOT
32
32
 
33
33
  positional_arg :my_positional_arg, 'This is a positional arg'
34
- keyword_arg :my_keyword_arg, 'This is a keyword arg'
34
+ keyword_arg :my_keyword_arg, 'This is a keyword arg; if not specified, returns value1',
35
+ default: 'value1'
36
+ # An optional value keyword argument. If not specified, returns false. If specified
37
+ # without a value, returns 'maybe'. If specified with a value, returns the value.
38
+ keyword_arg :val_opt, 'This is a keyword arg with optional value',
39
+ value_optional: 'maybe'
35
40
  flag_arg :flag, 'This is a flag argument'
36
41
  rest_arg :files, 'This is where we specify that remaining args will be collected in an array'
37
42
 
@@ -61,6 +66,8 @@ list of features:
61
66
  * Mandatory vs Optional: All arguments your program accepts can be defined as optional or mandatory.
62
67
  By default, positional arguments are considered mandatory, and all others default to optional. To change
63
68
  the default, simply specify `required: true` or `required: false` when defining the argument.
69
+ * Keyword arguments can also accept an optional value, using the `value_optional` option. If a keyword
70
+ argument is supplied without a value, it returns the value of the `value_optional` option.
64
71
  * Short-keys and long-keys: Arguments are defined with a long_key name which will be used to access the
65
72
  parsed value in the results. However, arguments can also define a single letter or digit short-key form
66
73
  which can be used as an alternate means for indicating a value. To define a short key, simply pass
@@ -195,8 +195,18 @@ module ArgParser
195
195
  class KeywordArgument < ValueArgument
196
196
 
197
197
  # Whether the keyword argument must be specified with a non-missing
198
- # value.
199
- # @return [Boolean] true if the keyword can be specified without a value.
198
+ # value. The default is false, meaning the keyword argument must be
199
+ # specified together with a value. When this property is set to a
200
+ # non-falsy value (i.e. not nil or false), the keyword argument can
201
+ # be specified either with or without a value (or not at all):
202
+ # - If specified with a value, the value will be returned.
203
+ # - If specified without a value, the value of this property will be
204
+ # returned.
205
+ # - If not specified at all, the default value will be returned.
206
+ #
207
+ # @return [Object] If truthy, the argument does not require a value.
208
+ # If the argument is specified but no value is provided, the value
209
+ # of this property will be the argument value.
200
210
  attr_accessor :value_optional
201
211
  alias_method :value_optional?, :value_optional
202
212
 
@@ -205,6 +215,7 @@ module ArgParser
205
215
  # on a command-line using either a long form key (i.e. --key), or
206
216
  # optionally, a short-form key (i.e. -k) should one be defined for this
207
217
  # argument.
218
+ #
208
219
  # @param key [Symbol] the key that will be used to identify this argument
209
220
  # value in the parse results.
210
221
  # @param desc [String] the description of this argument, displayed in the
@@ -185,9 +185,13 @@ module ArgParser
185
185
  self.errors << "No value was specified for required argument '#{arg}'"
186
186
  return
187
187
  end
188
- if !is_default && val.nil? && KeywordArgument === arg && !arg.value_optional?
189
- self.errors << "No value was specified for keyword argument '#{arg}'"
190
- return
188
+ if !is_default && val.nil? && KeywordArgument === arg
189
+ if arg.value_optional?
190
+ val = arg.value_optional
191
+ else
192
+ self.errors << "No value was specified for keyword argument '#{arg}'"
193
+ return
194
+ end
191
195
  end
192
196
 
193
197
  # Argument value validation
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arg-parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Gardiner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-11 00:00:00.000000000 Z
11
+ date: 2015-02-25 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: ! " ArgParser is a simple, yet powerful command-line argument
14
14
  parser, with\n support for positional, keyword, flag and rest arguments,