optparse 0.8.0 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/optparse.rb +23 -30
  3. data/misc/rb_optparse.zsh +4 -4
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4dec1fbb1e4ff0272a70fa344e4e13c828134304842865b4672c453e57211341
4
- data.tar.gz: ddd890350fc1b50926786a847720780e862cb20cd79a6f62171bebd113f40747
3
+ metadata.gz: 1e2f866d7ea25513c29f801cd387f92ec20eccd04267c0d85217efbcd709ada5
4
+ data.tar.gz: fad2cc841c36c918dfeb1678cc2748a1e810b9b91c586bc17d0611037c9dfccc
5
5
  SHA512:
6
- metadata.gz: 276d2e92d51aaa4712854fae44269cba7a4bdac3a74e82683338bb2aa9e210485da3ec68b9357bae6b4aa288ad8d2abe13240d2f87724c9d3bae161d71118490
7
- data.tar.gz: 68c2702b76557725162add964c094261a553631349bbcdf99c715d3eb8aabb22bdf46238390e88d2b03df490143a624149774ccde1cd145a0e068f2985fa20f1
6
+ metadata.gz: 9bb88ab609bfb642c34b6b9a86e46cc5266704df2af5322fcc066b6b12fa558ed135cf5bcc70aedb88b31d1c3e495b694db6d6864cc391e413c1fc4d4ad57048
7
+ data.tar.gz: 549fc097b68ed61a50dc92f48d8274ef5d1054eec3161f209503dc28845dfb72db14b64495ea9e7cebedc0ae452c0f7db5b5be16a499597cd8badf8046a3aad0
data/lib/optparse.rb CHANGED
@@ -426,8 +426,9 @@ require 'set' unless defined?(Set)
426
426
  #
427
427
  class OptionParser
428
428
  # The version string
429
- VERSION = "0.8.0"
430
- Version = VERSION # for compatibility
429
+ VERSION = "0.8.1"
430
+ # An alias for compatibility
431
+ Version = VERSION
431
432
 
432
433
  # :stopdoc:
433
434
  NoArgument = [NO_ARGUMENT = :NONE, nil].freeze
@@ -471,7 +472,6 @@ class OptionParser
471
472
  Completion.candidate(key, icase, pat, &method(:each))
472
473
  end
473
474
 
474
- public
475
475
  def complete(key, icase = false, pat = nil)
476
476
  candidates = candidate(key, icase, pat, &method(:each)).sort_by {|k, v, kn| kn.size}
477
477
  if candidates.size == 1
@@ -561,7 +561,7 @@ class OptionParser
561
561
  # Parses +arg+ and returns rest of +arg+ and matched portion to the
562
562
  # argument pattern. Yields when the pattern doesn't match substring.
563
563
  #
564
- def parse_arg(arg) # :nodoc:
564
+ private def parse_arg(arg) # :nodoc:
565
565
  pattern or return nil, [arg]
566
566
  unless m = pattern.match(arg)
567
567
  yield(InvalidArgument, arg)
@@ -579,14 +579,13 @@ class OptionParser
579
579
  yield(InvalidArgument, arg) # didn't match whole arg
580
580
  return arg[s.length..-1], m
581
581
  end
582
- private :parse_arg
583
582
 
584
583
  #
585
584
  # Parses argument, converts and returns +arg+, +block+ and result of
586
585
  # conversion. Yields at semi-error condition instead of raising an
587
586
  # exception.
588
587
  #
589
- def conv_arg(arg, val = []) # :nodoc:
588
+ private def conv_arg(arg, val = []) # :nodoc:
590
589
  v, = *val
591
590
  if conv
592
591
  val = conv.call(*val)
@@ -598,7 +597,6 @@ class OptionParser
598
597
  end
599
598
  return arg, block, val
600
599
  end
601
- private :conv_arg
602
600
 
603
601
  #
604
602
  # Produces the summary text. Each line of the summary is yielded to the
@@ -882,14 +880,13 @@ class OptionParser
882
880
  # +lopts+:: Long style option list.
883
881
  # +nlopts+:: Negated long style options list.
884
882
  #
885
- def update(sw, sopts, lopts, nsw = nil, nlopts = nil) # :nodoc:
883
+ private def update(sw, sopts, lopts, nsw = nil, nlopts = nil) # :nodoc:
886
884
  sopts.each {|o| @short[o] = sw} if sopts
887
885
  lopts.each {|o| @long[o] = sw} if lopts
