shellopts 2.6.3 → 2.6.4

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: dd0eab6e9ab4b9b3f88b7e0431411d683fc4b1f0edc01a4841637083cffad482
4
- data.tar.gz: e46065ac5acf79b47d96e44c1b5b9c70f9cf1f086794364b15389f1582a15501
3
+ metadata.gz: abc8469755c86dcf44a9c55bc94e1ff2e7666a4e7b03f64ead617ffe01b3b8ac
4
+ data.tar.gz: bb77b26f604d37f3a055db86b7698b1fdc95e28ee3650e11d1ea384d27cd7100
5
5
  SHA512:
6
- metadata.gz: 16a38fdf11c48d499898008754ef648eda8e9ff018ba4aa914361dd08aa82028fcdcb653629a3fc13bc40145bab7a0f698703f65f3564be2a14602783b7099f5
7
- data.tar.gz: '09ae9862034fbcf05d6559d8d6356ed87123d38a19b193f8881d434e762b36e3ae04390fafe506fc019fa783ae1d7d02c61c56aaf27de7389caf4a1527969538'
6
+ metadata.gz: fd22327ccba22437e2133aa5bd6f887a7297774712e5452c573f5cc3c8a6748dfa2981fb5b9829f3c354d444029959d0e105430cd4eee71629974834ee731a51
7
+ data.tar.gz: 9973cf20508104fa5f2b53d32fed51dc7944b24c11492b78612a8fc1f0c19c784b622e1809f61265019212ab27cebad4a70503a0429fe55b0fb5bde1272c8585
@@ -1,3 +1,3 @@
1
1
  module ShellOpts
2
- VERSION = "2.6.3"
2
+ VERSION = "2.6.4"
3
3
  end
data/lib/shellopts.rb CHANGED
@@ -29,6 +29,7 @@ require_relative 'shellopts/formatter.rb'
29
29
  require_relative 'shellopts/dump.rb'
30
30
 
31
31
  # TODO: Describe exception handling
32
+ # TODO: Option: float (from left to rigth), fill (fill-in everywhere)
32
33
  #
33
34
  # Notes
34
35
  # * Two kinds of exceptions: Expected & unexpected. Expected exceptions are
@@ -132,8 +133,8 @@ module ShellOpts
132
133
  # Floating options
133
134
  attr_accessor :float
134
135
 
135
- # True if ShellOpts lets exceptions through instead of writing an error
136
- # message and exit
136
+ # Use exceptions instead of ShellOpts's error methods. Default is
137
+ # ShellOpts.exception that itself defalts to false. Mostly used for debug
137
138
  attr_accessor :exception
138
139
 
139
140
  # Debug: Internal variables made public
@@ -155,8 +156,7 @@ module ShellOpts
155
156
  # Floating options
156
157
  float: true,
157
158
 
158
- # Let exceptions through
159
- exception: false
159
+ exception: ::ShellOpts.exception
160
160
  )
161
161
 
162
162
  @name = name || File.basename(file)
@@ -268,7 +268,8 @@ 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(subject = nil, message)
271
+ def error(message)
272
+ raise ShellOpts::Error.new(message) if ::ShellOpts.exception
272
273
  $stderr.puts "#{name}: #{message}"
273
274
  saved = $stdout
274
275
  begin
@@ -286,6 +287,7 @@ module ShellOpts
286
287
  # when the user specified the correct arguments but something else went
287
288
  # wrong during processing
288
289
  def failure(message)
290
+ raise ShellOpts::Failure.new(message) if ::ShellOpts.exception
289
291
  $stderr.puts "#{name}: #{message}"
290
292
  exit 1
291
293
  end
@@ -316,7 +318,7 @@ module ShellOpts
316
318
  end
317
319
 
318
320
  def handle_exceptions(&block)
319
- return yield if exception
321
+ return yield if ::ShellOpts.exception
320
322
  begin
321
323
  yield
322
324
  rescue Error => ex
@@ -408,6 +410,12 @@ module ShellOpts
408
410
  ShellOpts.process(spec, argv, silent: silent, quiet: quiet, verbose: verbose, debug: debug, **opts)
409
411
  end
410
412
 
413
+ # True if ShellOpts lets exceptions through instead of writing an error
414
+ # message and exit
415
+ @exception = false
416
+ def self.exception = @exception
417
+ def self.exception=(value) @exception = value end
418
+
411
419
  # The instance is a ShellOpts object. 'instance.program' and 'instance.argv'
412
420
  # is the same as the values returned from ShellOpts.process
413
421
  @instance = nil
@@ -428,13 +436,15 @@ module ShellOpts
428
436
  def self.verbose?(level = 1) level <= instance.program.__verbose__ end
429
437
  def self.debug?() instance.program.__debug__ end
430
438
 
431
- def self.error(subject = nil, message)
432
- instance.error(subject, message) if instance? # Never returns
439
+ def self.error(message)
440
+ raise Error.new(message) if exception
441
+ instance.error(message) if instance? # Never returns
433
442
  $stderr.puts "#{File.basename($PROGRAM_NAME)}: #{message}"
434
443
  exit 1
435
444
  end
436
445
 
437
446
  def self.failure(message)
447
+ raise Error.new(message) if exception
438
448
  instance.failure(message) if instance?
439
449
  $stderr.puts "#{File.basename($PROGRAM_NAME)}: #{message}"
440
450
  exit 1
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shellopts
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.6.3
4
+ version: 2.6.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claus Rasmussen
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2025-06-18 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: forward_to
@@ -159,7 +158,6 @@ files:
159
158
  homepage: http://github.com/clrgit/shellopts
160
159
  licenses: []
161
160
  metadata: {}
162
- post_install_message:
163
161
  rdoc_options: []
164
162
  require_paths:
165
163
  - lib
@@ -174,8 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
174
172
  - !ruby/object:Gem::Version
175
173
  version: '0'
176
174
  requirements: []
177
- rubygems_version: 3.3.7
178
- signing_key:
175
+ rubygems_version: 3.6.9
179
176
  specification_version: 4
180
177
  summary: Parse command line options and arguments
181
178
  test_files: []