shellopts 2.8.0 → 2.9.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ef632532d3cd4b1aa83c037e246b18000d8b3852163c2a17e59c4ca9af11a1b2
4
- data.tar.gz: 17ca0bc5a4a8f5b29ceb4d130339608fbfe0e94925d05dd9185f0b4304cbdaf2
3
+ metadata.gz: 3dcef062b0b6bf1df9e6596e7410dc51a85c2b990fecfc8e7fede565e162fc2e
4
+ data.tar.gz: cf8bdddb542e324a0efcdef4fae00ce76338994263e4f603bd22149f5acd7777
5
5
  SHA512:
6
- metadata.gz: e813c56df7e0680acc25733cc89afe7969cdecf592e555fb484d05fe8994f993d08e949198ef9b328018a1dfb7b7de7f823bb1b4f4e4ac538e1dbde8f79397cd
7
- data.tar.gz: d083566cdc01944d3a30894e94ee025b73d2be9f70310b5df9184e50f701184117cfbfdd757421d7d9ae1e66be15de22d1522f86d477003a9f15a037cda1f5ca
6
+ metadata.gz: 93b9d18edd54a015170350865e460625cef1a6fa42918b386634912260c900041a76f486135813ef89341bec64355e2d29ef011f36f234143d42874d8fe0908a
7
+ data.tar.gz: 8434df86e5ef6238975a018530509de6d7fcef69bbaa63d4e6b2f33f2d738e74c5232d691172ff6f475cbe78995e62c7966b51517202ba6a440517b76a4843df
@@ -104,7 +104,6 @@ module ShellOpts
104
104
  keys.filter_map { |key| __option_values__.key?(key) && [key, self.__send__(key)] }.to_h
105
105
  end
106
106
 
107
-
108
107
  # Subcommand identifier or nil if not present. #subcommand is often used in
109
108
  # case statement to branch out to code that handles the given subcommand:
110
109
  #
@@ -123,9 +122,9 @@ module ShellOpts
123
122
  # (#<identifier>!) are often used instead of #subcommand! to get the
124
123
  # subcommand
125
124
  #
126
- # Note: Can be overridden by a subcommand declaration (but not an
127
- # option), in that case use #__subcommand__! or
128
- # ShellOpts.subcommand!(object) instead
125
+ # Note: Can be overridden by a subcommand declaration (but not an option),
126
+ # in that case use #__subcommand__! or ShellOpts.subcommand!(object)
127
+ # instead
129
128
  #
130
129
  def subcommand!() __subcommand__! end
131
130
 
@@ -1,3 +1,3 @@
1
1
  module ShellOpts
2
- VERSION = "2.8.0"
2
+ VERSION = "2.9.1"
3
3
  end
data/lib/shellopts.rb CHANGED
@@ -268,14 +268,14 @@ module ShellOpts
268
268
  #
269
269
  # #error is supposed to be used when the user made an error and the usage
270
270
  # is written to help correcting the error
271
- def error(message)
271
+ def error(message, exit: 1)
272
272
  raise ShellOpts::Error.new(message) if ::ShellOpts.exception
273
273
  $stderr.puts "#{name}: #{message}"
274
274
  saved = $stdout
275
275
  begin
276
276
  $stdout = $stderr
277
277
  Formatter.usage(grammar)
278
- exit 1
278
+ ::ShellOpts.handle_exit(exit)
279
279
  ensure
280
280
  $stdout = saved
281
281
  end
@@ -286,10 +286,10 @@ module ShellOpts
286
286
  # #failure doesn't print the program usage because is supposed to be used
287
287
  # when the user specified the correct arguments but something else went
288
288
  # wrong during processing
289
- def failure(message)
289
+ def failure(message, exit: 1)
290
290
  raise ShellOpts::Failure.new(message) if ::ShellOpts.exception
291
291
  $stderr.puts "#{name}: #{message}"
292
- exit 1
292
+ ::ShellOpts.handle_exit(exit)
293
293
  end
294
294
 
295
295
  # Print usage
@@ -445,18 +445,24 @@ module ShellOpts
445
445
  def self.verbose?(level = 1) level <= instance.program.__verbose__ end
446
446
  def self.debug?() instance.program.__debug__ end
447
447
 
448
- def self.error(message)
448
+ def self.error(message, exit: 1)
449
449
  raise Error.new(message) if exception
450
- instance.error(message) if instance? # Never returns
451
- $stderr.puts "#{File.basename($PROGRAM_NAME)}: #{message}"
452
- exit 1
450
+ if instance?
451
+ instance.error(message, exit: exit)
452
+ else
453
+ $stderr.puts "#{File.basename($PROGRAM_NAME)}: #{message}"
454
+ handle_exit(exit)
455
+ end
453
456
  end
454
457
 
455
- def self.failure(message)
458
+ def self.failure(message, exit: 1)
456
459
  raise Error.new(message) if exception
457
- instance.failure(message) if instance?
458
- $stderr.puts "#{File.basename($PROGRAM_NAME)}: #{message}"
459
- exit 1
460
+ if instance?
461
+ instance.failure(message, exit: exit)
462
+ else
463
+ $stderr.puts "#{File.basename($PROGRAM_NAME)}: #{message}"
464
+ handle_exit(exit)
465
+ end
460
466
  end
461
467
 
462
468
  # Emit a message on standard error. The --silent option suppresses these messages
@@ -494,6 +500,14 @@ module ShellOpts
494
500
  end
495
501
  end
496
502
 
503
+ private
504
+ # Exit program with the given status if an integer and status 1 if not. Do
505
+ # not exit if status is falsy
506
+ def self.handle_exit(value)
507
+ exit(value.is_a?(Integer) ? value : 1) if value
508
+ end
509
+
510
+ public
497
511
  module Message
498
512
  @is_included = false
499
513
  def self.is_included?() @is_included 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: 2.8.0
4
+ version: 2.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claus Rasmussen