888
886
  nlopts.each {|o| @long[o] = nsw} if nsw and nlopts
889
887
  used = @short.invert.update(@long.invert)
890
888
  @list.delete_if {|o| Switch === o and !used[o]}
891
889
  end
892
- private :update
893
890
 
894
891
  #
895
892
  # Inserts +switch+ at the head of the list, and associates short, long
@@ -1458,14 +1455,13 @@ XXX
1458
1455
  # +prv+:: Previously specified argument.
1459
1456
  # +msg+:: Exception message.
1460
1457
  #
1461
- def notwice(obj, prv, msg) # :nodoc:
1458
+ private def notwice(obj, prv, msg) # :nodoc:
1462
1459
  unless !prv or prv == obj
1463
1460
  raise(ArgumentError, "argument #{msg} given twice: #{obj}",
1464
1461
  ParseError.filter_backtrace(caller(2)))
1465
1462
  end
1466
1463
  obj
1467
1464
  end
1468
- private :notwice
1469
1465
 
1470
1466
  SPLAT_PROC = proc {|*a| a.length <= 1 ? a.first : a} # :nodoc:
1471
1467
 
@@ -1732,7 +1728,7 @@ XXX
1732
1728
  parse_in_order(argv, setter, **keywords, &nonopt)
1733
1729
  end
1734
1730
 
1735
- def parse_in_order(argv = default_argv, setter = nil, exact: require_exact, **, &nonopt) # :nodoc:
1731
+ private def parse_in_order(argv = default_argv, setter = nil, exact: require_exact, **, &nonopt) # :nodoc:
1736
1732
  opt, arg, val, rest = nil
1737
1733
  nonopt ||= proc {|a| throw :terminate, a}
