getopt 1.4.2 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/{CHANGES → CHANGES.md} +39 -16
- data/Gemfile +3 -0
- data/LICENSE +177 -0
- data/{MANIFEST → MANIFEST.md} +12 -5
- data/README.md +197 -0
- data/Rakefile +13 -21
- data/certs/djberg96_pub.pem +26 -0
- data/getopt.gemspec +15 -6
- data/lib/getopt-long.rb +1 -0
- data/lib/getopt-std.rb +1 -0
- data/lib/getopt.rb +2 -0
- data/lib/getopt/long.rb +6 -6
- data/lib/getopt/std.rb +3 -3
- data/lib/getopt/version.rb +6 -0
- data/spec/getopt_long_spec.rb +279 -0
- data/spec/getopt_std_spec.rb +122 -0
- metadata +74 -24
- metadata.gz.sig +0 -0
- data/README +0 -191
- data/test/test_getopt_long.rb +0 -264
- data/test/test_getopt_std.rb +0 -125
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8fb3a945490a612eaf1e604f83dea2a0e1adecd5b3469c83e214bcb99eacd076
|
4
|
+
data.tar.gz: 13521ceb0616ee5e34e6434e6b2c94dc12be959eec7ca210977c1b5ce903c723
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 528a9e0c5f0c7aed85fc510e8f823b75b9b40b8f5142a8373474a4f643005ce1ab497f42657802f30dc8b0f002a6154ada4b246a93fa2ee9cc84c197f7621140
|
7
|
+
data.tar.gz: 2ff2aaf442063fbb69d5a96eff5e098b2e10d7472922263424ee9fd3d0539916d08201b04635de80b3abec9a8b40ebe24732eb9ef5ddd705c488d4209b198865
|
checksums.yaml.gz.sig
ADDED
Binary file
|
data.tar.gz.sig
ADDED
Binary file
|
data/{CHANGES → CHANGES.md}
RENAMED
@@ -1,21 +1,44 @@
|
|
1
|
-
|
1
|
+
## 1.6.0 - 2-Mar-2021
|
2
|
+
* Switch from test-unit to rspec, and update the Rakefile and gemspec accordingly.
|
3
|
+
* Added a Gemfile.
|
4
|
+
|
5
|
+
## 1.5.1 - 23-Mar-2020
|
6
|
+
* Properly add a LICENSE file since the Apache-2.0 license requires it.
|
7
|
+
* Added explicit .rdoc extensions to the README, CHANGES and MANIFEST files,
|
8
|
+
mostly so they look nicer on github.
|
9
|
+
|
10
|
+
## 1.5.0 - 25-Jan-2019
|
11
|
+
* Changed license to Apache-2.0.
|
12
|
+
|
13
|
+
## 1.4.4 - 24-Mar-2018
|
14
|
+
* Fixed a deprecation warning.
|
15
|
+
* Now requires Ruby 2.2 or later.
|
16
|
+
* Added metadata to the gemspec.
|
17
|
+
* Updated the cert.
|
18
|
+
|
19
|
+
## 1.4.3 - 7-Jan-2016
|
20
|
+
* This gem is now signed.
|
21
|
+
* The gem related tasks in the Rakefile now assume Rubygems 2.x.
|
22
|
+
* Added getopt.rb, getopt-std.rb and getopt-long.rb files for convenience.
|
23
|
+
|
24
|
+
## 1.4.2 - 12-Oct-2014
|
2
25
|
* Updated Rakefile, README and gemspec.
|
3
26
|
* Minor updates to the test file and examples.
|
4
27
|
|
5
|
-
|
28
|
+
## 1.4.1 - 17-Jul-2011
|
6
29
|
* Now works with Ruby 1.9.x. Thanks go to Shura for the patch.
|
7
30
|
* Refactored the gemspec. Gem building code is now handled by Rake tasks.
|
8
31
|
* Refactored the Rakefile. Added a default task, removed the old install
|
9
32
|
task, and namespaced the gem related tasks.
|
10
33
|
|
11
|
-
|
34
|
+
## 1.4.0 - 5-Sep-2009
|
12
35
|
* Fixed a packaging bug where the libs weren't actually being included! Gah!
|
13
36
|
Thanks go to Steven Hilton for the spot.
|
14
37
|
* Other minor refactorings to the gemspec.
|
15
38
|
* The release number does not reflect any code changes. I simply ran out
|
16
39
|
of numbers. :)
|
17
40
|
|
18
|
-
|
41
|
+
## 1.3.9 - 29-Jul-2009
|
19
42
|
* Now compatible with Ruby 1.9.x.
|
20
43
|
* Gemspec updates, including a license change to Artistic 2.0.
|
21
44
|
* Added individual rake tasks for testing Getopt::Long and Getopt::Std.
|
@@ -23,7 +46,7 @@
|
|
23
46
|
* The test-unit library was switched from a standard dependency to a
|
24
47
|
development dependency.
|
25
48
|
|
26
|
-
|
49
|
+
## 1.3.8 - 6-Jan-2008
|
27
50
|
* Fixed RF bug #23477 - Getopt::Std inadvertently raises an error if you
|
28
51
|
pass a letter (without a hyphen) as an argument to a switch that matches
|
29
52
|
that letter, e.g. "-a a" should be legal. Thanks go to an anonymous user
|
@@ -31,7 +54,7 @@
|
|
31
54
|
* Added tests for RF bug #23477.
|
32
55
|
* Added Test::Unit 2.x as a prerequisite.
|
33
56
|
|
34
|
-
|
57
|
+
## 1.3.7 - 27-Jul-2008
|
35
58
|
* Fixed a potential infinite hash recursion bug in ARGV processing. This
|
36
59
|
was smoked out as the result of the alternate hash implementations in
|
37
60
|
JRuby and Ruby 1.9.
|
@@ -39,41 +62,41 @@
|
|
39
62
|
* Removed the ts_all.rb file, and renamed the other test files. The Rakefile
|
40
63
|
test task was updated accordingly.
|
41
64
|
|
42
|
-
|
65
|
+
## 1.3.6 - 8-Aug-2007
|
43
66
|
* The Getopt::StdError class is now Getopt::Std::Error.
|
44
67
|
* The Getopt::LongError class is now Getopt::Long::Error.
|
45
68
|
* Added some inline rdoc documentation to the source code.
|
46
69
|
* Added a Rakefile with tasks for installation and testing.
|
47
70
|
* Removed the install.rb file - use the 'rake install' task instead.
|
48
71
|
|
49
|
-
|
72
|
+
## 1.3.5 - 5-Jul-2006
|
50
73
|
* Fixed a bug where multiple long switches with the same first character
|
51
74
|
could cause invalid results. Thanks go to Michael Campbell for the spot.
|
52
75
|
* Added documentation to the README file that explains what happens if you
|
53
76
|
specify multiple long switches with the same first character and no short
|
54
77
|
switch alias.
|
55
78
|
|
56
|
-
|
79
|
+
## 1.3.4 - 7-Mar-2006
|
57
80
|
* Fixed Getopt::Long so that it can handle embedded hyphens in the long
|
58
81
|
form, e.g. --foo-bar. Thanks go to Mark Meves for the spot.
|
59
82
|
* Corresponding test suite additions.
|
60
83
|
* Added example to the 'example_long.rb' file that uses long form with
|
61
84
|
embedded hyphens.
|
62
85
|
|
63
|
-
|
86
|
+
## 1.3.3 - 22-Feb-2006
|
64
87
|
* Bug fix for the two argument form of Getopt::Long.getopts.
|
65
88
|
* Corresponding test suite additions.
|
66
89
|
|
67
|
-
|
90
|
+
## 1.3.2 - 13-Feb-2006
|
68
91
|
* Improved error message if an option is passed without a preceding switch.
|
69
92
|
* Minor documentation fixes and clarifications.
|
70
93
|
|
71
|
-
|
94
|
+
## 1.3.1 - 18-Nov-2005
|
72
95
|
* Added support for compressed switches with getopt/long.
|
73
96
|
* More tests.
|
74
97
|
* Fixed a bug in the gemspec.
|
75
98
|
|
76
|
-
|
99
|
+
## 1.3.0 - 4-Nov-2005
|
77
100
|
* Added the Getopt::Long class (long.rb). This is a complete revamp of the
|
78
101
|
old getoptlong package, with ideas tossed in from Perl's Getopt::Long
|
79
102
|
package. See the README and example script for more detail.
|
@@ -81,14 +104,14 @@
|
|
81
104
|
* Added lots of documentation to the README file.
|
82
105
|
* Updated the MANIFEST, test suite, etc.
|
83
106
|
|
84
|
-
|
107
|
+
## 1.2.0 - 24-Oct-2005
|
85
108
|
* Altered the way multiple occurrences of the same switch are handled, for
|
86
109
|
those switches that accept arguments.
|
87
110
|
|
88
|
-
|
111
|
+
## 1.1.0 - 7-Oct-2005
|
89
112
|
* Changed parser, added a bit stricter enforcement
|
90
113
|
* Now handles squished arguments properly, e.g. "-ID" as well as "-I -D"
|
91
114
|
* Some test suite changes
|
92
115
|
|
93
|
-
|
116
|
+
## 1.0.0 - 5-Oct-2005
|
94
117
|
* Initial commit
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,177 @@
|
|
1
|
+
|
2
|
+
Apache License
|
3
|
+
Version 2.0, January 2004
|
4
|
+
http://www.apache.org/licenses/
|
5
|
+
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
7
|
+
|
8
|
+
1. Definitions.
|
9
|
+
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
12
|
+
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
14
|
+
the copyright owner that is granting the License.
|
15
|
+
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
17
|
+
other entities that control, are controlled by, or are under common
|
18
|
+
control with that entity. For the purposes of this definition,
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
20
|
+
direction or management of such entity, whether by contract or
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
23
|
+
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
25
|
+
exercising permissions granted by this License.
|
26
|
+
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
28
|
+
including but not limited to software source code, documentation
|
29
|
+
source, and configuration files.
|
30
|
+
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
32
|
+
transformation or translation of a Source form, including but
|
33
|
+
not limited to compiled object code, generated documentation,
|
34
|
+
and conversions to other media types.
|
35
|
+
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
37
|
+
Object form, made available under the License, as indicated by a
|
38
|
+
copyright notice that is included in or attached to the work
|
39
|
+
(an example is provided in the Appendix below).
|
40
|
+
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
47
|
+
the Work and Derivative Works thereof.
|
48
|
+
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
50
|
+
the original version of the Work and any modifications or additions
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
62
|
+
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
65
|
+
subsequently incorporated within the Work.
|
66
|
+
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
73
|
+
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
79
|
+
where such license applies only to those patent claims licensable
|
80
|
+
by such Contributor that are necessarily infringed by their
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
83
|
+
institute patent litigation against any entity (including a
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
86
|
+
or contributory patent infringement, then any patent licenses
|
87
|
+
granted to You under this License for that Work shall terminate
|
88
|
+
as of the date such litigation is filed.
|
89
|
+
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
92
|
+
modifications, and in Source or Object form, provided that You
|
93
|
+
meet the following conditions:
|
94
|
+
|
95
|
+
(a) You must give any other recipients of the Work or
|
96
|
+
Derivative Works a copy of this License; and
|
97
|
+
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
99
|
+
stating that You changed the files; and
|
100
|
+
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
103
|
+
attribution notices from the Source form of the Work,
|
104
|
+
excluding those notices that do not pertain to any part of
|
105
|
+
the Derivative Works; and
|
106
|
+
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
109
|
+
include a readable copy of the attribution notices contained
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
112
|
+
of the following places: within a NOTICE text file distributed
|
113
|
+
as part of the Derivative Works; within the Source form or
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
115
|
+
within a display generated by the Derivative Works, if and
|
116
|
+
wherever such third-party notices normally appear. The contents
|
117
|
+
of the NOTICE file are for informational purposes only and
|
118
|
+
do not modify the License. You may add Your own attribution
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
121
|
+
that such additional attribution notices cannot be construed
|
122
|
+
as modifying the License.
|
123
|
+
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
125
|
+
may provide additional or different license terms and conditions
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
129
|
+
the conditions stated in this License.
|
130
|
+
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
134
|
+
this License, without any additional terms or conditions.
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
136
|
+
the terms of any separate license agreement you may have executed
|
137
|
+
with Licensor regarding such Contributions.
|
138
|
+
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
141
|
+
except as required for reasonable and customary use in describing the
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
143
|
+
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
153
|
+
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
159
|
+
incidental, or consequential damages of any character arising as a
|
160
|
+
result of this License or out of the use or inability to use the
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
163
|
+
other commercial damages or losses), even if such Contributor
|
164
|
+
has been advised of the possibility of such damages.
|
165
|
+
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
169
|
+
or other liability obligations and/or rights consistent with this
|
170
|
+
License. However, in accepting such obligations, You may act only
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
175
|
+
of your accepting any such warranty or additional liability.
|
176
|
+
|
177
|
+
END OF TERMS AND CONDITIONS
|
data/{MANIFEST → MANIFEST.md}
RENAMED
@@ -1,11 +1,18 @@
|
|
1
|
-
* CHANGES
|
2
|
-
*
|
3
|
-
*
|
1
|
+
* CHANGES.md
|
2
|
+
* LICENSE
|
3
|
+
* MANIFEST.md
|
4
|
+
* README.md
|
5
|
+
* Gemfile
|
4
6
|
* Rakefile
|
5
7
|
* getopt.gemspec
|
8
|
+
* certs/djberg96_pub.pem
|
6
9
|
* examples/example_std.rb
|
7
10
|
* examples/example_long.rb
|
8
|
-
* lib/getopt
|
11
|
+
* lib/getopt.rb
|
12
|
+
* lib/getopt-long.rb
|
13
|
+
* lib/getopt-std.rb
|
9
14
|
* lib/getopt/long.rb
|
10
|
-
*
|
15
|
+
* lib/getopt/std.rb
|
16
|
+
* lib/getopt/version.rb
|
11
17
|
* test/test_getopt_long.rb
|
18
|
+
* test/test_getopt_std.rb
|
data/README.md
ADDED
@@ -0,0 +1,197 @@
|
|
1
|
+
## Description
|
2
|
+
The getopt Ruby library is a simple command line parsing library. It implements
|
3
|
+
a `Getopt::Std` class for basic command line parsing, as well as a `Getopt::Long`
|
4
|
+
class for more advanced command line parsing.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
`gem install getopt`
|
8
|
+
|
9
|
+
## Synopsis
|
10
|
+
### Getopt::Std
|
11
|
+
```ruby
|
12
|
+
require 'getopt/std'
|
13
|
+
|
14
|
+
# Look for -o with argument, and -I and -D boolean arguments
|
15
|
+
opt = Getopt::Std.getopts("o:ID")
|
16
|
+
|
17
|
+
if opt["I"]
|
18
|
+
# Do something if -I passed
|
19
|
+
|
20
|
+
if opt["D"]
|
21
|
+
# Do something if -D passed
|
22
|
+
|
23
|
+
if opt["o"]
|
24
|
+
case opt["o"]
|
25
|
+
# blah, blah, blah
|
26
|
+
end
|
27
|
+
end
|
28
|
+
```
|
29
|
+
|
30
|
+
### Getopt::Long
|
31
|
+
```ruby
|
32
|
+
require 'getopt/long'
|
33
|
+
|
34
|
+
opt = Getopt::Long.getopts(
|
35
|
+
["--foo", "-f", Getopt::BOOLEAN],
|
36
|
+
["--bar", "-b", Getopt::REQUIRED]
|
37
|
+
)
|
38
|
+
|
39
|
+
# Or, to save your fingers some typing:
|
40
|
+
#
|
41
|
+
# require "getopt/long"
|
42
|
+
# include Getopt
|
43
|
+
# opt = Long.getopts(
|
44
|
+
# ["--foo", "-f", BOOLEAN],
|
45
|
+
# ["--bar", "-b", REQUIRED]
|
46
|
+
# )
|
47
|
+
|
48
|
+
if opt["foo"]
|
49
|
+
# Do something if --foo or -f passed
|
50
|
+
end
|
51
|
+
|
52
|
+
if opt["b"]
|
53
|
+
# Do something if --bar or -b passed
|
54
|
+
end
|
55
|
+
```
|
56
|
+
|
57
|
+
## Singleton Methods
|
58
|
+
`Std.getopts(switches)`
|
59
|
+
|
60
|
+
Takes a series of single character switches that can be accepted on the
|
61
|
+
command line. Any characters followed by a ":" require an argument. The
|
62
|
+
rest are considered boolean switches.
|
63
|
+
|
64
|
+
The method returns a hash, with the switches as the key (minus the leading '-').
|
65
|
+
For boolean switches, the value is either true or false. Switches that were
|
66
|
+
not passed on the command line do not appear in the hash.
|
67
|
+
|
68
|
+
In the event that a switch which accepts an argument appears multiple times
|
69
|
+
the value for that key becomes an array of values.
|
70
|
+
|
71
|
+
`Long.getopts(switches)`
|
72
|
+
|
73
|
+
Takes an array of switches beginning with "--" followed by one or more
|
74
|
+
alphanumeric or hyphen characters, or "-" followed by a single character.
|
75
|
+
The type of argument, if any, can be specified as BOOLEAN, OPTIONAL,
|
76
|
+
REQUIRED or INCREMENT.
|
77
|
+
|
78
|
+
The array should be in the form:
|
79
|
+
|
80
|
+
```
|
81
|
+
# long form, short form (alias), option type
|
82
|
+
["--long", "-l", Getopt::OPTION]
|
83
|
+
```
|
84
|
+
|
85
|
+
Note that only the long form is required. If the short form is not
|
86
|
+
specified, it will automatically be set to the first letter of the long
|
87
|
+
switch. If multiple long switches with the same first character are
|
88
|
+
listed without short switches, only the first long switch gets the short
|
89
|
+
switch alias.
|
90
|
+
|
91
|
+
If the argument type is not specified, the default is BOOLEAN.
|
92
|
+
|
93
|
+
For the truly lazy, you can also pass a string of long switches (with
|
94
|
+
no short switches or argument types).
|
95
|
+
|
96
|
+
See the 'examples' directory for more examples.
|
97
|
+
|
98
|
+
## Getopt::Long argument types
|
99
|
+
`REQUIRED`
|
100
|
+
|
101
|
+
If the option is specified on the command line, it must be followed by
|
102
|
+
a non-blank argument. This argument cannot be another switch. If this
|
103
|
+
switch appears multiple times, the values are collected into an array.
|
104
|
+
|
105
|
+
`BOOLEAN`
|
106
|
+
|
107
|
+
If the option is specified on the command line, its value is set to true.
|
108
|
+
It must not be followed by a non-blank argument, excluding other switches.
|
109
|
+
Attempting to pass a boolean switch more than once will raise an error.
|
110
|
+
|
111
|
+
`OPTIONAL`
|
112
|
+
|
113
|
+
If the option is specified on the command line, it may or may not accept
|
114
|
+
an argument, excluding other valid switches. If an argument is present,
|
115
|
+
it's value is set to that argument. If an argument is not present, it's
|
116
|
+
value is set to nil.
|
117
|
+
|
118
|
+
`INCREMENT`
|
119
|
+
|
120
|
+
If the option is specified on the command line, its value is incremented
|
121
|
+
by one for each appearance on the command line, or set to 1 if it appears
|
122
|
+
only once.
|
123
|
+
|
124
|
+
## Future Plans
|
125
|
+
|
126
|
+
* Add support for negatable options so that you can do "--no-foo", for example.
|
127
|
+
|
128
|
+
* Add support for numeric types, so that you don't have to manually convert
|
129
|
+
strings to numbers.
|
130
|
+
|
131
|
+
* Allow shortcut characters for the option types, e.g. "?" for BOOLEAN, "+"
|
132
|
+
for INCREMENT, etc.
|
133
|
+
|
134
|
+
## Known Issues
|
135
|
+
|
136
|
+
### Getopt::Std
|
137
|
+
You cannot squish switches that require arguments with the argument itself.
|
138
|
+
For example, if you do `Getopt::Std.getopts("o:ID")`, it will not parse
|
139
|
+
"-IDohello" properly. Instead, you must do "-IDo hello". Or, you can just
|
140
|
+
separate the argument, e.g. "-I -D -o hello".
|
141
|
+
|
142
|
+
### Getopt::Long
|
143
|
+
If you mix and match compressed switches with separate, optional switches
|
144
|
+
the optional switch will be set to true instead of nil if it separated
|
145
|
+
from the compressed switches.
|
146
|
+
|
147
|
+
## Reporting Issues
|
148
|
+
|
149
|
+
If you find any other issues, please log them on the project
|
150
|
+
page at https://github.com/djberg96/getopt.
|
151
|
+
|
152
|
+
## Other Stuff
|
153
|
+
Neither class attempts to be POSIX compliant in any way, shape or form.
|
154
|
+
|
155
|
+
And I don't care!
|
156
|
+
|
157
|
+
## Notes From the Author
|
158
|
+
My main gripe with the `getoptlong` library currently in the standard library
|
159
|
+
is that it doesn't return a hash, yet gives you partial hash behavior. This
|
160
|
+
was both confusing and annoying, since the first thing I do (along with
|
161
|
+
everyone else) is collect the results into a hash for later processing.
|
162
|
+
|
163
|
+
My main gripe with the `optparse` library (also in the standard library) is
|
164
|
+
that it treats command line processing like event processing. It's too
|
165
|
+
complex, when most of the time all you want to do is slurp the command line
|
166
|
+
options into a hash.
|
167
|
+
|
168
|
+
So, I did something utterly novel with this library. I collected the command
|
169
|
+
line options ... (wait for it) ... into a hash! Then I give that hash to
|
170
|
+
you, aliases and all. I did get some ideas from Perl's Getopt::Long library,
|
171
|
+
but this is in no way a port of that module (which supports POSIX parsing, GNU
|
172
|
+
parsing, more option types, etc). My goal was to provide the functionality
|
173
|
+
that I felt would cover the vast majority of common cases, yet still provide
|
174
|
+
a little extra spice with switch types (REQUIRED, OPTIONAL, etc).
|
175
|
+
|
176
|
+
There are a few extra things I plan to add (see the 'Future Plans' above) but
|
177
|
+
I do not plan on this library ever becoming as feature rich as, say, Perl's
|
178
|
+
Getopt::Long module.
|
179
|
+
|
180
|
+
If you plan to write a full fledged command line application, e.g. you plan
|
181
|
+
on implementing a full help system, gobs of command line options and tons of
|
182
|
+
switches, consider Jim Freeze's `commandline` gem.
|
183
|
+
|
184
|
+
## Warranty
|
185
|
+
This package is provided "as is" and without any express or
|
186
|
+
implied warranties, including, without limitation, the implied
|
187
|
+
warranties of merchantability and fitness for a particular purpose.
|
188
|
+
|
189
|
+
## License
|
190
|
+
Apache-2.0
|
191
|
+
|
192
|
+
## Copyright
|
193
|
+
(C) 2005-2021, Daniel J. Berger
|
194
|
+
All Rights Reserved
|
195
|
+
|
196
|
+
## Author
|
197
|
+
Daniel J. Berger
|