shellopts 2.8.0 → 2.9.0

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: 5c095c6dc48613d922a0e45d567422fa09d3907fb266415b5f37faab5d1d61a1
4
+ data.tar.gz: 76824b5dd2abfd66d919ddca7ba7d47a219d653c7ed32fb60c0a09382d9d7f88
5
5
  SHA512:
6
- metadata.gz: e813c56df7e0680acc25733cc89afe7969cdecf592e555fb484d05fe8994f993d08e949198ef9b328018a1dfb7b7de7f823bb1b4f4e4ac538e1dbde8f79397cd
7
- data.tar.gz: d083566cdc01944d3a30894e94ee025b73d2be9f70310b5df9184e50f701184117cfbfdd757421d7d9ae1e66be15de22d1522f86d477003a9f15a037cda1f5ca
6
+ metadata.gz: 4a5b67e387057c0da8146ea4e65b08015a65d4834710c43a6fb42eacccad4981ad74e4760941e0d41e40b1b4f99d80b9d4f11b35d5b7c8f8d5fd048bc20d5a17
7
+ data.tar.gz: 72f40f34cdea62cd58ed6990f45f037b061853539d6face68e4194827f04a0895c288b12260d0f0640fa8fb3e15727894d173046a774910e7e839774af4b4fcc
@@ -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.0"
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,18 @@ 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
450
+ instance.error(message, exit: exit) if instance? # Never returns
451
451
  $stderr.puts "#{File.basename($PROGRAM_NAME)}: #{message}"
452
- exit 1
452
+ handle_exit(exit)
453
453
  end
454
454
 
455
- def self.failure(message)
455
+ def self.failure(message, exit: 1)
456
456
  raise Error.new(message) if exception
457
- instance.failure(message) if instance?
457
+ instance.failure(message, exit: exit) if instance?
458
458
  $stderr.puts "#{File.basename($PROGRAM_NAME)}: #{message}"
459
- exit 1
459
+ handle_exit(exit)
460
460
  end
461
461
 
462
462
  # Emit a message on standard error. The --silent option suppresses these messages
@@ -494,6 +494,14 @@ module ShellOpts
494
494
  end
495
495
  end
496
496
 
497
+ private
498
+ # Exit program with the given status if an integer and status 1 if not. Do
499
+ # not exit if status is falsy
500
+ def self.handle_exit(value)
501
+ exit(value.is_a?(Integer) ? value : 1) if value
502
+ end
503
+
504
+ public
497
505
  module Message
498
506
  @is_included = false
499
507
  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.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claus Rasmussen