shellopts 0.9.6 → 0.9.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 943b9d0c44ba0291937be24cbc79d0155dfc22ac788c69a76639850d78af3303
4
- data.tar.gz: f38e038f613c577b06e9d2facc6096b39eb18f28266ba8c58a8280adcf75fe47
3
+ metadata.gz: 4a081efe12e3a4e2f4b38eab4d2f6776c5dc3c748fb06178a4b42dbbba4e9612
4
+ data.tar.gz: 27a8d76c4de24c440bd330aa84d2e17014456c927af3c4a12807573df798c01a
5
5
  SHA512:
6
- metadata.gz: 42cc6102c0c66dcffda0b03f9c584c32abc0e62a65dbe79e1389753b74af11f189e27a456e79fb2cb082595622ddbce0840dd22419204e276a48134ac8afd610
7
- data.tar.gz: 6a3b2e35718a5ee1f52e5d56a50ea067da90fef35a4ac3322738e24d5ba80f4aba4ac4a692caace4bb094ccfb84432e9211fef2b15dfef2e194a95569ca80686
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`. It can be overridden by assigning to
279
- `ShellOpts.usage`. You'll often assign to the usage string when it needs to be
280
- split over several lines:
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
@@ -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 ||= @shellopts&.usage end
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
- $stderr.puts "Usage: #{program} #{usage}" if usage
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
@@ -1,3 +1,3 @@
1
1
  module Shellopts
2
- VERSION = "0.9.6"
2
+ VERSION = "0.9.7"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shellopts
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.6
4
+ version: 0.9.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claus Rasmussen