optparse 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +0 -1
- data/lib/optparse.rb +48 -15
- data/lib/optparse/kwargs.rb +3 -0
- data/misc/rb_optparse.bash +21 -0
- data/misc/rb_optparse.zsh +39 -0
- data/optparse.gemspec +3 -2
- data/rakelib/changelogs.rake +34 -0
- data/rakelib/epoch.rake +5 -0
- data/rakelib/version.rake +47 -0
- metadata +8 -9
- data/.github/workflows/test.yml +0 -24
- data/.gitignore +0 -8
- data/Gemfile +0 -4
- data/Gemfile.lock +0 -17
- data/bin/console +0 -7
- data/bin/setup +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f8070528a5fa8e91d067053a532c9771c71f63d16d6a31622c7ca3c6e487c425
|
4
|
+
data.tar.gz: e854fcd1fe22dd596fe2650e4141e59124d0f78ae492de3164b250a4d18cc9de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e246c2d76a0b033b8f31e4d0c850050281b6722e3d7d4ae5e11de16bc00ad337f75243b2b932b915cc45406294038d7b770c3e2150d3faab5bc674135ce6355
|
7
|
+
data.tar.gz: 75b3d9526ad311161ad01507616dbd60ec97714a1440d10b15702bf360a3f0d081a5cade68d25d6bed50f56ed19599d657e7fb4e56d130b50b51861d501b08ce
|
data/README.md
CHANGED
data/lib/optparse.rb
CHANGED
@@ -72,10 +72,10 @@
|
|
72
72
|
# require 'optparse'
|
73
73
|
#
|
74
74
|
# options = {}
|
75
|
-
# OptionParser.new do |
|
76
|
-
#
|
75
|
+
# OptionParser.new do |parser|
|
76
|
+
# parser.banner = "Usage: example.rb [options]"
|
77
77
|
#
|
78
|
-
#
|
78
|
+
# parser.on("-v", "--[no-]verbose", "Run verbosely") do |v|
|
79
79
|
# options[:verbose] = v
|
80
80
|
# end
|
81
81
|
# end.parse!
|
@@ -96,15 +96,15 @@
|
|
96
96
|
# def self.parse(options)
|
97
97
|
# args = Options.new("world")
|
98
98
|
#
|
99
|
-
# opt_parser = OptionParser.new do |
|
100
|
-
#
|
99
|
+
# opt_parser = OptionParser.new do |parser|
|
100
|
+
# parser.banner = "Usage: example.rb [options]"
|
101
101
|
#
|
102
|
-
#
|
102
|
+
# parser.on("-nNAME", "--name=NAME", "Name to say hello to") do |n|
|
103
103
|
# args.name = n
|
104
104
|
# end
|
105
105
|
#
|
106
|
-
#
|
107
|
-
# puts
|
106
|
+
# parser.on("-h", "--help", "Prints this help") do
|
107
|
+
# puts parser
|
108
108
|
# exit
|
109
109
|
# end
|
110
110
|
# end
|
@@ -241,10 +241,10 @@
|
|
241
241
|
# require 'optparse'
|
242
242
|
#
|
243
243
|
# params = {}
|
244
|
-
# OptionParser.new do |
|
245
|
-
#
|
246
|
-
#
|
247
|
-
#
|
244
|
+
# OptionParser.new do |parser|
|
245
|
+
# parser.on('-a')
|
246
|
+
# parser.on('-b NUM', Integer)
|
247
|
+
# parser.on('-v', '--verbose')
|
248
248
|
# end.parse!(into: params)
|
249
249
|
#
|
250
250
|
# p params
|
@@ -419,7 +419,7 @@
|
|
419
419
|
# have any questions, file a ticket at http://bugs.ruby-lang.org.
|
420
420
|
#
|
421
421
|
class OptionParser
|
422
|
-
OptionParser::Version = "0.1.
|
422
|
+
OptionParser::Version = "0.1.1"
|
423
423
|
|
424
424
|
# :stopdoc:
|
425
425
|
NoArgument = [NO_ARGUMENT = :NONE, nil].freeze
|
@@ -1091,6 +1091,7 @@ XXX
|
|
1091
1091
|
@summary_width = width
|
1092
1092
|
@summary_indent = indent
|
1093
1093
|
@default_argv = ARGV
|
1094
|
+
@require_exact = false
|
1094
1095
|
add_officious
|
1095
1096
|
yield self if block_given?
|
1096
1097
|
end
|
@@ -1164,6 +1165,10 @@ XXX
|
|
1164
1165
|
# Strings to be parsed in default.
|
1165
1166
|
attr_accessor :default_argv
|
1166
1167
|
|
1168
|
+
# Whether to require that options match exactly (disallows providing
|
1169
|
+
# abbreviated long option as short option).
|
1170
|
+
attr_accessor :require_exact
|
1171
|
+
|
1167
1172
|
#
|
1168
1173
|
# Heading banner preceding summary.
|
1169
1174
|
#
|
@@ -1305,13 +1310,16 @@ XXX
|
|
1305
1310
|
private :notwice
|
1306
1311
|
|
1307
1312
|
SPLAT_PROC = proc {|*a| a.length <= 1 ? a.first : a} # :nodoc:
|
1313
|
+
|
1314
|
+
# :call-seq:
|
1315
|
+
# make_switch(params, block = nil)
|
1308
1316
|
#
|
1309
1317
|
# Creates an OptionParser::Switch from the parameters. The parsed argument
|
1310
1318
|
# value is passed to the given block, where it can be processed.
|
1311
1319
|
#
|
1312
1320
|
# See at the beginning of OptionParser for some full examples.
|
1313
1321
|
#
|
1314
|
-
# +
|
1322
|
+
# +params+ can include the following elements:
|
1315
1323
|
#
|
1316
1324
|
# [Argument style:]
|
1317
1325
|
# One of the following:
|
@@ -1498,11 +1506,16 @@ XXX
|
|
1498
1506
|
nolong
|
1499
1507
|
end
|
1500
1508
|
|
1509
|
+
# :call-seq:
|
1510
|
+
# define(*params, &block)
|
1511
|
+
#
|
1501
1512
|
def define(*opts, &block)
|
1502
1513
|
top.append(*(sw = make_switch(opts, block)))
|
1503
1514
|
sw[0]
|
1504
1515
|
end
|
1505
1516
|
|
1517
|
+
# :call-seq:
|
1518
|
+
# on(*params, &block)
|
1506
1519
|
#
|
1507
1520
|
# Add option switch and handler. See #make_switch for an explanation of
|
1508
1521
|
# parameters.
|
@@ -1513,11 +1526,16 @@ XXX
|
|
1513
1526
|
end
|
1514
1527
|
alias def_option define
|
1515
1528
|
|
1529
|
+
# :call-seq:
|
1530
|
+
# define_head(*params, &block)
|
1531
|
+
#
|
1516
1532
|
def define_head(*opts, &block)
|
1517
1533
|
top.prepend(*(sw = make_switch(opts, block)))
|
1518
1534
|
sw[0]
|
1519
1535
|
end
|
1520
1536
|
|
1537
|
+
# :call-seq:
|
1538
|
+
# on_head(*params, &block)
|
1521
1539
|
#
|
1522
1540
|
# Add option switch like with #on, but at head of summary.
|
1523
1541
|
#
|
@@ -1527,11 +1545,17 @@ XXX
|
|
1527
1545
|
end
|
1528
1546
|
alias def_head_option define_head
|
1529
1547
|
|
1548
|
+
# :call-seq:
|
1549
|
+
# define_tail(*params, &block)
|
1550
|
+
#
|
1530
1551
|
def define_tail(*opts, &block)
|
1531
1552
|
base.append(*(sw = make_switch(opts, block)))
|
1532
1553
|
sw[0]
|
1533
1554
|
end
|
1534
1555
|
|
1556
|
+
#
|
1557
|
+
# :call-seq:
|
1558
|
+
# on_tail(*params, &block)
|
1535
1559
|
#
|
1536
1560
|
# Add option switch like with #on, but at tail of summary.
|
1537
1561
|
#
|
@@ -1583,6 +1607,9 @@ XXX
|
|
1583
1607
|
opt.tr!('_', '-')
|
1584
1608
|
begin
|
1585
1609
|
sw, = complete(:long, opt, true)
|
1610
|
+
if require_exact && !sw.long.include?(arg)
|
1611
|
+
raise InvalidOption, arg
|
1612
|
+
end
|
1586
1613
|
rescue ParseError
|
1587
1614
|
raise $!.set_option(arg, true)
|
1588
1615
|
end
|
@@ -1607,6 +1634,7 @@ XXX
|
|
1607
1634
|
val = arg.delete_prefix('-')
|
1608
1635
|
has_arg = true
|
1609
1636
|
rescue InvalidOption
|
1637
|
+
raise if require_exact
|
1610
1638
|
# if no short options match, try completion with long
|
1611
1639
|
# options.
|
1612
1640
|
sw, = complete(:long, opt)
|
@@ -1618,7 +1646,12 @@ XXX
|
|
1618
1646
|
end
|
1619
1647
|
begin
|
1620
1648
|
opt, cb, val = sw.parse(val, argv) {|*exc| raise(*exc) if eq}
|
1649
|
+
rescue ParseError
|
1650
|
+
raise $!.set_option(arg, arg.length > 2)
|
1651
|
+
else
|
1621
1652
|
raise InvalidOption, arg if has_arg and !eq and arg == "-#{opt}"
|
1653
|
+
end
|
1654
|
+
begin
|
1622
1655
|
argv.unshift(opt) if opt and (!rest or (opt = opt.sub(/\A-*/, '-')) != '-')
|
1623
1656
|
val = cb.call(val) if cb
|
1624
1657
|
setter.call(sw.switch_name, val) if setter
|
@@ -1749,7 +1782,7 @@ XXX
|
|
1749
1782
|
#
|
1750
1783
|
def visit(id, *args, &block)
|
1751
1784
|
@stack.reverse_each do |el|
|
1752
|
-
el.
|
1785
|
+
el.__send__(id, *args, &block)
|
1753
1786
|
end
|
1754
1787
|
nil
|
1755
1788
|
end
|
data/lib/optparse/kwargs.rb
CHANGED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- bash -*-
|
2
|
+
#
|
3
|
+
# Completion for bash:
|
4
|
+
#
|
5
|
+
# (1) install this file,
|
6
|
+
#
|
7
|
+
# (2) load the script, and
|
8
|
+
# . ~/.profile.d/rb_optparse.bash
|
9
|
+
#
|
10
|
+
# (3) define completions in your .bashrc,
|
11
|
+
# rb_optparse command_using_optparse_1
|
12
|
+
# rb_optparse command_using_optparse_2
|
13
|
+
|
14
|
+
_rb_optparse() {
|
15
|
+
COMPREPLY=($("${COMP_WORDS[0]}" "--*-completion-bash=${COMP_WORDS[COMP_CWORD]}"))
|
16
|
+
return 0
|
17
|
+
}
|
18
|
+
|
19
|
+
rb_optparse () {
|
20
|
+
[ $# = 0 ] || complete -o default -F _rb_optparse "$@"
|
21
|
+
}
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# -*- zsh -*-
|
2
|
+
#
|
3
|
+
# Completion for zsh:
|
4
|
+
# (based on <http://d.hatena.ne.jp/rubikitch/20071002/zshcomplete>)
|
5
|
+
#
|
6
|
+
# (1) install this file.
|
7
|
+
# mkdir -p ~/.zsh.d
|
8
|
+
# cp rb_optparse.zsh ~/.zsh.d/rb_optparse.zsh
|
9
|
+
#
|
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"
|
14
|
+
#
|
15
|
+
# (3) restart zsh.
|
16
|
+
#
|
17
|
+
# (4) generate completion files once.
|
18
|
+
# generate-complete-function/ruby/optparse COMMAND1
|
19
|
+
# generate-complete-function/ruby/optparse COMMAND2
|
20
|
+
#
|
21
|
+
|
22
|
+
generate-complete-function/ruby/optparse ()
|
23
|
+
{
|
24
|
+
local cmpl="_${1:t}"
|
25
|
+
mkdir -p "${ZSH_COMPLETION_DIR-$HOME/.zsh.d/Completion}"
|
26
|
+
$1 "--*-completion-zsh=${1:t}" >! "${ZSH_COMPLETION_DIR-$HOME/.zsh.d/Completion}/$cmpl"
|
27
|
+
if [[ $(type -w "$cmpl") == "${cmpl}: function" ]]; then
|
28
|
+
unfunction "$cmpl"
|
29
|
+
autoload -U "$cmpl"
|
30
|
+
else
|
31
|
+
compinit "$cmpl"
|
32
|
+
fi
|
33
|
+
}
|
34
|
+
|
35
|
+
compdef _command generate-complete-function/ruby/optparse
|
36
|
+
|
37
|
+
for cmd in "$@"; do
|
38
|
+
generate-complete-function/ruby/optparse "$cmd"
|
39
|
+
done
|
data/optparse.gemspec
CHANGED
@@ -16,7 +16,6 @@ Gem::Specification.new do |spec|
|
|
16
16
|
spec.summary = %q{OptionParser is a class for command-line option analysis.}
|
17
17
|
spec.description = %q{OptionParser is a class for command-line option analysis.}
|
18
18
|
spec.homepage = "https://github.com/ruby/optparse"
|
19
|
-
spec.license = ["Ruby", "BSD-2-Clause"]
|
20
19
|
spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
|
21
20
|
spec.licenses = ["Ruby", "BSD-2-Clause"]
|
22
21
|
|
@@ -24,7 +23,9 @@ Gem::Specification.new do |spec|
|
|
24
23
|
spec.metadata["source_code_uri"] = spec.homepage
|
25
24
|
|
26
25
|
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
27
|
-
`git ls-files -z`.split("\x0").reject { |f|
|
26
|
+
`git ls-files -z`.split("\x0").reject { |f|
|
27
|
+
f.match(%r{\A(?:(?:test|spec|features)/|Gemfile|\.(?:editor|git))})
|
28
|
+
}
|
28
29
|
end
|
29
30
|
spec.bindir = "exe"
|
30
31
|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
@@ -0,0 +1,34 @@
|
|
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"
|
data/rakelib/epoch.rake
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
class << (helper = Bundler::GemHelper.instance)
|
2
|
+
def mainfile
|
3
|
+
"lib/#{File.basename(gemspec.loaded_from, ".gemspec")}.rb"
|
4
|
+
end
|
5
|
+
|
6
|
+
def update_version
|
7
|
+
File.open(mainfile, "r+b") do |f|
|
8
|
+
d = f.read
|
9
|
+
if d.sub!(/^(\s*OptionParser::Version\s*=\s*)".*"/) {$1 + gemspec.version.to_s.dump}
|
10
|
+
f.rewind
|
11
|
+
f.truncate(0)
|
12
|
+
f.print(d)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def commit_bump
|
18
|
+
sh(%W[git -C #{File.dirname(gemspec.loaded_from)} commit -m bump\ up\ to\ #{gemspec.version}
|
19
|
+
#{mainfile}])
|
20
|
+
end
|
21
|
+
|
22
|
+
def version=(v)
|
23
|
+
gemspec.version = v
|
24
|
+
update_version
|
25
|
+
commit_bump
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
major, minor, teeny = helper.gemspec.version.segments
|
30
|
+
|
31
|
+
task "bump:teeny" do
|
32
|
+
helper.version = Gem::Version.new("#{major}.#{minor}.#{teeny+1}")
|
33
|
+
end
|
34
|
+
|
35
|
+
task "bump:minor" do
|
36
|
+
helper.version = Gem::Version.new("#{major}.#{minor+1}.0")
|
37
|
+
end
|
38
|
+
|
39
|
+
task "bump:major" do
|
40
|
+
helper.version = Gem::Version.new("#{major+1}.0.0")
|
41
|
+
end
|
42
|
+
|
43
|
+
task "bump" => "bump:teeny"
|
44
|
+
|
45
|
+
task "tag" do
|
46
|
+
helper.__send__(:tag_version)
|
47
|
+
end
|
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.1.
|
4
|
+
version: 0.1.1
|
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: 2021-03-29 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: OptionParser is a class for command-line option analysis.
|
14
14
|
email:
|
@@ -17,15 +17,9 @@ executables: []
|
|
17
17
|
extensions: []
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
|
-
- ".github/workflows/test.yml"
|
21
|
-
- ".gitignore"
|
22
20
|
- COPYING
|
23
|
-
- Gemfile
|
24
|
-
- Gemfile.lock
|
25
21
|
- README.md
|
26
22
|
- Rakefile
|
27
|
-
- bin/console
|
28
|
-
- bin/setup
|
29
23
|
- lib/optionparser.rb
|
30
24
|
- lib/optparse.rb
|
31
25
|
- lib/optparse/ac.rb
|
@@ -35,7 +29,12 @@ files:
|
|
35
29
|
- lib/optparse/time.rb
|
36
30
|
- lib/optparse/uri.rb
|
37
31
|
- lib/optparse/version.rb
|
32
|
+
- misc/rb_optparse.bash
|
33
|
+
- misc/rb_optparse.zsh
|
38
34
|
- optparse.gemspec
|
35
|
+
- rakelib/changelogs.rake
|
36
|
+
- rakelib/epoch.rake
|
37
|
+
- rakelib/version.rake
|
39
38
|
homepage: https://github.com/ruby/optparse
|
40
39
|
licenses:
|
41
40
|
- Ruby
|
@@ -58,7 +57,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
58
57
|
- !ruby/object:Gem::Version
|
59
58
|
version: '0'
|
60
59
|
requirements: []
|
61
|
-
rubygems_version: 3.
|
60
|
+
rubygems_version: 3.3.0.dev
|
62
61
|
signing_key:
|
63
62
|
specification_version: 4
|
64
63
|
summary: OptionParser is a class for command-line option analysis.
|
data/.github/workflows/test.yml
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
name: test
|
2
|
-
|
3
|
-
on: [push, pull_request]
|
4
|
-
|
5
|
-
jobs:
|
6
|
-
build:
|
7
|
-
name: build (${{ matrix.ruby }} / ${{ matrix.os }})
|
8
|
-
strategy:
|
9
|
-
matrix:
|
10
|
-
ruby: [ 2.7, 2.6, 2.5, head ]
|
11
|
-
os: [ ubuntu-latest, macos-latest ]
|
12
|
-
runs-on: ${{ matrix.os }}
|
13
|
-
steps:
|
14
|
-
- uses: actions/checkout@master
|
15
|
-
- name: Set up Ruby
|
16
|
-
uses: ruby/setup-ruby@v1
|
17
|
-
with:
|
18
|
-
ruby-version: ${{ matrix.ruby }}
|
19
|
-
- name: Install dependencies
|
20
|
-
run: |
|
21
|
-
gem install bundler --no-document
|
22
|
-
bundle install
|
23
|
-
- name: Run test
|
24
|
-
run: rake test
|
data/.gitignore
DELETED
data/Gemfile
DELETED
data/Gemfile.lock
DELETED
data/bin/console
DELETED