shellopts 2.7.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: 3906747a497d13ee1e7ba9c102184c8b331f8a02333e6a96c2b7c7c9748c6006
4
- data.tar.gz: e4b407b8ab49895b7b2e222d59a35fcb88bb3df75449f94bbb797dbb80e5b362
3
+ metadata.gz: 5c095c6dc48613d922a0e45d567422fa09d3907fb266415b5f37faab5d1d61a1
4
+ data.tar.gz: 76824b5dd2abfd66d919ddca7ba7d47a219d653c7ed32fb60c0a09382d9d7f88
5
5
  SHA512:
6
- metadata.gz: 4f008f01dcc0909988aeed3e1e0def4bf9372bd31c5bdad0d3c65efb56a4b841324984ddce8bf59a49a0d16b6375538322c581489bdb64d74866c4797c39aa45
7
- data.tar.gz: 44d1fe0700802ef288b5a087edcfb58110cc9b51e56b2282dc70bce8b161efa45f3601866709f317b81e42c47f16fd5379949da74eff76193ae31286e3717443
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.7.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
@@ -403,7 +403,11 @@ module ShellOpts
403
403
  # The full path to the program. This is initialized when shellopts.rb is
404
404
  # loaded so it is not affected by later changes of directory
405
405
  @@PROGRAM_PATH = File.absolute_path($PROGRAM_NAME)
406
- def self.path = @@PROGRAM_PATH
406
+ def self.program_path = @@PROGRAM_PATH
407
+
408
+ # The full path to the user's current directory when the program was called
409
+ @@ENVIRONMENT_PATH = File.absolute_path(Dir.getwd)
410
+ def self.environment_path = @@ENVIRONMENT_PATH
407
411
 
408
412
  def self.process(spec, argv, silent: nil, quiet: nil, verbose: nil, debug: nil, **opts)
409
413
  constrain silent, String, true, false, nil
@@ -441,18 +445,18 @@ module ShellOpts
441
445
  def self.verbose?(level = 1) level <= instance.program.__verbose__ end
442
446
  def self.debug?() instance.program.__debug__ end
443
447
 
444
- def self.error(message)
448
+ def self.error(message, exit: 1)
445
449
  raise Error.new(message) if exception
446
- instance.error(message) if instance? # Never returns
450
+ instance.error(message, exit: exit) if instance? # Never returns
447
451
  $stderr.puts "#{File.basename($PROGRAM_NAME)}: #{message}"
448
- exit 1
452
+ handle_exit(exit)
449
453
  end
450
454
 
451
- def self.failure(message)
455
+ def self.failure(message, exit: 1)
452
456
  raise Error.new(message) if exception
453
- instance.failure(message) if instance?
457
+ instance.failure(message, exit: exit) if instance?
454
458
  $stderr.puts "#{File.basename($PROGRAM_NAME)}: #{message}"
455
- exit 1
459
+ handle_exit(exit)
456
460
  end
457
461
 
458
462
  # Emit a message on standard error. The --silent option suppresses these messages
@@ -490,6 +494,14 @@ module ShellOpts
490
494
  end
491
495
  end
492
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
493
505
  module Message
494
506
  @is_included = false
495
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.7.0
4
+ version: 2.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claus Rasmussen