optparse 0.1.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ChangeLog +277 -0
- data/doc/optparse/argument_converters.rdoc +380 -0
- data/doc/optparse/creates_option.rdoc +7 -0
- data/doc/optparse/option_params.rdoc +509 -0
- data/doc/optparse/ruby/argument_keywords.rb +6 -0
- data/doc/optparse/ruby/argument_strings.rb +6 -0
- data/doc/optparse/ruby/argv.rb +2 -0
- data/doc/optparse/ruby/array.rb +6 -0
- data/doc/optparse/ruby/basic.rb +17 -0
- data/doc/optparse/ruby/block.rb +9 -0
- data/doc/optparse/ruby/collected_options.rb +8 -0
- data/doc/optparse/ruby/custom_converter.rb +9 -0
- data/doc/optparse/ruby/date.rb +6 -0
- data/doc/optparse/ruby/datetime.rb +6 -0
- data/doc/optparse/ruby/decimal_integer.rb +7 -0
- data/doc/optparse/ruby/decimal_numeric.rb +7 -0
- data/doc/optparse/ruby/default_values.rb +8 -0
- data/doc/optparse/ruby/descriptions.rb +15 -0
- data/doc/optparse/ruby/explicit_array_values.rb +9 -0
- data/doc/optparse/ruby/explicit_hash_values.rb +9 -0
- data/doc/optparse/ruby/false_class.rb +6 -0
- data/doc/optparse/ruby/float.rb +6 -0
- data/doc/optparse/ruby/help.rb +18 -0
- data/doc/optparse/ruby/help_banner.rb +7 -0
- data/doc/optparse/ruby/help_format.rb +25 -0
- data/doc/optparse/ruby/help_program_name.rb +7 -0
- data/doc/optparse/ruby/integer.rb +6 -0
- data/doc/optparse/ruby/long_names.rb +9 -0
- data/doc/optparse/ruby/long_optional.rb +6 -0
- data/doc/optparse/ruby/long_required.rb +6 -0
- data/doc/optparse/ruby/long_simple.rb +9 -0
- data/doc/optparse/ruby/long_with_negation.rb +6 -0
- data/doc/optparse/ruby/match_converter.rb +9 -0
- data/doc/optparse/ruby/matched_values.rb +6 -0
- data/doc/optparse/ruby/method.rb +11 -0
- data/doc/optparse/ruby/missing_options.rb +12 -0
- data/doc/optparse/ruby/mixed_names.rb +12 -0
- data/doc/optparse/ruby/name_abbrev.rb +9 -0
- data/doc/optparse/ruby/no_abbreviation.rb +10 -0
- data/doc/optparse/ruby/numeric.rb +6 -0
- data/doc/optparse/ruby/object.rb +6 -0
- data/doc/optparse/ruby/octal_integer.rb +7 -0
- data/doc/optparse/ruby/optional_argument.rb +9 -0
- data/doc/optparse/ruby/parse.rb +13 -0
- data/doc/optparse/ruby/parse_bang.rb +13 -0
- data/doc/optparse/ruby/proc.rb +13 -0
- data/doc/optparse/ruby/regexp.rb +6 -0
- data/doc/optparse/ruby/required_argument.rb +9 -0
- data/doc/optparse/ruby/shellwords.rb +6 -0
- data/doc/optparse/ruby/short_names.rb +9 -0
- data/doc/optparse/ruby/short_optional.rb +6 -0
- data/doc/optparse/ruby/short_range.rb +6 -0
- data/doc/optparse/ruby/short_required.rb +6 -0
- data/doc/optparse/ruby/short_simple.rb +9 -0
- data/doc/optparse/ruby/string.rb +6 -0
- data/doc/optparse/ruby/terminator.rb +6 -0
- data/doc/optparse/ruby/time.rb +6 -0
- data/doc/optparse/ruby/true_class.rb +6 -0
- data/doc/optparse/ruby/uri.rb +6 -0
- data/doc/optparse/tutorial.rdoc +835 -0
- data/lib/optparse/ac.rb +1 -1
- data/lib/optparse/date.rb +1 -1
- data/lib/optparse/kwargs.rb +3 -1
- data/lib/optparse/shellwords.rb +1 -1
- data/lib/optparse/time.rb +1 -1
- data/lib/optparse/uri.rb +1 -1
- data/lib/optparse.rb +124 -83
- metadata +67 -9
- data/Rakefile +0 -10
- data/optparse.gemspec +0 -33
- data/rakelib/changelogs.rake +0 -34
- data/rakelib/epoch.rake +0 -5
- data/rakelib/version.rake +0 -47
data/lib/optparse/ac.rb
CHANGED
data/lib/optparse/date.rb
CHANGED
data/lib/optparse/kwargs.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
2
|
+
require_relative '../optparse'
|
3
3
|
|
4
4
|
class OptionParser
|
5
5
|
# :call-seq:
|
6
6
|
# define_by_keywords(options, method, **params)
|
7
7
|
#
|
8
|
+
# :include: ../../doc/optparse/creates_option.rdoc
|
9
|
+
#
|
8
10
|
def define_by_keywords(options, meth, **opts)
|
9
11
|
meth.parameters.each do |type, name|
|
10
12
|
case type
|
data/lib/optparse/shellwords.rb
CHANGED
data/lib/optparse/time.rb
CHANGED
data/lib/optparse/uri.rb
CHANGED
data/lib/optparse.rb
CHANGED
@@ -48,6 +48,10 @@
|
|
48
48
|
#
|
49
49
|
# == OptionParser
|
50
50
|
#
|
51
|
+
# === New to \OptionParser?
|
52
|
+
#
|
53
|
+
# See the {Tutorial}[optparse/tutorial.rdoc].
|
54
|
+
#
|
51
55
|
# === Introduction
|
52
56
|
#
|
53
57
|
# OptionParser is a class for command-line option analysis. It is much more
|
@@ -240,14 +244,14 @@
|
|
240
244
|
#
|
241
245
|
# require 'optparse'
|
242
246
|
#
|
243
|
-
#
|
247
|
+
# options = {}
|
244
248
|
# OptionParser.new do |parser|
|
245
249
|
# parser.on('-a')
|
246
250
|
# parser.on('-b NUM', Integer)
|
247
251
|
# parser.on('-v', '--verbose')
|
248
|
-
# end.parse!(into:
|
252
|
+
# end.parse!(into: options)
|
249
253
|
#
|
250
|
-
# p
|
254
|
+
# p options
|
251
255
|
#
|
252
256
|
# Used:
|
253
257
|
#
|
@@ -415,11 +419,13 @@
|
|
415
419
|
#
|
416
420
|
# === Further documentation
|
417
421
|
#
|
418
|
-
# The above examples
|
419
|
-
#
|
422
|
+
# The above examples, along with the accompanying
|
423
|
+
# {Tutorial}[optparse/tutorial.rdoc],
|
424
|
+
# should be enough to learn how to use this class.
|
425
|
+
# If you have any questions, file a ticket at http://bugs.ruby-lang.org.
|
420
426
|
#
|
421
427
|
class OptionParser
|
422
|
-
OptionParser::Version = "0.
|
428
|
+
OptionParser::Version = "0.3.0"
|
423
429
|
|
424
430
|
# :stopdoc:
|
425
431
|
NoArgument = [NO_ARGUMENT = :NONE, nil].freeze
|
@@ -547,7 +553,7 @@ class OptionParser
|
|
547
553
|
# Parses +arg+ and returns rest of +arg+ and matched portion to the
|
548
554
|
# argument pattern. Yields when the pattern doesn't match substring.
|
549
555
|
#
|
550
|
-
def parse_arg(arg)
|
556
|
+
def parse_arg(arg) # :nodoc:
|
551
557
|
pattern or return nil, [arg]
|
552
558
|
unless m = pattern.match(arg)
|
553
559
|
yield(InvalidArgument, arg)
|
@@ -572,7 +578,7 @@ class OptionParser
|
|
572
578
|
# conversion. Yields at semi-error condition instead of raising an
|
573
579
|
# exception.
|
574
580
|
#
|
575
|
-
def conv_arg(arg, val = [])
|
581
|
+
def conv_arg(arg, val = []) # :nodoc:
|
576
582
|
if conv
|
577
583
|
val = conv.call(*val)
|
578
584
|
else
|
@@ -668,6 +674,29 @@ class OptionParser
|
|
668
674
|
end
|
669
675
|
end
|
670
676
|
|
677
|
+
def pretty_print_contents(q) # :nodoc:
|
678
|
+
if @block
|
679
|
+
q.text ":" + @block.source_location.join(":") + ":"
|
680
|
+
first = false
|
681
|
+
else
|
682
|
+
first = true
|
683
|
+
end
|
684
|
+
[@short, @long].each do |list|
|
685
|
+
list.each do |opt|
|
686
|
+
if first
|
687
|
+
q.text ":"
|
688
|
+
first = false
|
689
|
+
end
|
690
|
+
q.breakable
|
691
|
+
q.text opt
|
692
|
+
end
|
693
|
+
end
|
694
|
+
end
|
695
|
+
|
696
|
+
def pretty_print(q) # :nodoc:
|
697
|
+
q.object_group(self) {pretty_print_contents(q)}
|
698
|
+
end
|
699
|
+
|
671
700
|
#
|
672
701
|
# Switch that takes no arguments.
|
673
702
|
#
|
@@ -687,6 +716,10 @@ class OptionParser
|
|
687
716
|
def self.pattern
|
688
717
|
Object
|
689
718
|
end
|
719
|
+
|
720
|
+
def pretty_head # :nodoc:
|
721
|
+
"NoArgument"
|
722
|
+
end
|
690
723
|
end
|
691
724
|
|
692
725
|
#
|
@@ -704,6 +737,10 @@ class OptionParser
|
|
704
737
|
end
|
705
738
|
conv_arg(*parse_arg(arg, &method(:raise)))
|
706
739
|
end
|
740
|
+
|
741
|
+
def pretty_head # :nodoc:
|
742
|
+
"Required"
|
743
|
+
end
|
707
744
|
end
|
708
745
|
|
709
746
|
#
|
@@ -721,18 +758,22 @@ class OptionParser
|
|
721
758
|
conv_arg(arg)
|
722
759
|
end
|
723
760
|
end
|
761
|
+
|
762
|
+
def pretty_head # :nodoc:
|
763
|
+
"Optional"
|
764
|
+
end
|
724
765
|
end
|
725
766
|
|
726
767
|
#
|
727
|
-
# Switch that takes an argument, which does not begin with '-'.
|
768
|
+
# Switch that takes an argument, which does not begin with '-' or is '-'.
|
728
769
|
#
|
729
770
|
class PlacedArgument < self
|
730
771
|
|
731
772
|
#
|
732
|
-
# Returns nil if argument is not present or begins with '-'.
|
773
|
+
# Returns nil if argument is not present or begins with '-' and is not '-'.
|
733
774
|
#
|
734
775
|
def parse(arg, argv, &error)
|
735
|
-
if !(val = arg) and (argv.empty? or /\A
|
776
|
+
if !(val = arg) and (argv.empty? or /\A-./ =~ (val = argv[0]))
|
736
777
|
return nil, block, nil
|
737
778
|
end
|
738
779
|
opt = (val = parse_arg(val, &error))[1]
|
@@ -744,6 +785,10 @@ class OptionParser
|
|
744
785
|
end
|
745
786
|
val
|
746
787
|
end
|
788
|
+
|
789
|
+
def pretty_head # :nodoc:
|
790
|
+
"Placed"
|
791
|
+
end
|
747
792
|
end
|
748
793
|
end
|
749
794
|
|
@@ -775,6 +820,17 @@ class OptionParser
|
|
775
820
|
@list = []
|
776
821
|
end
|
777
822
|
|
823
|
+
def pretty_print(q) # :nodoc:
|
824
|
+
q.group(1, "(", ")") do
|
825
|
+
@list.each do |sw|
|
826
|
+
next unless Switch === sw
|
827
|
+
q.group(1, "(" + sw.pretty_head, ")") do
|
828
|
+
sw.pretty_print_contents(q)
|
829
|
+
end
|
830
|
+
end
|
831
|
+
end
|
832
|
+
end
|
833
|
+
|
778
834
|
#
|
779
835
|
# See OptionParser.accept.
|
780
836
|
#
|
@@ -806,7 +862,7 @@ class OptionParser
|
|
806
862
|
# +lopts+:: Long style option list.
|
807
863
|
# +nlopts+:: Negated long style options list.
|
808
864
|
#
|
809
|
-
def update(sw, sopts, lopts, nsw = nil, nlopts = nil)
|
865
|
+
def update(sw, sopts, lopts, nsw = nil, nlopts = nil) # :nodoc:
|
810
866
|
sopts.each {|o| @short[o] = sw} if sopts
|
811
867
|
lopts.each {|o| @long[o] = sw} if lopts
|
812
868
|
nlopts.each {|o| @long[o] = nsw} if nsw and nlopts
|
@@ -1092,6 +1148,7 @@ XXX
|
|
1092
1148
|
@summary_indent = indent
|
1093
1149
|
@default_argv = ARGV
|
1094
1150
|
@require_exact = false
|
1151
|
+
@raise_unknown = true
|
1095
1152
|
add_officious
|
1096
1153
|
yield self if block_given?
|
1097
1154
|
end
|
@@ -1169,6 +1226,9 @@ XXX
|
|
1169
1226
|
# abbreviated long option as short option).
|
1170
1227
|
attr_accessor :require_exact
|
1171
1228
|
|
1229
|
+
# Whether to raise at unknown option.
|
1230
|
+
attr_accessor :raise_unknown
|
1231
|
+
|
1172
1232
|
#
|
1173
1233
|
# Heading banner preceding summary.
|
1174
1234
|
#
|
@@ -1287,6 +1347,29 @@ XXX
|
|
1287
1347
|
def help; summarize("#{banner}".sub(/\n?\z/, "\n")) end
|
1288
1348
|
alias to_s help
|
1289
1349
|
|
1350
|
+
def pretty_print(q) # :nodoc:
|
1351
|
+
q.object_group(self) do
|
1352
|
+
first = true
|
1353
|
+
if @stack.size > 2
|
1354
|
+
@stack.each_with_index do |s, i|
|
1355
|
+
next if i < 2
|
1356
|
+
next if s.list.empty?
|
1357
|
+
if first
|
1358
|
+
first = false
|
1359
|
+
q.text ":"
|
1360
|
+
end
|
1361
|
+
q.breakable
|
1362
|
+
s.pretty_print(q)
|
1363
|
+
end
|
1364
|
+
end
|
1365
|
+
end
|
1366
|
+
end
|
1367
|
+
|
1368
|
+
def inspect # :nodoc:
|
1369
|
+
require 'pp'
|
1370
|
+
pretty_print_inspect
|
1371
|
+
end
|
1372
|
+
|
1290
1373
|
#
|
1291
1374
|
# Returns option summary list.
|
1292
1375
|
#
|
@@ -1300,7 +1383,7 @@ XXX
|
|
1300
1383
|
# +prv+:: Previously specified argument.
|
1301
1384
|
# +msg+:: Exception message.
|
1302
1385
|
#
|
1303
|
-
def notwice(obj, prv, msg)
|
1386
|
+
def notwice(obj, prv, msg) # :nodoc:
|
1304
1387
|
unless !prv or prv == obj
|
1305
1388
|
raise(ArgumentError, "argument #{msg} given twice: #{obj}",
|
1306
1389
|
ParseError.filter_backtrace(caller(2)))
|
@@ -1314,64 +1397,7 @@ XXX
|
|
1314
1397
|
# :call-seq:
|
1315
1398
|
# make_switch(params, block = nil)
|
1316
1399
|
#
|
1317
|
-
#
|
1318
|
-
# value is passed to the given block, where it can be processed.
|
1319
|
-
#
|
1320
|
-
# See at the beginning of OptionParser for some full examples.
|
1321
|
-
#
|
1322
|
-
# +params+ can include the following elements:
|
1323
|
-
#
|
1324
|
-
# [Argument style:]
|
1325
|
-
# One of the following:
|
1326
|
-
# :NONE, :REQUIRED, :OPTIONAL
|
1327
|
-
#
|
1328
|
-
# [Argument pattern:]
|
1329
|
-
# Acceptable option argument format, must be pre-defined with
|
1330
|
-
# OptionParser.accept or OptionParser#accept, or Regexp. This can appear
|
1331
|
-
# once or assigned as String if not present, otherwise causes an
|
1332
|
-
# ArgumentError. Examples:
|
1333
|
-
# Float, Time, Array
|
1334
|
-
#
|
1335
|
-
# [Possible argument values:]
|
1336
|
-
# Hash or Array.
|
1337
|
-
# [:text, :binary, :auto]
|
1338
|
-
# %w[iso-2022-jp shift_jis euc-jp utf8 binary]
|
1339
|
-
# { "jis" => "iso-2022-jp", "sjis" => "shift_jis" }
|
1340
|
-
#
|
1341
|
-
# [Long style switch:]
|
1342
|
-
# Specifies a long style switch which takes a mandatory, optional or no
|
1343
|
-
# argument. It's a string of the following form:
|
1344
|
-
# "--switch=MANDATORY" or "--switch MANDATORY"
|
1345
|
-
# "--switch[=OPTIONAL]"
|
1346
|
-
# "--switch"
|
1347
|
-
#
|
1348
|
-
# [Short style switch:]
|
1349
|
-
# Specifies short style switch which takes a mandatory, optional or no
|
1350
|
-
# argument. It's a string of the following form:
|
1351
|
-
# "-xMANDATORY"
|
1352
|
-
# "-x[OPTIONAL]"
|
1353
|
-
# "-x"
|
1354
|
-
# There is also a special form which matches character range (not full
|
1355
|
-
# set of regular expression):
|
1356
|
-
# "-[a-z]MANDATORY"
|
1357
|
-
# "-[a-z][OPTIONAL]"
|
1358
|
-
# "-[a-z]"
|
1359
|
-
#
|
1360
|
-
# [Argument style and description:]
|
1361
|
-
# Instead of specifying mandatory or optional arguments directly in the
|
1362
|
-
# switch parameter, this separate parameter can be used.
|
1363
|
-
# "=MANDATORY"
|
1364
|
-
# "=[OPTIONAL]"
|
1365
|
-
#
|
1366
|
-
# [Description:]
|
1367
|
-
# Description string for the option.
|
1368
|
-
# "Run verbosely"
|
1369
|
-
# If you give multiple description strings, each string will be printed
|
1370
|
-
# line by line.
|
1371
|
-
#
|
1372
|
-
# [Handler:]
|
1373
|
-
# Handler for the parsed argument value. Either give a block or pass a
|
1374
|
-
# Proc or Method as an argument.
|
1400
|
+
# :include: ../doc/optparse/creates_option.rdoc
|
1375
1401
|
#
|
1376
1402
|
def make_switch(opts, block = nil)
|
1377
1403
|
short, long, nolong, style, pattern, conv, not_pattern, not_conv, not_style = [], [], []
|
@@ -1480,7 +1506,7 @@ XXX
|
|
1480
1506
|
style = notwice(default_style.guess(arg = o), style, 'style')
|
1481
1507
|
default_pattern, conv = search(:atype, Object) unless default_pattern
|
1482
1508
|
else
|
1483
|
-
desc.push(o)
|
1509
|
+
desc.push(o) if o && !o.empty?
|
1484
1510
|
end
|
1485
1511
|
end
|
1486
1512
|
|
@@ -1509,6 +1535,8 @@ XXX
|
|
1509
1535
|
# :call-seq:
|
1510
1536
|
# define(*params, &block)
|
1511
1537
|
#
|
1538
|
+
# :include: ../doc/optparse/creates_option.rdoc
|
1539
|
+
#
|
1512
1540
|
def define(*opts, &block)
|
1513
1541
|
top.append(*(sw = make_switch(opts, block)))
|
1514
1542
|
sw[0]
|
@@ -1517,8 +1545,7 @@ XXX
|
|
1517
1545
|
# :call-seq:
|
1518
1546
|
# on(*params, &block)
|
1519
1547
|
#
|
1520
|
-
#
|
1521
|
-
# parameters.
|
1548
|
+
# :include: ../doc/optparse/creates_option.rdoc
|
1522
1549
|
#
|
1523
1550
|
def on(*opts, &block)
|
1524
1551
|
define(*opts, &block)
|
@@ -1529,6 +1556,8 @@ XXX
|
|
1529
1556
|
# :call-seq:
|
1530
1557
|
# define_head(*params, &block)
|
1531
1558
|
#
|
1559
|
+
# :include: ../doc/optparse/creates_option.rdoc
|
1560
|
+
#
|
1532
1561
|
def define_head(*opts, &block)
|
1533
1562
|
top.prepend(*(sw = make_switch(opts, block)))
|
1534
1563
|
sw[0]
|
@@ -1537,7 +1566,9 @@ XXX
|
|
1537
1566
|
# :call-seq:
|
1538
1567
|
# on_head(*params, &block)
|
1539
1568
|
#
|
1540
|
-
#
|
1569
|
+
# :include: ../doc/optparse/creates_option.rdoc
|
1570
|
+
#
|
1571
|
+
# The new option is added at the head of the summary.
|
1541
1572
|
#
|
1542
1573
|
def on_head(*opts, &block)
|
1543
1574
|
define_head(*opts, &block)
|
@@ -1548,6 +1579,8 @@ XXX
|
|
1548
1579
|
# :call-seq:
|
1549
1580
|
# define_tail(*params, &block)
|
1550
1581
|
#
|
1582
|
+
# :include: ../doc/optparse/creates_option.rdoc
|
1583
|
+
#
|
1551
1584
|
def define_tail(*opts, &block)
|
1552
1585
|
base.append(*(sw = make_switch(opts, block)))
|
1553
1586
|
sw[0]
|
@@ -1557,7 +1590,9 @@ XXX
|
|
1557
1590
|
# :call-seq:
|
1558
1591
|
# on_tail(*params, &block)
|
1559
1592
|
#
|
1560
|
-
#
|
1593
|
+
# :include: ../doc/optparse/creates_option.rdoc
|
1594
|
+
#
|
1595
|
+
# The new option is added at the tail of the summary.
|
1561
1596
|
#
|
1562
1597
|
def on_tail(*opts, &block)
|
1563
1598
|
define_tail(*opts, &block)
|
@@ -1608,9 +1643,11 @@ XXX
|
|
1608
1643
|
begin
|
1609
1644
|
sw, = complete(:long, opt, true)
|
1610
1645
|
if require_exact && !sw.long.include?(arg)
|
1646
|
+
throw :terminate, arg unless raise_unknown
|
1611
1647
|
raise InvalidOption, arg
|
1612
1648
|
end
|
1613
1649
|
rescue ParseError
|
1650
|
+
throw :terminate, arg unless raise_unknown
|
1614
1651
|
raise $!.set_option(arg, true)
|
1615
1652
|
end
|
1616
1653
|
begin
|
@@ -1642,6 +1679,7 @@ XXX
|
|
1642
1679
|
end
|
1643
1680
|
end
|
1644
1681
|
rescue ParseError
|
1682
|
+
throw :terminate, arg unless raise_unknown
|
1645
1683
|
raise $!.set_option(arg, true)
|
1646
1684
|
end
|
1647
1685
|
begin
|
@@ -1780,7 +1818,7 @@ XXX
|
|
1780
1818
|
# Traverses @stack, sending each element method +id+ with +args+ and
|
1781
1819
|
# +block+.
|
1782
1820
|
#
|
1783
|
-
def visit(id, *args, &block)
|
1821
|
+
def visit(id, *args, &block) # :nodoc:
|
1784
1822
|
@stack.reverse_each do |el|
|
1785
1823
|
el.__send__(id, *args, &block)
|
1786
1824
|
end
|
@@ -1791,7 +1829,7 @@ XXX
|
|
1791
1829
|
#
|
1792
1830
|
# Searches +key+ in @stack for +id+ hash and returns or yields the result.
|
1793
1831
|
#
|
1794
|
-
def search(id, key)
|
1832
|
+
def search(id, key) # :nodoc:
|
1795
1833
|
block_given = block_given?
|
1796
1834
|
visit(:search, id, key) do |k|
|
1797
1835
|
return block_given ? yield(k) : k
|
@@ -1808,7 +1846,7 @@ XXX
|
|
1808
1846
|
# +icase+:: Search case insensitive if true.
|
1809
1847
|
# +pat+:: Optional pattern for completion.
|
1810
1848
|
#
|
1811
|
-
def complete(typ, opt, icase = false, *pat)
|
1849
|
+
def complete(typ, opt, icase = false, *pat) # :nodoc:
|
1812
1850
|
if pat.empty?
|
1813
1851
|
search(typ, opt) {|sw| return [sw, opt]} # exact match or...
|
1814
1852
|
end
|
@@ -1872,10 +1910,13 @@ XXX
|
|
1872
1910
|
# directory ~/.options, then the basename with '.options' suffix
|
1873
1911
|
# under XDG and Haiku standard places.
|
1874
1912
|
#
|
1875
|
-
|
1913
|
+
# The optional +into+ keyword argument works exactly like that accepted in
|
1914
|
+
# method #parse.
|
1915
|
+
#
|
1916
|
+
def load(filename = nil, into: nil)
|
1876
1917
|
unless filename
|
1877
1918
|
basename = File.basename($0, '.*')
|
1878
|
-
return true if load(File.expand_path(basename, '~/.options')) rescue nil
|
1919
|
+
return true if load(File.expand_path(basename, '~/.options'), into: into) rescue nil
|
1879
1920
|
basename << ".options"
|
1880
1921
|
return [
|
1881
1922
|
# XDG
|
@@ -1887,11 +1928,11 @@ XXX
|
|
1887
1928
|
'~/config/settings',
|
1888
1929
|
].any? {|dir|
|
1889
1930
|
next if !dir or dir.empty?
|
1890
|
-
load(File.expand_path(basename, dir)) rescue nil
|
1931
|
+
load(File.expand_path(basename, dir), into: into) rescue nil
|
1891
1932
|
}
|
1892
1933
|
end
|
1893
1934
|
begin
|
1894
|
-
parse(*
|
1935
|
+
parse(*File.readlines(filename, chomp: true), into: into)
|
1895
1936
|
true
|
1896
1937
|
rescue Errno::ENOENT, Errno::ENOTDIR
|
1897
1938
|
false
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: optparse
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nobu Nakada
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-12-05 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: OptionParser is a class for command-line option analysis.
|
14
14
|
email:
|
@@ -18,8 +18,67 @@ extensions: []
|
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
20
|
- COPYING
|
21
|
+
- ChangeLog
|
21
22
|
- README.md
|
22
|
-
-
|
23
|
+
- doc/optparse/argument_converters.rdoc
|
24
|
+
- doc/optparse/creates_option.rdoc
|
25
|
+
- doc/optparse/option_params.rdoc
|
26
|
+
- doc/optparse/ruby/argument_keywords.rb
|
27
|
+
- doc/optparse/ruby/argument_strings.rb
|
28
|
+
- doc/optparse/ruby/argv.rb
|
29
|
+
- doc/optparse/ruby/array.rb
|
30
|
+
- doc/optparse/ruby/basic.rb
|
31
|
+
- doc/optparse/ruby/block.rb
|
32
|
+
- doc/optparse/ruby/collected_options.rb
|
33
|
+
- doc/optparse/ruby/custom_converter.rb
|
34
|
+
- doc/optparse/ruby/date.rb
|
35
|
+
- doc/optparse/ruby/datetime.rb
|
36
|
+
- doc/optparse/ruby/decimal_integer.rb
|
37
|
+
- doc/optparse/ruby/decimal_numeric.rb
|
38
|
+
- doc/optparse/ruby/default_values.rb
|
39
|
+
- doc/optparse/ruby/descriptions.rb
|
40
|
+
- doc/optparse/ruby/explicit_array_values.rb
|
41
|
+
- doc/optparse/ruby/explicit_hash_values.rb
|
42
|
+
- doc/optparse/ruby/false_class.rb
|
43
|
+
- doc/optparse/ruby/float.rb
|
44
|
+
- doc/optparse/ruby/help.rb
|
45
|
+
- doc/optparse/ruby/help_banner.rb
|
46
|
+
- doc/optparse/ruby/help_format.rb
|
47
|
+
- doc/optparse/ruby/help_program_name.rb
|
48
|
+
- doc/optparse/ruby/integer.rb
|
49
|
+
- doc/optparse/ruby/long_names.rb
|
50
|
+
- doc/optparse/ruby/long_optional.rb
|
51
|
+
- doc/optparse/ruby/long_required.rb
|
52
|
+
- doc/optparse/ruby/long_simple.rb
|
53
|
+
- doc/optparse/ruby/long_with_negation.rb
|
54
|
+
- doc/optparse/ruby/match_converter.rb
|
55
|
+
- doc/optparse/ruby/matched_values.rb
|
56
|
+
- doc/optparse/ruby/method.rb
|
57
|
+
- doc/optparse/ruby/missing_options.rb
|
58
|
+
- doc/optparse/ruby/mixed_names.rb
|
59
|
+
- doc/optparse/ruby/name_abbrev.rb
|
60
|
+
- doc/optparse/ruby/no_abbreviation.rb
|
61
|
+
- doc/optparse/ruby/numeric.rb
|
62
|
+
- doc/optparse/ruby/object.rb
|
63
|
+
- doc/optparse/ruby/octal_integer.rb
|
64
|
+
- doc/optparse/ruby/optional_argument.rb
|
65
|
+
- doc/optparse/ruby/parse.rb
|
66
|
+
- doc/optparse/ruby/parse_bang.rb
|
67
|
+
- doc/optparse/ruby/proc.rb
|
68
|
+
- doc/optparse/ruby/regexp.rb
|
69
|
+
- doc/optparse/ruby/required_argument.rb
|
70
|
+
- doc/optparse/ruby/shellwords.rb
|
71
|
+
- doc/optparse/ruby/short_names.rb
|
72
|
+
- doc/optparse/ruby/short_optional.rb
|
73
|
+
- doc/optparse/ruby/short_range.rb
|
74
|
+
- doc/optparse/ruby/short_required.rb
|
75
|
+
- doc/optparse/ruby/short_simple.rb
|
76
|
+
- doc/optparse/ruby/string.rb
|
77
|
+
- doc/optparse/ruby/terminator.rb
|
78
|
+
- doc/optparse/ruby/time.rb
|
79
|
+
- doc/optparse/ruby/true_class.rb
|
80
|
+
- doc/optparse/ruby/uri.rb
|
81
|
+
- doc/optparse/tutorial.rdoc
|
23
82
|
- lib/optionparser.rb
|
24
83
|
- lib/optparse.rb
|
25
84
|
- lib/optparse/ac.rb
|
@@ -31,10 +90,6 @@ files:
|
|
31
90
|
- lib/optparse/version.rb
|
32
91
|
- misc/rb_optparse.bash
|
33
92
|
- misc/rb_optparse.zsh
|
34
|
-
- optparse.gemspec
|
35
|
-
- rakelib/changelogs.rake
|
36
|
-
- rakelib/epoch.rake
|
37
|
-
- rakelib/version.rake
|
38
93
|
homepage: https://github.com/ruby/optparse
|
39
94
|
licenses:
|
40
95
|
- Ruby
|
@@ -43,7 +98,10 @@ metadata:
|
|
43
98
|
homepage_uri: https://github.com/ruby/optparse
|
44
99
|
source_code_uri: https://github.com/ruby/optparse
|
45
100
|
post_install_message:
|
46
|
-
rdoc_options:
|
101
|
+
rdoc_options:
|
102
|
+
- "--main=README.md"
|
103
|
+
- "--op=rdoc"
|
104
|
+
- "--page-dir=doc"
|
47
105
|
require_paths:
|
48
106
|
- lib
|
49
107
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -57,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
57
115
|
- !ruby/object:Gem::Version
|
58
116
|
version: '0'
|
59
117
|
requirements: []
|
60
|
-
rubygems_version: 3.
|
118
|
+
rubygems_version: 3.4.0.dev
|
61
119
|
signing_key:
|
62
120
|
specification_version: 4
|
63
121
|
summary: OptionParser is a class for command-line option analysis.
|
data/Rakefile
DELETED
data/optparse.gemspec
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
name = File.basename(__FILE__, ".gemspec")
|
4
|
-
version = ["lib", Array.new(name.count("-")+1, "..").join("/")].find do |dir|
|
5
|
-
break File.foreach(File.join(__dir__, dir, "#{name.tr('-', '/')}.rb")) do |line|
|
6
|
-
/^\s*OptionParser::Version\s*=\s*"(.*)"/ =~ line and break $1
|
7
|
-
end rescue nil
|
8
|
-
end
|
9
|
-
|
10
|
-
Gem::Specification.new do |spec|
|
11
|
-
spec.name = name
|
12
|
-
spec.version = version
|
13
|
-
spec.authors = ["Nobu Nakada"]
|
14
|
-
spec.email = ["nobu@ruby-lang.org"]
|
15
|
-
|
16
|
-
spec.summary = %q{OptionParser is a class for command-line option analysis.}
|
17
|
-
spec.description = %q{OptionParser is a class for command-line option analysis.}
|
18
|
-
spec.homepage = "https://github.com/ruby/optparse"
|
19
|
-
spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
|
20
|
-
spec.licenses = ["Ruby", "BSD-2-Clause"]
|
21
|
-
|
22
|
-
spec.metadata["homepage_uri"] = spec.homepage
|
23
|
-
spec.metadata["source_code_uri"] = spec.homepage
|
24
|
-
|
25
|
-
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
26
|
-
`git ls-files -z`.split("\x0").reject { |f|
|
27
|
-
f.match(%r{\A(?:(?:test|spec|features)/|Gemfile|\.(?:editor|git))})
|
28
|
-
}
|
29
|
-
end
|
30
|
-
spec.bindir = "exe"
|
31
|
-
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
32
|
-
spec.require_paths = ["lib"]
|
33
|
-
end
|
data/rakelib/changelogs.rake
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
task "build" => "changelogs"
|
2
|
-
|
3
|
-
changelog = proc do |output, ver = nil, prev = nil|
|
4
|
-
ver &&= Gem::Version.new(ver)
|
5
|
-
range = [[prev], [ver, "HEAD"]].map {|ver, branch| ver ? "v#{ver.to_s}" : branch}.compact.join("..")
|
6
|
-
IO.popen(%W[git log --format=fuller --topo-order --no-merges #{range}]) do |log|
|
7
|
-
line = log.gets
|
8
|
-
FileUtils.mkpath(File.dirname(output))
|
9
|
-
File.open(output, "wb") do |f|
|
10
|
-
f.print "-*- coding: utf-8 -*-\n\n", line
|
11
|
-
log.each_line do |line|
|
12
|
-
line.sub!(/^(?!:)(?:Author|Commit)?(?:Date)?: /, ' \&')
|
13
|
-
line.sub!(/ +$/, '')
|
14
|
-
f.print(line)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
tags = IO.popen(%w[git tag -l v[0-9]*]).grep(/v(.*)/) {$1}
|
21
|
-
tags.sort_by! {|tag| tag.scan(/\d+/).map(&:to_i)}
|
22
|
-
tags.inject(nil) do |prev, tag|
|
23
|
-
task("logs/ChangeLog-#{tag}") {|t| changelog[t.name, tag, prev]}
|
24
|
-
tag
|
25
|
-
end
|
26
|
-
|
27
|
-
desc "Make ChangeLog"
|
28
|
-
task "ChangeLog", [:ver, :prev] do |t, ver: nil, prev: tags.last|
|
29
|
-
changelog[t.name, ver, prev]
|
30
|
-
end
|
31
|
-
|
32
|
-
changelogs = ["ChangeLog", *tags.map {|tag| "logs/ChangeLog-#{tag}"}]
|
33
|
-
task "changelogs" => changelogs
|
34
|
-
CLOBBER.concat(changelogs) << "logs"
|