arg-parser 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9b0c2c32a741e3751760248db85d2cc4e1a47288
4
+ data.tar.gz: cbd2b833b43077480b73e932bdf45168c52d8d04
5
+ SHA512:
6
+ metadata.gz: 571fb0dda1c9f9b9162fe126da1795c22db68e3ae2732b6b66db0fbe87466cd617f8fb7a413f44b30ad21e47aa2d22b563030e4133151509766a49ad4506bd33
7
+ data.tar.gz: 1dd67d98bedea2a677490e999fc9db92ee5c29ab1099740f4a0f828a33938ae4640220436140b247f72fdcc09c9361833df921a20b23f36fe389a515ff05877d
@@ -55,7 +55,8 @@ module ArgParser
55
55
  raise ArgumentError, "An argument with key '#{arg.key}' has already been defined"
56
56
  end
57
57
  if arg.short_key && @short_keys[arg.short_key]
58
- raise ArgumentError, "An argument with short key '#{arg.short_key}' has already been defined"
58
+ raise ArgumentError, "The short key '#{arg.short_key}' has already been registered by the '#{
59
+ @short_keys[arg.short_key]}' argument"
59
60
  end
60
61
  if arg.is_a?(RestArgument) && rest_args
61
62
  raise ArgumentError, "Only one rest argument can be defined"
@@ -224,6 +225,18 @@ module ArgParser
224
225
  end
225
226
 
226
227
 
228
+ # @return [Array] all argument keys that have been defined.
229
+ def keys
230
+ @arguments.keys
231
+ end
232
+
233
+
234
+ # @return [Array] all argument short keys that have been defined.
235
+ def short_keys
236
+ @short_keys.keys
237
+ end
238
+
239
+
227
240
  # @return [Array] all arguments that have been defined.
228
241
  def args
229
242
  @arguments.values
@@ -133,6 +133,7 @@ module ArgParser
133
133
  # the DSL ClassMethods module.
134
134
  def self.included(base)
135
135
  base.extend(ClassMethods)
136
+ base.title base.class.name
136
137
  end
137
138
 
138
139
  # @return [Definition] The arguments Definition object defined on this
@@ -3,6 +3,11 @@ module ArgParser
3
3
  # Parser for parsing a command-line
4
4
  class Parser
5
5
 
6
+ # Create an empty structure for cases where we parse an empty arguments
7
+ # definition (and therefore need to return an empty Struct)
8
+ EmptyArgs = Struct.new(nil)
9
+
10
+
6
11
  # @return [Definition] The supported Arguments to be used when parsing
7
12
  # the command-line.
8
13
  attr_reader :definition
@@ -85,7 +90,7 @@ module ArgParser
85
90
  case token
86
91
  when '/?', '-?', '--help'
87
92
  @show_help = true
88
- when /^-([a-z0-9]+)/i
93
+ when /^[-\/]([a-z0-9]+)$/i
89
94
  $1.to_s.each_char do |sk|
90
95
  kw_vals[arg] = nil if arg
91
96
  arg = @definition[sk]
@@ -94,7 +99,7 @@ module ArgParser
94
99
  arg = nil
95
100
  end
96
101
  end
97
- when /^(?:--|\/)(no-)?(.+)/i
102
+ when /^--(no-)?(.+)/i
98
103
  kw_vals[arg] = nil if arg
99
104
  arg = @definition[$2]
100
105
  if FlagArgument === arg || (KeywordArgument === arg && $1)
@@ -166,7 +171,7 @@ module ArgParser
166
171
  if self.errors.size > 0
167
172
  @show_usage = true
168
173
  elsif result.empty?
169
- BasicObject.new
174
+ EmptyArgs.new
170
175
  else
171
176
  props = result.keys
172
177
  @definition.args.each{ |arg| props << arg.key unless result.has_key?(arg.key) }
metadata CHANGED
@@ -1,19 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arg-parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
5
- prerelease:
4
+ version: 0.3.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Adam Gardiner
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2015-05-29 00:00:00.000000000 Z
11
+ date: 2017-09-13 00:00:00.000000000 Z
13
12
  dependencies: []
14
- description: ! " ArgParser is a simple, yet powerful command-line argument
15
- parser, with\n support for positional, keyword, flag and rest arguments,
16
- any of which\n may be optional or mandatory.\n"
13
+ description: |2
14
+ ArgParser is a simple, yet powerful command-line argument parser, with
15
+ support for positional, keyword, flag and rest arguments, any of which
16
+ may be optional or mandatory.
17
17
  email: adam.b.gardiner@gmail.com
18
18
  executables: []
19
19
  extensions: []
@@ -29,26 +29,25 @@ files:
29
29
  - lib/arg_parser.rb
30
30
  homepage: https://github.com/agardiner/arg-parser
31
31
  licenses: []
32
+ metadata: {}
32
33
  post_install_message:
33
34
  rdoc_options: []
34
35
  require_paths:
35
36
  - lib
36
37
  required_ruby_version: !ruby/object:Gem::Requirement
37
- none: false
38
38
  requirements:
39
- - - ! '>='
39
+ - - '>='
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
42
  required_rubygems_version: !ruby/object:Gem::Requirement
43
- none: false
44
43
  requirements:
45
- - - ! '>='
44
+ - - '>='
46
45
  - !ruby/object:Gem::Version
47
46
  version: '0'
48
47
  requirements: []
49
48
  rubyforge_project:
50
- rubygems_version: 1.8.21
49
+ rubygems_version: 2.0.14.1
51
50
  signing_key:
52
- specification_version: 3
51
+ specification_version: 4
53
52
  summary: ArgParser is a simple, yet powerful, command-line argument (option) parser
54
53
  test_files: []