arg-parser 0.1 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ M2JiZDNjZTA3NTZiNWE0ZmE2ZDI5M2VkMzY4NjEwZWEwMWMxMDRiNg==
5
+ data.tar.gz: !binary |-
6
+ N2QwNjcyMWE5MzQ2MTk4MDFmNmFmZGZiNjk4ZTFiMmJiODY5ZWFmNg==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ ZjIxZWEzM2ZlNzdiMmZlODBmYWMwYzI3ODQ2MTA3NWVhYjEwZjBhYTFjNzkz
10
+ MDNhZDA5YmQzMTM4ODg4MmE2YzUyYjBmNjNmNTZiZWJiNWU2ZmViZWQ2MjJl
11
+ OTAyYjg2Njg5ZTIzZTQ3ZGM3MTg4YzM3ZjZjYzVmNGIxNzRhY2I=
12
+ data.tar.gz: !binary |-
13
+ MjgyMmQxMmRmMjViN2YyNWJmMGY5MTIzZDIyYTk0MzQ0N2MzYzkwYzY5NTJj
14
+ NmExMzE4Yjg4ODkxZGUyMDZmODUyYWIzZGFhYjUxZTBjNGRiYzJhMTNjNDAz
15
+ MGZjNTExNGU2MTJjZjIwODgzOTAyZTBjY2IxMzI1Yjc2MWVmZTY=
@@ -57,7 +57,8 @@ module ArgParser
57
57
  # @return [Symbol] the key by which an argument can be retrieved from
58
58
  # the arguments definition, and the parse results.
59
59
  def self.to_key(label)
60
- label.to_s.gsub(/^-+/, '').gsub('-', '_').downcase.intern
60
+ k = label.to_s.gsub(/^-+/, '').gsub('-', '_')
61
+ k.length > 1 ? k.downcase.intern : k.intern
61
62
  end
62
63
 
63
64
 
@@ -31,7 +31,7 @@ module ArgParser
31
31
  # if it does not.
32
32
  def has_key?(key)
33
33
  k = Argument.to_key(key)
34
- arg = @arguments[k] || @short_keys[k]
34
+ @arguments[k] || @short_keys[k]
35
35
  end
36
36
 
37
37
 
@@ -46,6 +46,12 @@ module ArgParser
46
46
  @args_def && @args_def.args.size > 0
47
47
  end
48
48
 
49
+ # Registers the supplied +block+ as an on_parse handler that can be
50
+ # attached to an argument using +key+.
51
+ def register_parse_handler(key, &block)
52
+ ArgParser::OnParseHandlers[key] = block
53
+ end
54
+
49
55
  # Sets the title that will appear in the Usage output generated from
50
56
  # the Definition.
51
57
  def title(val)
@@ -61,27 +67,41 @@ module ArgParser
61
67
  # Define a new positional argument.
62
68
  # @see PositionalArgument#initialize
63
69
  def positional_arg(key, desc, opts = {}, &block)
70
+ opts.merge!(@arg_opts){ |k, e, n| e || n } if @arg_opts
71
+ @arg_opts = nil
64
72
  args_def.positional_arg(key, desc, opts, &block)
65
73
  end
66
74
 
67
75
  # Define a new positional argument.
68
76
  # @see KeywordArgument#initialize
69
77
  def keyword_arg(key, desc, opts = {}, &block)
78
+ opts.merge!(@arg_opts){ |k, e, n| e || n } if @arg_opts
79
+ @arg_opts = nil
70
80
  args_def.keyword_arg(key, desc, opts, &block)
71
81
  end
72
82
 
73
83
  # Define a new flag argument.
74
84
  # @see FlagArgument#initialize
75
85
  def flag_arg(key, desc, opts = {}, &block)
86
+ opts.merge!(@arg_opts){ |k, e, n| e || n } if @arg_opts
87
+ @arg_opts = nil
76
88
  args_def.flag_arg(key, desc, opts, &block)
77
89
  end
