rubysl-getoptlong 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3536cc041a64d512b90faa69b462239d59a7d76c
4
- data.tar.gz: 83ff9342026f92d5c9a5fc2ea5af625a1f6fc2b6
3
+ metadata.gz: 33eae63a1731a9502d501689c0f1d1ab36116bbe
4
+ data.tar.gz: 9e5df99b50bb9312fd49263c8047d4cf3fcf5152
5
5
  SHA512:
6
- metadata.gz: a479f266722fef5c6415da317ac4bd1c2dec4eea7c5d5862bf58c370652b1326ff7d613b611ca18f88b8d3321e73548a1a2854018cf322c28bc6257891b8a099
7
- data.tar.gz: c6a81a360957af20d366886f6691bcf784164e0aec3f8264c48f7848279b3d74156aa2e8461e982ac5da0f80b02ccce380dc34c1ff0d5210e315fc176c97c2b9
6
+ metadata.gz: 1e240bf44aef8bff5cc3826b00787062bd7d8467045af1ccabc7b783b5ce6addcace72bbf4d0d18ceb2ba20615f2f13645e8e910297010de42354f54cc61403e
7
+ data.tar.gz: d0118f759d0cceb310b673c2fb553fa54a12b6282582270f32953b4e7ea547554b3fcdd9ce258c6961ebd947332669c65e8ab813ef192e3db6e8153614ebc396
@@ -1,8 +1,6 @@
1
1
  language: ruby
2
- before_install:
3
- - gem update --system
4
- - gem --version
5
- - gem install rubysl-bundler
2
+ env:
3
+ - RUBYLIB=lib
6
4
  script: bundle exec mspec spec
7
5
  rvm:
8
- - rbx-nightly-18mode
6
+ - rbx-nightly-19mode
@@ -12,10 +12,10 @@
12
12
  # found at http://www.sra.co.jp/people/m-kasahr/ruby/getoptlong/
13
13
 
14
14
  # The GetoptLong class allows you to parse command line options similarly to
15
- # the GNU getopt_long() C library call. Note, however, that GetoptLong is a
15
+ # the GNU getopt_long() C library call. Note, however, that GetoptLong is a
16
16
  # pure Ruby implementation.
17
17
  #
18
- # GetoptLong allows for POSIX-style options like <tt>--file</tt> as well
18
+ # GetoptLong allows for POSIX-style options like <tt>--file</tt> as well
19
19
  # as single letter options like <tt>-f</tt>
20
20
  #
21
21
  # The empty option <tt>--</tt> (two minus symbols) is used to end option
@@ -24,41 +24,34 @@
24
24
  #
25
25
  # Here is a simple example of usage:
26
26
  #
27
- # # == Synopsis
28
- # #
29
- # # hello: greets user, demonstrates command line parsing
30
- # #
31
- # # == Usage
32
- # #
33
- # # hello [OPTION] ... DIR
34
- # #
35
- # # -h, --help:
36
- # # show help
37
- # #
38
- # # --repeat x, -n x:
39
- # # repeat x times
40
- # #
41
- # # --name [name]:
42
- # # greet user by name, if name not supplied default is John
43
- # #
44
- # # DIR: The directory in which to issue the greeting.
45
- #
46
27
  # require 'getoptlong'
47
- # require 'rdoc/usage'
48
- #
28
+ #
49
29
  # opts = GetoptLong.new(
50
30
  # [ '--help', '-h', GetoptLong::NO_ARGUMENT ],
51
31
  # [ '--repeat', '-n', GetoptLong::REQUIRED_ARGUMENT ],
52
32
  # [ '--name', GetoptLong::OPTIONAL_ARGUMENT ]
53
33
  # )
54
- #
34
+ #
55
35
  # dir = nil
56
36
  # name = nil
57
37
  # repetitions = 1
58
38
  # opts.each do |opt, arg|
59
39
  # case opt
60
40
  # when '--help'
