parseopt 0.3.1 → 0.3.2
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.
- checksums.yaml +4 -4
- data/README.md +3 -0
- metadata +35 -9
- data/Rakefile +0 -7
- data/test/test_optparse.rb +0 -132
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e71504505679f5006a0295dadbe34a54b1a89134e3eea20afc7de0276b87bf82
|
4
|
+
data.tar.gz: e033c551ba4bfeb45c7dd5a60805fff5f41c93de08df8fd3fd2bf1a08780ac43
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99fd1dc52decc99d6ba058968646fe4486f1879ad960785a452bdb7f01b2be3905f34d0bb60edee53c28f024fbeb5c0ff3b85fc44b2c0cfc70f6f6a6db678956
|
7
|
+
data.tar.gz: b75cc225b26888f84098758b44bb840dd522e03674d9fc638b8cbf80ed2a89d91c02199354b64a0334c4d11b089dedbaa75d53233a655c49713b3409556d6478
|
data/README.md
CHANGED
metadata
CHANGED
@@ -1,25 +1,52 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: parseopt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Felipe Contreras
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
11
|
+
date: 2023-04-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '13'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '13'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: test-unit
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3'
|
13
41
|
description:
|
14
42
|
email: felipe.contreras@gmail.com
|
15
43
|
executables: []
|
16
44
|
extensions: []
|
17
|
-
extra_rdoc_files:
|
45
|
+
extra_rdoc_files:
|
46
|
+
- README.md
|
18
47
|
files:
|
19
48
|
- README.md
|
20
|
-
- Rakefile
|
21
49
|
- lib/parseopt.rb
|
22
|
-
- test/test_optparse.rb
|
23
50
|
homepage: https://github.com/felipec/ruby-parseopt
|
24
51
|
licenses:
|
25
52
|
- GPL-2.0-only
|
@@ -39,9 +66,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
39
66
|
- !ruby/object:Gem::Version
|
40
67
|
version: '0'
|
41
68
|
requirements: []
|
42
|
-
rubygems_version: 3.
|
69
|
+
rubygems_version: 3.4.7
|
43
70
|
signing_key:
|
44
71
|
specification_version: 4
|
45
72
|
summary: A very simple option parser.
|
46
|
-
test_files:
|
47
|
-
- test/test_optparse.rb
|
73
|
+
test_files: []
|
data/Rakefile
DELETED
data/test/test_optparse.rb
DELETED
@@ -1,132 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
require 'parseopt'
|
3
|
-
require 'stringio'
|
4
|
-
|
5
|
-
class ParseOptTest < Test::Unit::TestCase
|
6
|
-
|
7
|
-
def test_bool
|
8
|
-
bool = false
|
9
|
-
run_opts('b', %w[-b]) { |v| bool = v }
|
10
|
-
assert(bool)
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_empty_bool
|
14
|
-
bool = false
|
15
|
-
run_opts('b', []) { |v| bool = v }
|
16
|
-
assert(!bool)
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_unknown
|
20
|
-
run_opts('b', %w[-x], %w[-x])
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_other
|
24
|
-
run_opts('b', %w[foo], %w[foo])
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_other_then_bool
|
28
|
-
bool = false
|
29
|
-
run_opts('b', %w[foo -b], %w[foo]) { |v| bool = v }
|
30
|
-
assert(bool)
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_double_dash
|
34
|
-
run_opts('b', %w[-- -b], %w[-b])
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_value
|
38
|
-
str = 'default'
|
39
|
-
run_opts('s', %w[-sfoo]) { |v| str = v }
|
40
|
-
assert_equal('foo', str)
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_long
|
44
|
-
bool = false
|
45
|
-
run_opts(['b', 'bool'], %w[--bool]) { |v| bool = v }
|
46
|
-
assert(bool)
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_long_value
|
50
|
-
str = 'default'
|
51
|
-
run_opts(['s', 'string'], %w[--string=foo]) { |v| str = v }
|
52
|
-
assert_equal('foo', str)
|
53
|
-
end
|
54
|
-
|
55
|
-
def test_no_long
|
56
|
-
bool = true
|
57
|
-
run_opts(['b', 'bool'], %w[--no-bool]) { |v| bool = v }
|
58
|
-
assert(!bool)
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_init
|
62
|
-
bool = false
|
63
|
-
ParseOpt.new('test script') do |opts|
|
64
|
-
opts.on('b', 'bool') { |v| bool = v }
|
65
|
-
end.parse(%w[-b])
|
66
|
-
assert(bool)
|
67
|
-
end
|
68
|
-
|
69
|
-
def test_usage
|
70
|
-
expected = <<~EOF
|
71
|
-
usage:
|
72
|
-
-b, --bool
|
73
|
-
EOF
|
74
|
-
run_usage(['b', 'bool'], expected) { |opts| opts.usage }
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_help
|
78
|
-
expected = <<~EOF
|
79
|
-
usage:
|
80
|
-
-b, --bool
|
81
|
-
EOF
|
82
|
-
run_usage(['b', 'bool'], expected) do |opts|
|
83
|
-
begin
|
84
|
-
opts.parse(%w[-h])
|
85
|
-
rescue SystemExit
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
def test_custom_usage
|
91
|
-
expected = <<~EOF
|
92
|
-
usage: test script
|
93
|
-
-b, --bool
|
94
|
-
EOF
|
95
|
-
run_usage(['b', 'bool'], expected) do |opts|
|
96
|
-
opts.usage = 'test script'
|
97
|
-
opts.usage
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
def test_option_help
|
102
|
-
expected = <<~EOF
|
103
|
-
usage:
|
104
|
-
-b, --bool Boolean
|
105
|
-
EOF
|
106
|
-
run_usage(['b', 'bool', 'Boolean'], expected) { |opts| opts.usage }
|
107
|
-
end
|
108
|
-
|
109
|
-
private
|
110
|
-
|
111
|
-
def run_opts(opt, args, result = [])
|
112
|
-
opts = ParseOpt.new
|
113
|
-
opts.on(*opt) { |v| yield v }
|
114
|
-
assert_equal(result, opts.parse(args))
|
115
|
-
end
|
116
|
-
|
117
|
-
def run_usage(opt, expected)
|
118
|
-
opts = ParseOpt.new
|
119
|
-
opts.on(*opt)
|
120
|
-
assert_equal(expected, capture { yield opts })
|
121
|
-
end
|
122
|
-
|
123
|
-
def capture
|
124
|
-
stdout_save = $stdout
|
125
|
-
$stdout = StringIO.new
|
126
|
-
yield
|
127
|
-
$stdout.string
|
128
|
-
ensure
|
129
|
-
$stdout = stdout_save
|
130
|
-
end
|
131
|
-
|
132
|
-
end
|