78
90
 
79
91
  # Define a rest argument.
80
92
  # @see RestArgument#initialize
81
93
  def rest_arg(key, desc, opts = {}, &block)
94
+ opts.merge!(@arg_opts){ |k, e, n| e || n } if @arg_opts
95
+ @arg_opts = nil
82
96
  args_def.rest_arg(key, desc, opts, &block)
83
97
  end
84
98
 
99
+ # Set a label for a usage break to be applied on the next argument
100
+ # that is defined.
101
+ def usage_break(label)
102
+ @arg_opts = {usage_break: label}
103
+ end
104
+
85
105
  # Make exactly one of the specified arguments mandatory.
86
106
  # @see Definition#require_one_of
87
107
  def require_one_of(*keys)
@@ -131,7 +151,7 @@ module ArgParser
131
151
 
132
152
  # Whether help should be displayed.
133
153
  def show_help?
134
- args_def.show_usage?
154
+ args_def.show_help?
135
155
  end
136
156
 
137
157
 
@@ -149,8 +149,8 @@ module ArgParser
149
149
  end
150
150
 
151
151
  # Process rest values
152
- if arg = @definition.rest_args
153
- result[arg.key] = process_arg_val(arg, rest_vals, result)
152
+ if rest_arg = @definition.rest_args
153
+ result[rest_arg.key] = process_arg_val(rest_arg, rest_vals, result)
154
154
  elsif rest_vals.size > 0
155
155
  self.errors << "#{rest_vals.size} rest #{rest_vals.size == 1 ? 'value' : 'values'} #{
156
156
  rest_vals.size == 1 ? 'was' : 'were'} supplied, but no rest argument is defined"
@@ -190,7 +190,7 @@ module ArgParser
190
190
 
191
191
  # Argument value validation
192
192
  if ValueArgument === arg && arg.validation && val
193
- valid = case arg.validation
193
+ case arg.validation
194
194
  when Regexp
195
195
  [val].flatten.each do |v|
196
196
  add_value_error(arg, val) unless v =~ arg.validation
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arg-parser
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
5
- prerelease:
4
+ version: 0.2.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: 2013-05-21 00:00:00.000000000 Z
11
+ date: 2013-08-11 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description: ! " ArgParser is a simple, yet powerful command-line argument
15
14
  parser, with\n support for positional, keyword, flag and rest arguments,
@@ -19,36 +18,35 @@ executables: []
19
18
  extensions: []
20
19
  extra_rdoc_files: []
21
20
  files:
22
- - README.md
23
21
  - LICENSE
22
+ - README.md
23
+ - lib/arg-parser.rb
24
24
  - lib/arg-parser/argument.rb
25
25
  - lib/arg-parser/definition.rb
26
26
  - lib/arg-parser/dsl.rb
27
27
  - lib/arg-parser/parser.rb
28
- - lib/arg-parser.rb
29
28
  - lib/arg_parser.rb
30
29
  homepage: https://github.com/agardiner/arg-parser
31
30
  licenses: []
31
+ metadata: {}
32
32
  post_install_message:
33
33
  rdoc_options: []
34
34
  require_paths:
35
35
  - lib
36
36
  required_ruby_version: !ruby/object:Gem::Requirement
37
- none: false
38
37
  requirements:
39
38
  - - ! '>='
40
39
  - !ruby/object:Gem::Version
41
40
  version: '0'
42
41
  required_rubygems_version: !ruby/object:Gem::Requirement
43
- none: false
44
42
  requirements:
45
43
  - - ! '>='
46
44
  - !ruby/object:Gem::Version
47
45
  version: '0'
48
46
  requirements: []
49
47
  rubyforge_project:
50
- rubygems_version: 1.8.21
48
+ rubygems_version: 2.4.1
51
49
  signing_key:
52
- specification_version: 3
50
+ specification_version: 4
53
51
  summary: ArgParser is a simple, yet powerful, command-line argument (option) parser
54
52
  test_files: []