61
- # RDoc::usage
41
+ # puts <<-EOF
42
+ # hello [OPTION] ... DIR
43
+ #
44
+ # -h, --help:
45
+ # show help
46
+ #
47
+ # --repeat x, -n x:
48
+ # repeat x times
49
+ #
50
+ # --name [name]:
51
+ # greet user by name, if name not supplied default is John
52
+ #
53
+ # DIR: The directory in which to issue the greeting.
54
+ # EOF
62
55
  # when '--repeat'
63
56
  # repetitions = arg.to_i
64
57
  # when '--name'
@@ -69,14 +62,14 @@
69
62
  # end
70
63
  # end
71
64
  # end
72
- #
65
+ #
73
66
  # if ARGV.length != 1
74
67
  # puts "Missing dir argument (try --help)"
75
68
  # exit 0
76
69
  # end
77
- #
70
+ #
78
71
  # dir = ARGV.shift
79
- #
72
+ #
80
73
  # Dir.chdir(dir)
81
74
  # for i in (1..repetitions)
82
75
  # print "Hello"
@@ -111,7 +104,7 @@ class GetoptLong
111
104
  # Error types.
112
105
  #
113
106
  class Error < StandardError; end
114
- class AmbigousOption < Error; end
107
+ class AmbiguousOption < Error; end
115
108
  class NeedlessArgument < Error; end
116
109
  class MissingArgument < Error; end
117
110
  class InvalidOption < Error; end
@@ -120,7 +113,7 @@ class GetoptLong
120
113
  # Set up option processing.
121
114
  #
122
115
  # The options to support are passed to new() as an array of arrays.
123
- # Each sub-array contains any number of String option names which carry
116
+ # Each sub-array contains any number of String option names which carry
124
117
  # the same meaning, and one of the following flags:
125
118
  #
126
119
  # GetoptLong::NO_ARGUMENT :: Option does not take an argument.
@@ -157,7 +150,7 @@ class GetoptLong
157
150
  @argument_flags = Hash.new
158
151
 
159
152
  #
160
- # Whether error messages are output to $deferr.
153
+ # Whether error messages are output to $stderr.
161
154
  #
162
155
  @quiet = FALSE
163
156
 
@@ -200,23 +193,23 @@ class GetoptLong
200
193
  # the processing of options as follows:
201
194
  #
202
195
  # <b>REQUIRE_ORDER</b> :
203
- #
196
+ #
204
197
  # Options are required to occur before non-options.
205
198
  #
206
199
  # Processing of options ends as soon as a word is encountered that has not
207
200
  # been preceded by an appropriate option flag.
208
201
  #
209
202
  # For example, if -a and -b are options which do not take arguments,
210
- # parsing command line arguments of '-a one -b two' would result in
211
- # 'one', '-b', 'two' being left in ARGV, and only ('-a', '') being
203
+ # parsing command line arguments of '-a one -b two' would result in
204
+ # 'one', '-b', 'two' being left in ARGV, and only ('-a', '') being
212
205
  # processed as an option/arg pair.
213
206
  #
214
207
  # This is the default ordering, if the environment variable
215
208
  # POSIXLY_CORRECT is set. (This is for compatibility with GNU getopt_long.)
216
209
  #
217
210
  # <b>PERMUTE</b> :
218
- #
219
- # Options can occur anywhere in the command line parsed. This is the
211
+ #
212
+ # Options can occur anywhere in the command line parsed. This is the
220
213
  # default behavior.
221
214
  #
222
215
  # Every sequence of words which can be interpreted as an option (with or
@@ -233,7 +226,7 @@ class GetoptLong
233
226
  #
234
227
  # <b>RETURN_IN_ORDER</b> :
235
228
  #
236
- # All words on the command line are processed as options. Words not
229
+ # All words on the command line are processed as options. Words not
237
230
  # preceded by a short or long option flag are passed as arguments
238
231
  # with an option of '' (empty string).
239
232
  #
@@ -248,7 +241,7 @@ class GetoptLong
248
241
  if @status != STATUS_YET
249
242
  set_error(ArgumentError, "argument error")
250
243
  raise RuntimeError,
251
- "invoke ordering=, but option processing has already started"
244
+ "invoke ordering=, but option processing has already started"
252
245
  end
253
246
 
254
247
  #
@@ -279,8 +272,8 @@ class GetoptLong
279
272
  # The method is failed if option processing has already started.
