getopt 1.5.0 → 1.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/{CHANGES → CHANGES.rdoc} +5 -0
- data/LICENSE +177 -0
- data/{MANIFEST → MANIFEST.rdoc} +4 -3
- data/README.rdoc +199 -0
- data/getopt.gemspec +2 -2
- data/lib/getopt/version.rb +1 -1
- data/test/test_getopt_long.rb +1 -1
- data/test/test_getopt_std.rb +1 -1
- metadata +9 -8
- metadata.gz.sig +0 -0
- data/README +0 -191
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca47de7a2b707c120f664cddb09b52ea83437da650968259b2bca08bded4b9d6
|
4
|
+
data.tar.gz: 0afa07ce4a5c65753fcb9cc9e1b878b1b83cb7cdce590fbe01dda585c19e923f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c1e31f007d67944148636e8db0b0700fd9c62399ca1b7961af769a4ccc7fa9deed32c49ba9e73daf3df099e647ede6480fe5951ff9a8ea63561c02a40e79fc78
|
7
|
+
data.tar.gz: f5ed551262c5e84c5b30a7c445174933081866394db9b448ac2ded94a2001597383aa1f0ebbfc699f5b9c16964b6ba2604d0801b8bcb5b566d50e0f755579474
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/{CHANGES → CHANGES.rdoc}
RENAMED
@@ -1,3 +1,8 @@
|
|
1
|
+
== 1.5.1 - 23-Mar-2020
|
2
|
+
* Properly add a LICENSE file since the Apache-2.0 license requires it.
|
3
|
+
* Added explicit .rdoc extensions to the README, CHANGES and MANIFEST files,
|
4
|
+
mostly so they look nicer on github.
|
5
|
+
|
1
6
|
== 1.5.0 - 25-Jan-2019
|
2
7
|
* Changed license to Apache-2.0.
|
3
8
|
|
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.rdoc}
RENAMED
data/README.rdoc
ADDED
@@ -0,0 +1,199 @@
|
|
1
|
+
= Description
|
2
|
+
|
3
|
+
Implements a simple Getopt::Std class for command line parsing, as well
|
4
|
+
as a Getopt::Long class for more advanced command line parsing.
|
5
|
+
|
6
|
+
= Installation
|
7
|
+
|
8
|
+
gem install getopt
|
9
|
+
|
10
|
+
= Synopsis
|
11
|
+
== Getopt::Std
|
12
|
+
|
13
|
+
require 'getopt/std'
|
14
|
+
|
15
|
+
# Look for -o with argument, and -I and -D boolean arguments
|
16
|
+
opt = Getopt::Std.getopts("o:ID")
|
17
|
+
|
18
|
+
if opt["I"]
|
19
|
+
# Do something if -I passed
|
20
|
+
|
21
|
+
if opt["D"]
|
22
|
+
# Do something if -D passed
|
23
|
+
|
24
|
+
if opt["o"]
|
25
|
+
case opt["o"]
|
26
|
+
# blah, blah, blah
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
== Getopt::Long
|
31
|
+
|
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
|
+
|
51
|
+
if opt["b"]
|
52
|
+
# Do something if --bar or -b passed
|
53
|
+
|
54
|
+
= Class Methods
|
55
|
+
|
56
|
+
Std.getopts(switches)
|
57
|
+
|
58
|
+
Takes a series of single character switches that can be accepted on the
|
59
|
+
command line. Those characters followed by a ':' require an argument. The
|
60
|
+
rest are considered boolean switches. Returns a hash, with the switches
|
61
|
+
as the key (sans the leading '-'). For boolean switches, the value is
|
62
|
+
either true or false. Switches that were not passed on the command line
|
63
|
+
do not appear in the hash.
|
64
|
+
|
65
|
+
In the event that a switch that accepts an argument appears multiple times
|
66
|
+
the value for that key becomes an array of values.
|
67
|
+
|
68
|
+
Long.getopts(switches)
|
69
|
+
|
70
|
+
Takes an array of switches beginning with "--" followed by one or more
|
71
|
+
alphanumeric or hyphen characters, or "-" followed by a single character.
|
72
|
+
The type of argument, if any, can be specified as BOOLEAN, OPTIONAL,
|
73
|
+
REQUIRED or INCREMENT.
|
74
|
+
|
75
|
+
The array should be in the form:
|
76
|
+
|
77
|
+
# long form, short form (alias), option type
|
78
|
+
["--long", "-l", Getopt::OPTION]
|
79
|
+
|
80
|
+
Note that only the long form is required. If the short form is not
|
81
|
+
specified, it will automatically be set to the first letter of the long
|
82
|
+
switch. If multiple long switches with the same first character are
|
83
|
+
listed without short switches, only the first long switch gets the short
|
84
|
+
switch alias.
|
85
|
+
|
86
|
+
If the argument type is not specified, the default is BOOLEAN.
|
87
|
+
|
88
|
+
For the truly lazy, you can also pass a string of long switches (with
|
89
|
+
no short switches or argument types).
|
90
|
+
|
91
|
+
See the 'examples' directory for more examples.
|
92
|
+
|
93
|
+
= Getopt::Long argument types
|
94
|
+
|
95
|
+
REQUIRED
|
96
|
+
|
97
|
+
If the option is specified on the command line, it must be followed by
|
98
|
+
a non-blank argument. This argument cannot be another switch. If this
|
99
|
+
switch appears multiple times, the values are collected into an array.
|
100
|
+
|
101
|
+
BOOLEAN
|
102
|
+
|
103
|
+
If the option is specified on the command line, its value is set to true.
|
104
|
+
It must not be followed by a non-blank argument, excluding other switches.
|
105
|
+
Attempting to pass a boolean switch more than once will raise an error.
|
106
|
+
|
107
|
+
OPTIONAL
|
108
|
+
|
109
|
+
If the option is specified on the command line, it may or may not accept
|
110
|
+
an argument, excluding other valid switches. If an argument is present,
|
111
|
+
it's value is set to that argument. If an argument is not present, it's
|
112
|
+
value is set to nil.
|
113
|
+
|
114
|
+
INCREMENT
|
115
|
+
|
116
|
+
If the option is specified on the command line, its value is incremented
|
117
|
+
by one for each appearance on the command line, or set to 1 if it appears
|
118
|
+
only once.
|
119
|
+
|
120
|
+
= Future Plans
|
121
|
+
|
122
|
+
* Add support for negatable options so that you can do "--no-foo", for example.
|
123
|
+
|
124
|
+
* Add support for numeric types, so that you don't have to manually convert
|
125
|
+
strings to numbers.
|
126
|
+
|
127
|
+
* Allow shortcut characters for the option types, e.g. "?" for BOOLEAN, "+"
|
128
|
+
for INCREMENT, etc.
|
129
|
+
|
130
|
+
= Known Issues
|
131
|
+
|
132
|
+
== Getopt::Std
|
133
|
+
|
134
|
+
You cannot squish switches that require arguments with the argument itself.
|
135
|
+
For example, if you do Getopt::Std.getopts("o:ID"), it will not parse
|
136
|
+
"-IDohello" properly. Instead, you must do "-IDo hello". Or, you can just
|
137
|
+
separate the argument, e.g. "-I -D -o hello".
|
138
|
+
|
139
|
+
== Getopt::Long
|
140
|
+
|
141
|
+
If you mix and match compressed switches with separate, optional switches
|
142
|
+
the optional switch will be set to true instead of nil if it separated
|
143
|
+
from the compressed switches.
|
144
|
+
|
145
|
+
== Reporting Issues
|
146
|
+
|
147
|
+
If you find any other issues, please log them on the project
|
148
|
+
page at https://github.com/djberg96/getopt.
|
149
|
+
|
150
|
+
= Other Stuff
|
151
|
+
|
152
|
+
Neither class attempts to be POSIX compliant in any way, shape or form. And I don't care!
|
153
|
+
|
154
|
+
= Notes From the Author
|
155
|
+
|
156
|
+
My main gripe with the getoptlong library currently in the standard library
|
157
|
+
is that it doesn't return a hash, yet gives you partial hash behavior. This
|
158
|
+
was both confusing and annoying, since the first thing I do (along with
|
159
|
+
everyone else) is collect the results into a hash for later processing.
|
160
|
+
|
161
|
+
My main gripe with the optparse library (also in the standard library) is
|
162
|
+
that it treats command line processing like event processing. It's too
|
163
|
+
complex, when 90% of the time all you want to do is slurp the command line
|
164
|
+
options into a hash.
|
165
|
+
|
166
|
+
So, I did something utterly novel with this library. I collected the command
|
167
|
+
line options ... (wait for it) ... into a hash! Then I give that hash to
|
168
|
+
you, aliases and all. I did get some ideas from Perl's Getopt::Long library,
|
169
|
+
but this is in no way a port of that module (which supports POSIX parsing, GNU
|
170
|
+
parsing, more option types, etc). My goal was to provide the functionality
|
171
|
+
that I felt would cover the vast majority of common cases, yet still provide
|
172
|
+
a little extra spice with switch types (REQUIRED, OPTIONAL, etc).
|
173
|
+
|
174
|
+
There are a few extra things I plan to add (see the 'Future Plans' above) but
|
175
|
+
I do not plan on this library ever becoming as feature rich as, say, Perl's
|
176
|
+
Getopt::Long module.
|
177
|
+
|
178
|
+
If you plan to write a full fledged command line application, e.g. you plan
|
179
|
+
on implementing a full help system, gobs of command line options and tons of
|
180
|
+
switches, consider Jim Freeze's 'commandline' gem.
|
181
|
+
|
182
|
+
= Warranty
|
183
|
+
|
184
|
+
This package is provided "as is" and without any express or
|
185
|
+
implied warranties, including, without limitation, the implied
|
186
|
+
warranties of merchantability and fitness for a particular purpose.
|
187
|
+
|
188
|
+
= License
|
189
|
+
|
190
|
+
Apache-2.0
|
191
|
+
|
192
|
+
= Copyright
|
193
|
+
|
194
|
+
(C) 2005-2020, Daniel J. Berger
|
195
|
+
All Rights Reserved
|
196
|
+
|
197
|
+
= Author
|
198
|
+
|
199
|
+
Daniel J. Berger
|
data/getopt.gemspec
CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = 'getopt'
|
5
|
-
spec.version = '1.5.
|
5
|
+
spec.version = '1.5.1'
|
6
6
|
spec.author = 'Daniel J. Berger'
|
7
7
|
spec.license = 'Apache-2.0'
|
8
8
|
spec.email = 'djberg96@gmail.com'
|
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
|
|
12
12
|
spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
|
13
13
|
spec.cert_chain = Dir['certs/*']
|
14
14
|
|
15
|
-
spec.extra_rdoc_files = ['README', 'CHANGES', 'MANIFEST']
|
15
|
+
spec.extra_rdoc_files = ['README.rdoc', 'CHANGES.rdoc', 'MANIFEST.rdoc']
|
16
16
|
|
17
17
|
spec.add_development_dependency('test-unit', '>= 2.5.0')
|
18
18
|
spec.required_ruby_version = '>= 2.2.0'
|
data/lib/getopt/version.rb
CHANGED
data/test/test_getopt_long.rb
CHANGED
data/test/test_getopt_std.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: getopt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel J. Berger
|
@@ -60,16 +60,14 @@ email: djberg96@gmail.com
|
|
60
60
|
executables: []
|
61
61
|
extensions: []
|
62
62
|
extra_rdoc_files:
|
63
|
-
- README
|
64
|
-
- CHANGES
|
65
|
-
- MANIFEST
|
63
|
+
- README.rdoc
|
64
|
+
- CHANGES.rdoc
|
65
|
+
- MANIFEST.rdoc
|
66
66
|
files:
|
67
|
+
- LICENSE
|
67
68
|
- test
|
68
69
|
- test/test_getopt_long.rb
|
69
70
|
- test/test_getopt_std.rb
|
70
|
-
- CHANGES
|
71
|
-
- MANIFEST
|
72
|
-
- README
|
73
71
|
- Rakefile
|
74
72
|
- certs
|
75
73
|
- certs/djberg96_pub.pem
|
@@ -84,7 +82,10 @@ files:
|
|
84
82
|
- lib/getopt/version.rb
|
85
83
|
- lib/getopt-long.rb
|
86
84
|
- lib/getopt-std.rb
|
85
|
+
- CHANGES.rdoc
|
86
|
+
- MANIFEST.rdoc
|
87
87
|
- getopt.gemspec
|
88
|
+
- README.rdoc
|
88
89
|
homepage: https://github.com/djberg96/getopt
|
89
90
|
licenses:
|
90
91
|
- Apache-2.0
|
@@ -110,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
111
|
- !ruby/object:Gem::Version
|
111
112
|
version: '0'
|
112
113
|
requirements: []
|
113
|
-
rubygems_version: 3.0.
|
114
|
+
rubygems_version: 3.0.6
|
114
115
|
signing_key:
|
115
116
|
specification_version: 4
|
116
117
|
summary: Getopt::Std and Getopt::Long option parsers for Ruby
|
metadata.gz.sig
CHANGED
Binary file
|
data/README
DELETED
@@ -1,191 +0,0 @@
|
|
1
|
-
= Description
|
2
|
-
Implements a simple Getopt::Std class for command line parsing, as well
|
3
|
-
as a Getopt::Long class for more advanced command line parsing.
|
4
|
-
|
5
|
-
= Installation
|
6
|
-
|
7
|
-
gem install getopt
|
8
|
-
|
9
|
-
= Synopsis
|
10
|
-
== Getopt::Std
|
11
|
-
|
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
|
-
== Getopt::Long
|
30
|
-
|
31
|
-
require 'getopt/long'
|
32
|
-
|
33
|
-
opt = Getopt::Long.getopts(
|
34
|
-
["--foo", "-f", Getopt::BOOLEAN],
|
35
|
-
["--bar", "-b", Getopt::REQUIRED]
|
36
|
-
)
|
37
|
-
|
38
|
-
# Or, to save your fingers some typing:
|
39
|
-
#
|
40
|
-
# require "getopt/long"
|
41
|
-
# include Getopt
|
42
|
-
# opt = Long.getopts(
|
43
|
-
# ["--foo", "-f", BOOLEAN],
|
44
|
-
# ["--bar", "-b", REQUIRED]
|
45
|
-
# )
|
46
|
-
|
47
|
-
if opt["foo"]
|
48
|
-
# Do something if --foo or -f passed
|
49
|
-
|
50
|
-
if opt["b"]
|
51
|
-
# Do something if --bar or -b passed
|
52
|
-
|
53
|
-
= Class Methods
|
54
|
-
|
55
|
-
Std.getopts(switches)
|
56
|
-
|
57
|
-
Takes a series of single character switches that can be accepted on the
|
58
|
-
command line. Those characters followed by a ':' require an argument. The
|
59
|
-
rest are considered boolean switches. Returns a hash, with the switches
|
60
|
-
as the key (sans the leading '-'). For boolean switches, the value is
|
61
|
-
either true or false. Switches that were not passed on the command line
|
62
|
-
do not appear in the hash.
|
63
|
-
|
64
|
-
In the event that a switch that accepts an argument appears multiple times
|
65
|
-
the value for that key becomes an array of values.
|
66
|
-
|
67
|
-
Long.getopts(switches)
|
68
|
-
|
69
|
-
Takes an array of switches beginning with "--" followed by one or more
|
70
|
-
alphanumeric or hyphen characters, or "-" followed by a single character.
|
71
|
-
The type of argument, if any, can be specified as BOOLEAN, OPTIONAL,
|
72
|
-
REQUIRED or INCREMENT.
|
73
|
-
|
74
|
-
The array should be in the form:
|
75
|
-
|
76
|
-
# long form, short form (alias), option type
|
77
|
-
["--long", "-l", Getopt::OPTION]
|
78
|
-
|
79
|
-
Note that only the long form is required. If the short form is not
|
80
|
-
specified, it will automatically be set to the first letter of the long
|
81
|
-
switch. If multiple long switches with the same first character are
|
82
|
-
listed without short switches, only the first long switch gets the short
|
83
|
-
switch alias.
|
84
|
-
|
85
|
-
If the argument type is not specified, the default is BOOLEAN.
|
86
|
-
|
87
|
-
For the truly lazy, you can also pass a string of long switches (with
|
88
|
-
no short switches or argument types).
|
89
|
-
|
90
|
-
See the 'examples' directory for more examples.
|
91
|
-
|
92
|
-
= Getopt::Long argument types
|
93
|
-
|
94
|
-
REQUIRED
|
95
|
-
If the option is specified on the command line, it must be followed by
|
96
|
-
a non-blank argument. This argument cannot be another switch. If this
|
97
|
-
switch appears multiple times, the values are collected into an array.
|
98
|
-
|
99
|
-
BOOLEAN
|
100
|
-
If the option is specified on the command line, its value is set to true.
|
101
|
-
It must not be followed by a non-blank argument, excluding other switches.
|
102
|
-
Attempting to pass a boolean switch more than once will raise an error.
|
103
|
-
|
104
|
-
OPTIONAL
|
105
|
-
If the option is specified on the command line, it may or may not accept
|
106
|
-
an argument, excluding other valid switches. If an argument is present,
|
107
|
-
it's value is set to that argument. If an argument is not present, it's
|
108
|
-
value is set to nil.
|
109
|
-
|
110
|
-
INCREMENT
|
111
|
-
If the option is specified on the command line, its value is incremented
|
112
|
-
by one for each appearance on the command line, or set to 1 if it appears
|
113
|
-
only once.
|
114
|
-
|
115
|
-
= Future Plans
|
116
|
-
Add support for negatable options so that you can do "--no-foo", for
|
117
|
-
example.
|
118
|
-
|
119
|
-
Add support for numeric types, so that you don't have to manually convert
|
120
|
-
strings to numbers.
|
121
|
-
|
122
|
-
Allow shortcut characters for the option types, e.g. "?" for BOOLEAN, "+"
|
123
|
-
for INCREMENT, etc.
|
124
|
-
|
125
|
-
= Known Issues
|
126
|
-
|
127
|
-
== Getopt::Std
|
128
|
-
|
129
|
-
You cannot squish switches that require arguments with the argument itself.
|
130
|
-
For example, if you do Getopt::Std.getopts("o:ID"), it will not parse
|
131
|
-
"-IDohello" properly. Instead, you must do "-IDo hello". Or, you can just
|
132
|
-
separate the argument, e.g. "-I -D -o hello".
|
133
|
-
|
134
|
-
== Getopt::Long
|
135
|
-
|
136
|
-
If you mix and match compressed switches with separate, optional switches
|
137
|
-
the optional switch will be set to true instead of nil if it separated
|
138
|
-
from the compressed switches.
|
139
|
-
|
140
|
-
== Reporting Issues
|
141
|
-
|
142
|
-
If you find any other issues, please log them on the project
|
143
|
-
page at https://github.com/djberg96/getopt.
|
144
|
-
|
145
|
-
= Other Stuff
|
146
|
-
|
147
|
-
Neither class attempts to be POSIX compliant in any way, shape or form.
|
148
|
-
And I don't care!
|
149
|
-
|
150
|
-
= Notes From the Author
|
151
|
-
|
152
|
-
My main gripe with the getoptlong library currently in the standard library
|
153
|
-
is that it doesn't return a hash, yet gives you partial hash behavior. This
|
154
|
-
was both confusing and annoying, since the first thing I do (along with
|
155
|
-
everyone else) is collect the results into a hash for later processing.
|
156
|
-
|
157
|
-
My main gripe with the optparse library (also in the standard library) is
|
158
|
-
that it treats command line processing like event processing. It's too
|
159
|
-
complex, when 90% of the time all you want to do is slurp the command line
|
160
|
-
options into a hash.
|
161
|
-
|
162
|
-
So, I did something utterly novel with this library. I collected the command
|
163
|
-
line options ... (wait for it) ... into a hash! Then I give that hash to
|
164
|
-
you, aliases and all. I did get some ideas from Perl's Getopt::Long library,
|
165
|
-
but this is in no way a port of that module (which supports POSIX parsing, GNU
|
166
|
-
parsing, more option types, etc). My goal was to provide the functionality
|
167
|
-
that I felt would cover the vast majority of common cases, yet still provide
|
168
|
-
a little extra spice with switch types (REQUIRED, OPTIONAL, etc).
|
169
|
-
|
170
|
-
There are a few extra things I plan to add (see the 'Future Plans' above) but
|
171
|
-
I do not plan on this library ever becoming as feature rich as, say, Perl's
|
172
|
-
Getopt::Long module.
|
173
|
-
|
174
|
-
If you plan to write a full fledged command line application, e.g. you plan
|
175
|
-
on implementing a full help system, gobs of command line options and tons of
|
176
|
-
switches, consider Jim Freeze's 'commandline' gem.
|
177
|
-
|
178
|
-
= Warranty
|
179
|
-
This package is provided "as is" and without any express or
|
180
|
-
implied warranties, including, without limitation, the implied
|
181
|
-
warranties of merchantability and fitness for a particular purpose.
|
182
|
-
|
183
|
-
= License
|
184
|
-
Apache-2.0
|
185
|
-
|
186
|
-
= Copyright
|
187
|
-
(C) 2005-2019, Daniel J. Berger
|
188
|
-
All Rights Reserved
|
189
|
-
|
190
|
-
= Author
|
191
|
-
Daniel J. Berger
|