1738
1734
  argv.unshift(arg) if arg = catch(:terminate) {
@@ -1823,10 +1819,9 @@ XXX
1823
1819
 
1824
1820
  argv
1825
1821
  end
1826
- private :parse_in_order
1827
1822
 
1828
1823
  # Calls callback with _val_.
1829
- def callback!(cb, max_arity, *args) # :nodoc:
1824
+ private def callback!(cb, max_arity, *args) # :nodoc:
1830
1825
  args.compact!
1831
1826
 
1832
1827
  if (size = args.size) < max_arity and cb.to_proc.lambda?
@@ -1836,7 +1831,6 @@ XXX
1836
1831
  end
1837
1832
  cb.call(*args)
1838
1833
  end
1839
- private :callback!
1840
1834
 
1841
1835
  #
1842
1836
  # Parses command line arguments +argv+ in permutation mode and returns
@@ -1950,24 +1944,22 @@ XXX
1950
1944
  # Traverses @stack, sending each element method +id+ with +args+ and
1951
1945
  # +block+.
1952
1946
  #
1953
- def visit(id, *args, &block) # :nodoc:
1947
+ private def visit(id, *args, &block) # :nodoc:
1954
1948
  @stack.reverse_each do |el|
1955
1949
  el.__send__(id, *args, &block)
1956
1950
  end
1957
1951
  nil
1958
1952
  end
1959
- private :visit
1960
1953
 
1961
1954
  #
1962
1955
  # Searches +key+ in @stack for +id+ hash and returns or yields the result.
1963
1956
  #
1964
- def search(id, key) # :nodoc:
1957
+ private def search(id, key) # :nodoc:
1965
1958
  block_given = block_given?
1966
1959
  visit(:search, id, key) do |k|
1967
1960
  return block_given ? yield(k) : k
1968
1961
  end
1969
1962
  end
1970
- private :search
1971
1963
 
1972
1964
  #
1973
1965
  # Completes shortened long style option switch and returns pair of
@@ -1978,7 +1970,7 @@ XXX
1978
1970
  # +icase+:: Search case insensitive if true.
1979
1971
  # +pat+:: Optional pattern for completion.
1980
1972
  #
1981
- def complete(typ, opt, icase = false, *pat) # :nodoc:
1973
+ private def complete(typ, opt, icase = false, *pat) # :nodoc:
1982
1974
  if pat.empty?
1983
1975
  search(typ, opt) {|sw| return [sw, opt]} # exact match or...
1984
1976
  end
@@ -1988,7 +1980,6 @@ XXX
1988
1980
  exc = ambiguous ? AmbiguousOption : InvalidOption
1989
1981
  raise exc.new(opt, additional: proc {|o| additional_message(typ, o)})
1990
1982
  end
1991
- private :complete
1992
1983
 
1993
1984
  #
1994
1985
  # Returns additional info.
@@ -2323,42 +2314,42 @@ XXX
2323
2314
  # Raises when ambiguously completable string is encountered.
2324
2315
  #
2325
2316
  class AmbiguousOption < ParseError
2326
- const_set(:Reason, 'ambiguous option')
2317
+ Reason = 'ambiguous option' # :nodoc:
2327
2318
  end
2328
2319
 
2329
2320
  #
2330
2321
  # Raises when there is an argument for a switch which takes no argument.
2331
2322
  #
2332
2323
  class NeedlessArgument < ParseError
2333
- const_set(:Reason, 'needless argument')
2324
+ Reason = 'needless argument' # :nodoc:
2334
2325
  end
2335
2326
 
2336
2327
  #
2337
2328
  # Raises when a switch with mandatory argument has no argument.
2338
2329
  #
2339
2330
  class MissingArgument < ParseError
2340
- const_set(:Reason, 'missing argument')
2331
+ Reason = 'missing argument' # :nodoc:
2341
2332
  end
2342
2333
 
2343
2334
  #
2344
2335
  # Raises when switch is undefined.
2345
2336
  #
2346
2337
  class InvalidOption < ParseError
2347
- const_set(:Reason, 'invalid option')
2338
+ Reason = 'invalid option' # :nodoc:
2348
2339
  end
2349
2340
 
2350
2341
  #
2351
2342
  # Raises when the given argument does not match required format.
2352
2343
  #
2353
2344
  class InvalidArgument < ParseError
2354
- const_set(:Reason, 'invalid argument')
2345
+ Reason = 'invalid argument' # :nodoc:
2355
2346
  end
2356
2347
 
2357
2348
  #
2358
2349
  # Raises when the given argument word can't be completed uniquely.
2359
2350
  #
2360
2351
  class AmbiguousArgument < InvalidArgument
2361
- const_set(:Reason, 'ambiguous argument')
2352
+ Reason = 'ambiguous argument' # :nodoc:
2362
2353
  end
2363
2354
 
2364
2355
  #
@@ -2457,9 +2448,11 @@ XXX
2457
2448
  # and DecimalNumeric. See Acceptable argument classes (in source code).
2458
2449
  #
2459
2450
  module Acceptables
2460
- const_set(:DecimalInteger, OptionParser::DecimalInteger)
2461
- const_set(:OctalInteger, OptionParser::OctalInteger)
2462
- const_set(:DecimalNumeric, OptionParser::DecimalNumeric)
2451
+ # :stopdoc:
2452
+ DecimalInteger = OptionParser::DecimalInteger
2453
+ OctalInteger = OptionParser::OctalInteger
2454
+ DecimalNumeric = OptionParser::DecimalNumeric
2455
+ # :startdoc:
2463
2456
  end
2464
2457
  end
2465
2458
 
data/misc/rb_optparse.zsh CHANGED
@@ -8,11 +8,11 @@
8
8
  # cp rb_optparse.zsh ~/.zsh.d/rb_optparse.zsh
9
9
  #
10
10
  # (2) load the script, and add a directory to fpath before compinit.
11
- # echo '. ~/.zsh.d/rb_optparse.zsh' >> "${ZDOTDIR:-~}/.zshrc"
12
- # echo 'fpath=(~/.zsh.d/Completion $fpath)' >> "${ZDOTDIR:-~}/.zshrc"
13
- # echo 'autoload -U compinit; compinit' >> "${ZDOTDIR:-~}/.zshrc"
11
+ # echo '. ~/.zsh.d/rb_optparse.zsh' >> "${ZDOTDIR:-$HOME}/.zshrc"
12
+ # echo 'fpath=(~/.zsh.d/Completion $fpath)' >> "${ZDOTDIR:-$HOME}/.zshrc"
13
+ # echo 'autoload -U compinit; compinit' >> "${ZDOTDIR:-$HOME}/.zshrc"
14
14
  #
15
- # (3) restart zsh.
15
+ # (3) restart zsh. (eg `exec zsh -il`)
16
16
  #
17
17
  # (4) generate completion files once.
18
18
  # generate-complete-function/ruby/optparse COMMAND1
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: optparse
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nobu Nakada
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-10-31 00:00:00.000000000 Z
10
+ date: 2025-12-10 00:00:00.000000000 Z
11
11
  dependencies: []
12
12
  description: |
13
13
  OptionParser is a class for command-line option analysis. It is much more