280
273
  #
281
274
  if @status != STATUS_YET
282
- raise RuntimeError,
283
- "invoke set_options, but option processing has already started"
275
+ raise RuntimeError,
276
+ "invoke set_options, but option processing has already started"
284
277
  end
285
278
 
286
279
  #
@@ -290,11 +283,8 @@ class GetoptLong
290
283
  @argument_flags.clear
291
284
 
292
285
  arguments.each do |arg|
293
- #
294
- # Each argument must be an Array.
295
- #
296
286
  if !arg.is_a?(Array)
297
- raise ArgumentError, "the option list contains non-Array argument"
287
+ raise ArgumentError, "the option list contains non-Array argument"
298
288
  end
299
289
 
300
290
  #
@@ -302,43 +292,44 @@ class GetoptLong
302
292
  #
303
293
  argument_flag = nil
304
294
  arg.each do |i|
305
- if ARGUMENT_FLAGS.include?(i)
306
- if argument_flag != nil
307
- raise ArgumentError, "too many argument-flags"
308
- end
309
- argument_flag = i
310
- end
295
+ if ARGUMENT_FLAGS.include?(i)
296
+ if argument_flag != nil
297
+ raise ArgumentError, "too many argument-flags"
298
+ end
299
+ argument_flag = i
300
+ end
311
301
  end
302
+
312
303
  raise ArgumentError, "no argument-flag" if argument_flag == nil
313
304
 
314
305
  canonical_name = nil
315
306
  arg.each do |i|
316
- #
317
- # Check an option name.
318
- #
319
- next if i == argument_flag
320
- begin
321
- if !i.is_a?(String) || i !~ /^-([^-]|-.+)$/
322
- raise ArgumentError, "an invalid option `#{i}'"
323
- end
324
- if (@canonical_names.include?(i))
325
- raise ArgumentError, "option redefined `#{i}'"
326
- end
327
- rescue
328
- @canonical_names.clear
329
- @argument_flags.clear
330
- raise
331
- end
332
-
333
- #
334
- # Register the option (`i') to the `@canonical_names' and
335
- # `@canonical_names' Hashes.
336
- #
337
- if canonical_name == nil
338
- canonical_name = i
339
- end
340
- @canonical_names[i] = canonical_name
341
- @argument_flags[i] = argument_flag
307
+ #
308
+ # Check an option name.
309
+ #
310
+ next if i == argument_flag
311
+ begin
312
+ if !i.is_a?(String) || i !~ /^-([^-]|-.+)$/
313
+ raise ArgumentError, "an invalid option `#{i}'"
314
+ end
315
+ if (@canonical_names.include?(i))
316
+ raise ArgumentError, "option redefined `#{i}'"
317
+ end
318
+ rescue
319
+ @canonical_names.clear
320
+ @argument_flags.clear
321
+ raise
322
+ end
323
+
324
+ #
325
+ # Register the option (`i') to the `@canonical_names' and
326
+ # `@canonical_names' Hashes.
327
+ #
328
+ if canonical_name == nil
329
+ canonical_name = i
330
+ end
331
+ @canonical_names[i] = canonical_name
332
+ @argument_flags[i] = argument_flag
342
333
  end
343
334
  raise ArgumentError, "no option name" if canonical_name == nil
344
335
  end
@@ -388,10 +379,10 @@ class GetoptLong
388
379
  end
389
380
 
390
381
  #
391
- # Set an error (protected).
382
+ # Set an error (a protected method).
392
383
  #
393
384
  def set_error(type, message)
394
- $deferr.print("#{$0}: #{message}\n") if !@quiet
385
+ $stderr.print("#{$0}: #{message}\n") if !@quiet
395
386
 
396
387
  @error = type
397
388
  @error_message = message
@@ -456,17 +447,17 @@ class GetoptLong
456
447
  return nil
457
448
  elsif @ordering == PERMUTE
458
449
  while 0 < ARGV.length && ARGV[0] !~ /^-./
459
- @non_option_arguments.push(ARGV.shift)
450
+ @non_option_arguments.push(ARGV.shift)
460
451
  end
461
452
  if ARGV.length == 0
