getopt 1.6.0 → 1.7.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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/CHANGES.md +9 -2
- data/Gemfile +2 -3
- data/MANIFEST.md +2 -2
- data/README.md +5 -2
- data/Rakefile +12 -2
- data/getopt.gemspec +12 -7
- data/lib/getopt/long.rb +246 -224
- data/lib/getopt/std.rb +91 -91
- data/lib/getopt/version.rb +3 -1
- data/spec/getopt_long_spec.rb +213 -121
- data/spec/getopt_std_spec.rb +79 -71
- data.tar.gz.sig +0 -0
- metadata +36 -8
- metadata.gz.sig +0 -0
data/spec/getopt_std_spec.rb
CHANGED
|
@@ -1,122 +1,130 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
###################################################################
|
|
2
4
|
# test_getopt_std.rb
|
|
3
5
|
#
|
|
4
|
-
# Test suite for the Getopt::
|
|
6
|
+
# Test suite for the Getopt::described_class class. You should run this test
|
|
5
7
|
# via the 'rake test' task.
|
|
6
8
|
###################################################################
|
|
7
9
|
require 'rspec'
|
|
8
10
|
require 'getopt/std'
|
|
9
|
-
include Getopt
|
|
10
11
|
|
|
11
12
|
RSpec.describe Getopt::Std do
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
expect(Std::VERSION).to be_frozen
|
|
13
|
+
after do
|
|
14
|
+
ARGV.clear
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
-
example
|
|
18
|
-
expect(
|
|
19
|
-
expect
|
|
20
|
-
expect(Std.getopts("ID")).to be_kind_of(Hash)
|
|
17
|
+
example 'version' do
|
|
18
|
+
expect(described_class::VERSION).to eq('1.7.1')
|
|
19
|
+
expect(described_class::VERSION).to be_frozen
|
|
21
20
|
end
|
|
22
21
|
|
|
23
|
-
example
|
|
24
|
-
|
|
25
|
-
expect
|
|
22
|
+
example 'getopts basic functionality' do
|
|
23
|
+
expect(described_class).to respond_to(:getopts)
|
|
24
|
+
expect{ described_class.getopts('ID') }.not_to raise_error
|
|
25
|
+
expect(described_class.getopts('ID')).to be_a(Hash)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
example 'getopts with separated switches' do
|
|
29
|
+
ARGV.push('-I', '-D')
|
|
30
|
+
expect(described_class.getopts('ID')).to eq({'I' => true, 'D' => true})
|
|
26
31
|
end
|
|
27
32
|
|
|
28
33
|
# Inspired by RF bug #23477
|
|
29
|
-
example
|
|
30
|
-
ARGV.push(
|
|
31
|
-
expect(
|
|
34
|
+
example 'getopts with arguments that match switch are ok' do
|
|
35
|
+
ARGV.push('-d', 'd')
|
|
36
|
+
expect(described_class.getopts('d:')).to eq({'d' => 'd'})
|
|
37
|
+
|
|
38
|
+
ARGV.push('-d', 'ad')
|
|
39
|
+
expect(described_class.getopts('d:')).to eq({'d' => 'ad'})
|
|
32
40
|
|
|
33
|
-
ARGV.push(
|
|
34
|
-
expect(
|
|
41
|
+
ARGV.push('-a', 'ad')
|
|
42
|
+
expect(described_class.getopts('d:a:')).to eq({'a' => 'ad'})
|
|
35
43
|
|
|
36
|
-
ARGV.push(
|
|
37
|
-
expect(
|
|
44
|
+
ARGV.push('-a', 'da')
|
|
45
|
+
expect(described_class.getopts('d:a:')).to eq({'a' => 'da'})
|
|
38
46
|
|
|
39
|
-
ARGV.push(
|
|
40
|
-
expect(
|
|
47
|
+
ARGV.push('-a', 'd')
|
|
48
|
+
expect(described_class.getopts('d:a:')).to eq({'a' => 'd'})
|
|
41
49
|
|
|
42
|
-
ARGV.push(
|
|
43
|
-
expect(
|
|
50
|
+
ARGV.push('-a', 'dad')
|
|
51
|
+
expect(described_class.getopts('d:a:')).to eq({'a' => 'dad'})
|
|
44
52
|
|
|
45
|
-
ARGV.push(
|
|
46
|
-
expect(
|
|
53
|
+
ARGV.push('-d', 'd', '-a', 'a')
|
|
54
|
+
expect(described_class.getopts('d:a:')).to eq({'d' => 'd', 'a' => 'a'})
|
|
55
|
+
end
|
|
47
56
|
|
|
48
|
-
|
|
49
|
-
|
|
57
|
+
example 'getopts with joined switches' do
|
|
58
|
+
ARGV.push('-ID')
|
|
59
|
+
expect(described_class.getopts('ID')).to eq({'I' => true, 'D' => true})
|
|
50
60
|
end
|
|
51
61
|
|
|
52
|
-
example
|
|
53
|
-
ARGV.push(
|
|
54
|
-
expect(
|
|
62
|
+
example 'getopts accepts question mark as a switch' do
|
|
63
|
+
ARGV.push('-?')
|
|
64
|
+
expect(described_class.getopts('?')).to eq({'?' => true})
|
|
55
65
|
end
|
|
56
66
|
|
|
57
|
-
example
|
|
58
|
-
ARGV.push(
|
|
59
|
-
expect(
|
|
67
|
+
example 'getopts with separated switches and mandatory argument' do
|
|
68
|
+
ARGV.push('-o', 'hello', '-I', '-D')
|
|
69
|
+
expect(described_class.getopts('o:ID')).to eq({'o' => 'hello', 'I' => true, 'D' => true})
|
|
60
70
|
end
|
|
61
71
|
|
|
62
|
-
example
|
|
63
|
-
ARGV.push(
|
|
64
|
-
expect(
|
|
72
|
+
example 'getopts with joined switches and mandatory argument' do
|
|
73
|
+
ARGV.push('-IDo', 'hello')
|
|
74
|
+
expect(described_class.getopts('o:ID')).to eq({'o' => 'hello', 'I' => true, 'D' => true})
|
|
65
75
|
end
|
|
66
76
|
|
|
67
|
-
example
|
|
68
|
-
expect{
|
|
69
|
-
expect(
|
|
70
|
-
expect(
|
|
71
|
-
expect(
|
|
77
|
+
example 'getopts with no arguments' do
|
|
78
|
+
expect{ described_class.getopts('ID') }.not_to raise_error
|
|
79
|
+
expect(described_class.getopts('ID')).to eq({})
|
|
80
|
+
expect(described_class.getopts('ID')['I']).to be_nil
|
|
81
|
+
expect(described_class.getopts('ID')['D']).to be_nil
|
|
72
82
|
end
|
|
73
83
|
|
|
74
84
|
# If a switch that accepts an argument appears more than once, the values
|
|
75
85
|
# are rolled into an array.
|
|
76
|
-
example
|
|
77
|
-
ARGV.push(
|
|
78
|
-
expect(
|
|
86
|
+
example 'getopts with switch repeated' do
|
|
87
|
+
ARGV.push('-I', '-I', '-o', 'hello', '-o', 'world')
|
|
88
|
+
expect(described_class.getopts('o:ID')).to eq({'o' => ['hello', 'world'], 'I' => true})
|
|
79
89
|
end
|
|
80
90
|
|
|
81
91
|
# EXPECTED ERRORS
|
|
82
92
|
|
|
83
|
-
example
|
|
84
|
-
|
|
85
|
-
expect{ Std.getopts("d:a:") }.to raise_error(Getopt::Std::Error)
|
|
86
|
-
|
|
87
|
-
ARGV.push("-d", "-a")
|
|
88
|
-
expect{ Std.getopts("d:a:") }.to raise_error(Getopt::Std::Error)
|
|
93
|
+
example 'getopts raises expected errors when passing a switch to another switch' do
|
|
94
|
+
msg = "cannot use switch '-d' as argument to another switch"
|
|
89
95
|
|
|
90
|
-
ARGV.push(
|
|
91
|
-
expect{
|
|
96
|
+
ARGV.push('-d', '-d')
|
|
97
|
+
expect{ described_class.getopts('d:a:') }.to raise_error(Getopt::Std::Error)
|
|
92
98
|
|
|
93
|
-
ARGV.push(
|
|
94
|
-
expect{
|
|
95
|
-
end
|
|
99
|
+
ARGV.push('-d', '-a')
|
|
100
|
+
expect{ described_class.getopts('d:a:') }.to raise_error(Getopt::Std::Error)
|
|
96
101
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
expect{ Std.getopts("I:D") }.to raise_error(Std::Error)
|
|
102
|
+
ARGV.push('-a', '-d')
|
|
103
|
+
expect{ described_class.getopts('d:a:') }.to raise_error(Getopt::Std::Error)
|
|
100
104
|
|
|
101
|
-
ARGV.push(
|
|
102
|
-
expect{
|
|
105
|
+
ARGV.push('-d', '-d')
|
|
106
|
+
expect{ described_class.getopts('d:a:') }.to raise_error(Getopt::Std::Error, msg)
|
|
103
107
|
end
|
|
104
108
|
|
|
105
|
-
example
|
|
106
|
-
ARGV.push(
|
|
107
|
-
expect{
|
|
109
|
+
example 'getopts raises expected errors if argument is missing' do
|
|
110
|
+
ARGV.push('-ID')
|
|
111
|
+
expect{ described_class.getopts('I:D') }.to raise_error(Getopt::Std::Error)
|
|
108
112
|
|
|
109
|
-
ARGV.push(
|
|
110
|
-
expect{
|
|
113
|
+
ARGV.push('-ID')
|
|
114
|
+
expect{ described_class.getopts('ID:') }.to raise_error(Getopt::Std::Error)
|
|
111
115
|
end
|
|
112
116
|
|
|
113
|
-
example
|
|
114
|
-
|
|
115
|
-
expect{
|
|
116
|
-
|
|
117
|
+
example 'getopts raises expected errors if there are extra arguments' do
|
|
118
|
+
ARGV.push('-I', '-D', '-X')
|
|
119
|
+
expect{ described_class.getopts('ID') }.to raise_error(Getopt::Std::Error)
|
|
120
|
+
|
|
121
|
+
ARGV.push('-IDX')
|
|
122
|
+
expect{ described_class.getopts('ID') }.to raise_error(Getopt::Std::Error, "invalid option 'X'")
|
|
117
123
|
end
|
|
118
124
|
|
|
119
|
-
|
|
120
|
-
|
|
125
|
+
example 'getopts raises expected errors with invalid or no arguments' do
|
|
126
|
+
expect{ described_class.getopts }.to raise_error(ArgumentError)
|
|
127
|
+
expect{ described_class.getopts(0) }.to raise_error(NoMethodError)
|
|
128
|
+
expect{ described_class.getopts(nil) }.to raise_error(NoMethodError)
|
|
121
129
|
end
|
|
122
130
|
end
|
data.tar.gz.sig
CHANGED
|
Binary file
|
metadata
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: getopt
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.7.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Daniel J. Berger
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain:
|
|
11
10
|
- |
|
|
@@ -35,7 +34,7 @@ cert_chain:
|
|
|
35
34
|
ORVCZpRuCPpmC8qmqxUnARDArzucjaclkxjLWvCVHeFa9UP7K3Nl9oTjJNv+7/jM
|
|
36
35
|
WZs4eecIcUc4tKdHxcAJ0MO/Dkqq7hGaiHpwKY76wQ1+8xAh
|
|
37
36
|
-----END CERTIFICATE-----
|
|
38
|
-
date:
|
|
37
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
39
38
|
dependencies:
|
|
40
39
|
- !ruby/object:Gem::Dependency
|
|
41
40
|
name: rake
|
|
@@ -65,6 +64,34 @@ dependencies:
|
|
|
65
64
|
- - "~>"
|
|
66
65
|
- !ruby/object:Gem::Version
|
|
67
66
|
version: '3.9'
|
|
67
|
+
- !ruby/object:Gem::Dependency
|
|
68
|
+
name: rubocop
|
|
69
|
+
requirement: !ruby/object:Gem::Requirement
|
|
70
|
+
requirements:
|
|
71
|
+
- - ">="
|
|
72
|
+
- !ruby/object:Gem::Version
|
|
73
|
+
version: '0'
|
|
74
|
+
type: :development
|
|
75
|
+
prerelease: false
|
|
76
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
77
|
+
requirements:
|
|
78
|
+
- - ">="
|
|
79
|
+
- !ruby/object:Gem::Version
|
|
80
|
+
version: '0'
|
|
81
|
+
- !ruby/object:Gem::Dependency
|
|
82
|
+
name: rubocop-rspec
|
|
83
|
+
requirement: !ruby/object:Gem::Requirement
|
|
84
|
+
requirements:
|
|
85
|
+
- - ">="
|
|
86
|
+
- !ruby/object:Gem::Version
|
|
87
|
+
version: '0'
|
|
88
|
+
type: :development
|
|
89
|
+
prerelease: false
|
|
90
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
91
|
+
requirements:
|
|
92
|
+
- - ">="
|
|
93
|
+
- !ruby/object:Gem::Version
|
|
94
|
+
version: '0'
|
|
68
95
|
description: |2
|
|
69
96
|
The getopt library provides two different command line option parsers.
|
|
70
97
|
They are meant as easier and more convenient replacements for the
|
|
@@ -99,11 +126,13 @@ licenses:
|
|
|
99
126
|
metadata:
|
|
100
127
|
homepage_uri: https://github.com/djberg96/getopt
|
|
101
128
|
bug_tracker_uri: https://github.com/djberg96/getopt/issues
|
|
102
|
-
changelog_uri: https://github.com/djberg96/getopt/blob/
|
|
129
|
+
changelog_uri: https://github.com/djberg96/getopt/blob/main/CHANGES.md
|
|
103
130
|
documentation_uri: https://github.com/djberg96/getopt/wiki
|
|
104
131
|
source_code_uri: https://github.com/djberg96/getopt
|
|
105
132
|
wiki_uri: https://github.com/djberg96/getopt/wiki
|
|
106
|
-
|
|
133
|
+
rubygems_mfa_required: 'true'
|
|
134
|
+
github_repo: https://github.com/djberg96/getopt
|
|
135
|
+
funding_uri: https://github.com/sponsors/djberg96
|
|
107
136
|
rdoc_options: []
|
|
108
137
|
require_paths:
|
|
109
138
|
- lib
|
|
@@ -118,10 +147,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
118
147
|
- !ruby/object:Gem::Version
|
|
119
148
|
version: '0'
|
|
120
149
|
requirements: []
|
|
121
|
-
rubygems_version:
|
|
122
|
-
signing_key:
|
|
150
|
+
rubygems_version: 4.0.6
|
|
123
151
|
specification_version: 4
|
|
124
152
|
summary: Getopt::Std and Getopt::Long option parsers for Ruby
|
|
125
153
|
test_files:
|
|
126
|
-
- spec/getopt_std_spec.rb
|
|
127
154
|
- spec/getopt_long_spec.rb
|
|
155
|
+
- spec/getopt_std_spec.rb
|
metadata.gz.sig
CHANGED
|
Binary file
|