shellopts 0.9.6 → 0.9.7
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 +9 -5
- data/lib/shellopts.rb +11 -7
- data/lib/shellopts/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a081efe12e3a4e2f4b38eab4d2f6776c5dc3c748fb06178a4b42dbbba4e9612
|
4
|
+
data.tar.gz: 27a8d76c4de24c440bd330aa84d2e17014456c927af3c4a12807573df798c01a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f21b1f020dd04219272d5772cf0483b88c108af9991450e2532fcdab5322635a80a1cbac512c284358d10f271c03b4adef65ffb379d3df8a1d6635b9ca9f518
|
7
|
+
data.tar.gz: e88c6c0abcb49a7ba6568aa66c62267a63b92cfb9969387522a52b045fc34d4121cddb4b8c11ffe68d8ed3f13f925391e393e5b4ac292732696de019f7ed4217
|
data/README.md
CHANGED
@@ -275,20 +275,24 @@ class methods on `ShellOpts`. They can also be included in the global scope by
|
|
275
275
|
#### Usage string
|
276
276
|
|
277
277
|
The error handling methods prints a prettified version of the usage string
|
278
|
-
given to `ShellOpts.parse`.
|
279
|
-
`ShellOpts.usage`.
|
280
|
-
|
278
|
+
given to `ShellOpts.parse`. The usage string can be overridden by assigning to
|
279
|
+
`ShellOpts.usage`. A typical use case is when you want to split the usage
|
280
|
+
description over multiple lines:
|
281
281
|
|
282
282
|
```ruby
|
283
283
|
|
284
284
|
USAGE="long-and-complex-usage-string"
|
285
|
-
ShellOpts.usage =
|
285
|
+
ShellOpts.usage = <<~EOD
|
286
286
|
usage explanation
|
287
287
|
split over
|
288
288
|
multiple lines
|
289
|
-
|
289
|
+
EOD
|
290
290
|
```
|
291
291
|
|
292
|
+
Note that this only affects the module-level `ShellOpts.error` method and not
|
293
|
+
object-level `ShellOpts::ShellOpts#error` method. This is considered a bug and
|
294
|
+
will fixed at some point
|
295
|
+
|
292
296
|
## Example
|
293
297
|
|
294
298
|
The rm(1) command could be implemented like this
|
data/lib/shellopts.rb
CHANGED
@@ -19,7 +19,7 @@ module ShellOpts
|
|
19
19
|
|
20
20
|
# Prettified usage string used by #error and #fail. Default is +usage+ of
|
21
21
|
# the current +ShellOpts::ShellOpts+ object
|
22
|
-
def self.usage() @usage
|
22
|
+
def self.usage() @usage || @shellopts&.usage end
|
23
23
|
|
24
24
|
# Set the usage string
|
25
25
|
def self.usage=(usage) @usage = usage end
|
@@ -122,7 +122,7 @@ module ShellOpts
|
|
122
122
|
def self.error(*msgs)
|
123
123
|
program = @shellopts&.program_name || PROGRAM
|
124
124
|
usage_string = usage || (defined?(USAGE) && USAGE ? Grammar.compile(PROGRAM, USAGE).usage : nil)
|
125
|
-
emit_and_exit(program, usage_string, *msgs)
|
125
|
+
emit_and_exit(program, @usage.nil?, usage_string, *msgs)
|
126
126
|
end
|
127
127
|
|
128
128
|
# Print error message and exit with status 1. It use the current ShellOpts
|
@@ -130,7 +130,7 @@ module ShellOpts
|
|
130
130
|
# user-errors but system errors (like disk full)
|
131
131
|
def self.fail(*msgs)
|
132
132
|
program = @shellopts&.program_name || PROGRAM
|
133
|
-
emit_and_exit(program, nil, *msgs)
|
133
|
+
emit_and_exit(program, false, nil, *msgs)
|
134
134
|
end
|
135
135
|
|
136
136
|
# The compilation object
|
@@ -191,13 +191,13 @@ module ShellOpts
|
|
191
191
|
# should be called in response to user-errors (eg. specifying an illegal
|
192
192
|
# option)
|
193
193
|
def error(*msgs)
|
194
|
-
::ShellOpts.emit_and_exit(program_name, usage, msgs)
|
194
|
+
::ShellOpts.emit_and_exit(program_name, true, usage, msgs)
|
195
195
|
end
|
196
196
|
|
197
197
|
# Print error message and exit with status 1. This method should not be
|
198
198
|
# called in response to user-errors but system errors (like disk full)
|
199
199
|
def fail(*msgs)
|
200
|
-
::ShellOpts.emit_and_exit(program_name, nil, msgs)
|
200
|
+
::ShellOpts.emit_and_exit(program_name, false, nil, msgs)
|
201
201
|
end
|
202
202
|
end
|
203
203
|
|
@@ -218,9 +218,13 @@ module ShellOpts
|
|
218
218
|
private
|
219
219
|
@shellopts = nil
|
220
220
|
|
221
|
-
def self.emit_and_exit(program, usage, *msgs)
|
221
|
+
def self.emit_and_exit(program, use_usage, usage, *msgs)
|
222
222
|
$stderr.puts "#{program}: #{msgs.join}"
|
223
|
-
|
223
|
+
if use_usage
|
224
|
+
$stderr.puts "Usage: #{program} #{usage}" if usage
|
225
|
+
else
|
226
|
+
$stderr.puts usage if usage
|
227
|
+
end
|
224
228
|
exit 1
|
225
229
|
end
|
226
230
|
end
|
data/lib/shellopts/version.rb
CHANGED