462
- terminate
463
- return nil
453
+ terminate
454
+ return nil
464
455
  end
465
456
  argument = ARGV.shift
466
- elsif @ordering == REQUIRE_ORDER
457
+ elsif @ordering == REQUIRE_ORDER
467
458
  if (ARGV[0] !~ /^-./)
468
- terminate
469
- return nil
459
+ terminate
460
+ return nil
470
461
  end
471
462
  argument = ARGV.shift
472
463
  else
@@ -491,49 +482,49 @@ class GetoptLong
491
482
  #
492
483
  pattern = $1
493
484
  if @canonical_names.include?(pattern)
494
- option_name = pattern
485
+ option_name = pattern
495
486
  else
496
- #
497
- # The option `option_name' is not registered in `@canonical_names'.
498
- # It may be an abbreviated.
499
- #
500
- match_count = 0
501
- @canonical_names.each_key do |key|
502
- if key.index(pattern) == 0
503
- option_name = key
504
- match_count += 1
505
- end
506
- end
507
- if 2 <= match_count
508
- set_error(AmbigousOption, "option `#{argument}' is ambiguous")
509
- elsif match_count == 0
510
- set_error(InvalidOption, "unrecognized option `#{argument}'")
511
- end
487
+ #
488
+ # The option `option_name' is not registered in `@canonical_names'.
489
+ # It may be an abbreviated.
490
+ #
491
+ matches = []
492
+ @canonical_names.each_key do |key|
493
+ if key.index(pattern) == 0
494
+ option_name = key
495
+ matches << key
496
+ end
497
+ end
498
+ if 2 <= matches.length
499
+ set_error(AmbiguousOption, "option `#{argument}' is ambiguous between #{matches.join(', ')}")
500
+ elsif matches.length == 0
501
+ set_error(InvalidOption, "unrecognized option `#{argument}'")
502
+ end
512
503
  end
513
504
 
514
505
  #
515
506
  # Check an argument to the option.
516
507
  #
517
508
  if @argument_flags[option_name] == REQUIRED_ARGUMENT
518
- if argument =~ /=(.*)$/
519
- option_argument = $1
520
- elsif 0 < ARGV.length
521
- option_argument = ARGV.shift
522
- else
523
- set_error(MissingArgument,
524
- "option `#{argument}' requires an argument")
525
- end
509
+ if argument =~ /=(.*)$/
510
+ option_argument = $1
511
+ elsif 0 < ARGV.length
512
+ option_argument = ARGV.shift
513
+ else
514
+ set_error(MissingArgument,
515
+ "option `#{argument}' requires an argument")
516
+ end
526
517
  elsif @argument_flags[option_name] == OPTIONAL_ARGUMENT
527
- if argument =~ /=(.*)$/
528
- option_argument = $1
529
- elsif 0 < ARGV.length && ARGV[0] !~ /^-./
530
- option_argument = ARGV.shift
531
- else
532
- option_argument = ''
533
- end
518
+ if argument =~ /=(.*)$/
519
+ option_argument = $1
520
+ elsif 0 < ARGV.length && ARGV[0] !~ /^-./
521
+ option_argument = ARGV.shift
522
+ else
523
+ option_argument = ''
524
+ end
534
525
  elsif argument =~ /=(.*)$/
535
- set_error(NeedlessArgument,
536
- "option `#{option_name}' doesn't allow an argument")
526
+ set_error(NeedlessArgument,
527
+ "option `#{option_name}' doesn't allow an argument")
537
528
  end
538
529
 
539
530
  elsif argument =~ /^(-(.))(.*)/
@@ -545,40 +536,40 @@ class GetoptLong
545
536
  option_name, ch, @rest_singles = $1, $2, $3
546
537
 
547
538
  if @canonical_names.include?(option_name)
548
- #
549
- # The option `option_name' is found in `@canonical_names'.
550
- # Check its argument.
551
- #
552
- if @argument_flags[option_name] == REQUIRED_ARGUMENT
553
- if 0 < @rest_singles.length
554
- option_argument = @rest_singles
555
- @rest_singles = ''
556
- elsif 0 < ARGV.length
557
- option_argument = ARGV.shift
558
- else
559
- # 1003.2 specifies the format of this message.
560
- set_error(MissingArgument, "option requires an argument -- #{ch}")
561
- end
562
- elsif @argument_flags[option_name] == OPTIONAL_ARGUMENT
563
- if 0 < @rest_singles.length
564
- option_argument = @rest_singles
565
- @rest_singles = ''
566
- elsif 0 < ARGV.length && ARGV[0] !~ /^-./
567
- option_argument = ARGV.shift
568
- else
569
- option_argument = ''
570
- end
571
- end
539
+ #
540
+ # The option `option_name' is found in `@canonical_names'.
541
+ # Check its argument.
542
+ #
543
+ if @argument_flags[option_name] == REQUIRED_ARGUMENT
544
+ if 0 < @rest_singles.length
545
+ option_argument = @rest_singles
546
+ @rest_singles = ''
547
+ elsif 0 < ARGV.length
548
+ option_argument = ARGV.shift
549
+ else
550
+ # 1003.2 specifies the format of this message.
551
+ set_error(MissingArgument, "option requires an argument -- #{ch}")
552
+ end
553
+ elsif @argument_flags[option_name] == OPTIONAL_ARGUMENT
554
+ if 0 < @rest_singles.length
555
+ option_argument = @rest_singles
556
+ @rest_singles = ''
557
+ elsif 0 < ARGV.length && ARGV[0] !~ /^-./
558
+ option_argument = ARGV.shift
559
+ else
560
+ option_argument = ''
561
+ end
562
+ end
572
563
  else
573
- #
574
- # This is an invalid option.
575
- # 1003.2 specifies the format of this message.
576
- #
577
- if ENV.include?('POSIXLY_CORRECT')
578
- set_error(InvalidOption, "illegal option -- #{ch}")
579
- else
580
- set_error(InvalidOption, "invalid option -- #{ch}")
581
- end
564
+ #
565
+ # This is an invalid option.
566
+ # 1003.2 specifies the format of this message.
567
+ #
568
+ if ENV.include?('POSIXLY_CORRECT')
569
+ set_error(InvalidOption, "invalid option -- #{ch}")
570
+ else
571
+ set_error(InvalidOption, "invalid option -- #{ch}")
572
+ end
582
573
  end
583
574
  else
584
575
  #
@@ -600,7 +591,7 @@ class GetoptLong
600
591
  #
601
592
  # The block is called repeatedly with two arguments:
602
593
  # The first is the option name.
603
- # The second is the argument which followed it (if any).
594
+ # The second is the argument which followed it (if any).
604
595
  # Example: ('--opt', 'value')
605
596
  #
606
597
  # The option name is always converted to the first (preferred)
@@ -1,5 +1,5 @@
1
1
  module RubySL
2
- module GetoptLong
3
- VERSION = "1.0.0"
2
+ class GetoptLong
3
+ VERSION = "2.0.0"
4
4
  end
5
5
  end
@@ -19,5 +19,4 @@ Gem::Specification.new do |spec|
19
19
  spec.add_development_dependency "bundler", "~> 1.3"
20
20
  spec.add_development_dependency "rake", "~> 10.0"
21
21
  spec.add_development_dependency "mspec", "~> 1.5"
22
- spec.add_development_dependency "rubysl-prettyprint", "~> 1.0"
23
22
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubysl-getoptlong
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Shirai
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-26 00:00:00.000000000 Z
11
+ date: 2013-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,20 +52,6 @@ dependencies:
52
52
  - - ~>
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.5'
55
- - !ruby/object:Gem::Dependency
56
- name: rubysl-prettyprint
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ~>
60
- - !ruby/object:Gem::Version
61
- version: '1.0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ~>
67
- - !ruby/object:Gem::Version
68
- version: '1.0'
69
55
  description: Ruby standard library getoptlong.
70
56
  email:
71
57
  - brixen@gmail.com
@@ -133,3 +119,4 @@ test_files:
133
119
  - spec/shared/get.rb
134
120
  - spec/terminate_spec.rb
135
121
  - spec/terminated_spec.rb
122
+ has_rdoc: