shellopts 2.3.0 → 2.4.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: 1c8545c5ef2b66679aa262ab499925ffa3e3a53e99df55844f658877a4722095
4
- data.tar.gz: adf2161d1a41f0161ed76031329a306677c88af739f341f01771eba863330a5c
3
+ metadata.gz: 68428ade0dd8ec48fa85a8d43362743d6dc5595d9f4af3347d0fa402eaf0e7bb
4
+ data.tar.gz: 51404fbc53ddbacb0b7a4552777e3de7c8abce1d508782f6c901da4b2cd332ba
5
5
  SHA512:
6
- metadata.gz: 260e46338b058593f0561bf524e595455060101e0de1bec96e3209b15992318cd29ed99a188d539ac2d57dad7c818306249fa3104a23da8e9fc665c1a7cb13fe
7
- data.tar.gz: 221cc49626cdd1d172f570187facf4e3941420ec12fc2fbe16a3d73c56fcddf048db40381234726467f2be8f568a9f81c95c038db0d26edff7b6fe31b76090a9
6
+ metadata.gz: ca5499680c53cc74388102b130eb9a7dfc7dc53ba7556615991d93d882ddc4993e1854891d78bbd97ccb4d37e8d493fb1c4e199cc4361f96ddb2e55c536f4cc7
7
+ data.tar.gz: d75bef2e9b154a0332ed55a272341072654db8c615c5e4c9a27a94823efd6bae354fe32ca14679c92553af3e0e4f69f50ca3aeb675c5149d8394195f1f5a9f4a
@@ -315,12 +315,14 @@ module ShellOpts
315
315
  class Program < Command
316
316
  # Accessors for standard options values that are not affected if the option
317
317
  # is renamed
318
+ attr_accessor :__silent__
318
319
  attr_accessor :__quiet__
319
320
  attr_accessor :__verbose__
320
321
  attr_accessor :__debug__
321
322
 
322
323
  def initialize
323
324
  super
325
+ @__silent__ = false
324
326
  @__quiet__ = false
325
327
  @__verbose__ = 0
326
328
  @__debug__ = false
@@ -1,3 +1,3 @@
1
1
  module ShellOpts
2
- VERSION = "2.3.0"
2
+ VERSION = "2.4.0"
3
3
  end
data/lib/shellopts.rb CHANGED
@@ -110,6 +110,9 @@ module ShellOpts
110
110
  # Version of client program. If not nil, a --version option is added to the program
111
111
  attr_reader :version
112
112
 
113
+ # Automatically add a -s and a --silent option if true
114
+ attr_reader :silent
115
+
113
116
  # Automatically add a -q and a --quiet option if true
114
117
  attr_reader :quiet
115
118
 
@@ -140,6 +143,7 @@ module ShellOpts
140
143
  # Options
141
144
  help: true,
142
145
  version: true,
146
+ silent: nil,
143
147
  quiet: nil,
144
148
  verbose: nil,
145
149
  debug: nil,
@@ -157,6 +161,7 @@ module ShellOpts
157
161
  @name = name || File.basename($PROGRAM_NAME)
158
162
  @help = help
159
163
  @version = version || (version.nil? && !version_number.nil?)
164
+ @silent = silent
160
165
  @quiet = quiet
161
166
  @verbose = verbose
162
167
  @debug = debug
@@ -177,10 +182,13 @@ module ShellOpts
177
182
 
178
183
  help_spec = (@help == true ? "-h,help" : @help)
179
184
  version_spec = (@version == true ? "--version" : @version)
185
+ silent_spec = (@silent == true ? "-q,silent" : @silent)
180
186
  quiet_spec = (@quiet == true ? "-q,quiet" : @quiet)
181
187
  verbose_spec = (@verbose == true ? "+v,verbose" : @verbose)
182
188
  debug_spec = (@debug == true ? "--debug" : @debug)
183
189
 
190
+ @silent_option =
191
+ ast.inject_option(silent_spec, "Quiet", "Do not write anything to standard output") if @silent
184
192
  @quiet_option =
185
193
  ast.inject_option(quiet_spec, "Quiet", "Do not write anything to standard output") if @quiet
186
194
  @verbose_option =
@@ -224,6 +232,8 @@ module ShellOpts
224
232
  puts version_number
225
233
  exit
226
234
  else
235
+ # Assign standard options. The targets doesn't change if the option is renamed
236
+ @program.__silent__ = @program.__send__(:"#{@silent_option.ident}?") if @silent
227
237
  @program.__quiet__ = @program.__send__(:"#{@quiet_option.ident}?") if @quiet
228
238
  @program.__verbose__ = @program.__send__(:"#{@verbose_option.ident}") if @verbose
229
239
  @program.__debug__ = @program.__send__(:"#{@debug_option.ident}?") if @debug
@@ -393,19 +403,35 @@ module ShellOpts
393
403
  end
394
404
  end
395
405
 
396
- def self.process(spec, argv, quiet: nil, verbose: nil, debug: nil, **opts)
406
+ def self.process(spec, argv, silent: nil, quiet: nil, verbose: nil, debug: nil, **opts)
407
+ constrain silent, String, true, false, nil
397
408
  constrain quiet, String, true, false, nil
409
+ silent = silent.nil? ? Message.is_included? || Verbose.is_included? : silent
398
410
  quiet = quiet.nil? ? Message.is_included? || Verbose.is_included? : quiet
399
411
  verbose = verbose.nil? ? ::ShellOpts::Verbose.is_included? : verbose
400
412
  debug = debug.nil? ? Debug.is_included? : debug
401
- ShellOpts.process(spec, argv, quiet: quiet, verbose: verbose, debug: debug, **opts)
413
+ ShellOpts.process(spec, argv, silent: silent, quiet: quiet, verbose: verbose, debug: debug, **opts)
402
414
  end
403
415
 
416
+ # The instance is a ShellOpts object. 'instance.program' and 'instance.argv'
417
+ # is the same as the values returned from ShellOpts.process
404
418
  @instance = nil
405
419
  def self.instance?() !@instance.nil? end
406
420
  def self.instance() @instance or raise Error, "ShellOpts is not initialized" end
407
421
  def self.instance=(instance) @instance = instance end
408
- def self.shellopts() instance end
422
+ def self.shellopts() instance end # TODO: Yt
423
+
424
+ # Returns the corresponding option status on the program object. Note that
425
+ # the "bare" ShellOpts standard option methods (eg. ShellOpts.silent)
426
+ # determines if an option can be used while the query methods (eg.
427
+ # ShellOpts.silent?) reports if the option was present on the command line
428
+ #
429
+ # The methods below are implemented using the name-independent members of
430
+ # Program: __silent__ etc.
431
+ def self.silent?() instance.program.__silent__ end
432
+ def self.quiet?() silent? || instance.program.__quiet__ end
433
+ def self.verbose?(level = 1) level <= instance.program.__verbose__ end
434
+ def self.debug?() instance.program.__debug__ end
409
435
 
410
436
  def self.error(subject = nil, message)
411
437
  instance.error(subject, message) if instance? # Never returns
@@ -419,33 +445,27 @@ module ShellOpts
419
445
  exit 1
420
446
  end
421
447
 
448
+ # Emit a message on standard error. The --silent option suppresses these messages
422
449
  def self.notice(message, newline: true)
423
450
  method = newline ? :puts : :print
424
- $stderr.send(method, message) if !instance.quiet || !instance.program.quiet? # FIXME quiet? vs __quiet__ below
451
+ $stderr.send(method, message) if !silent?
425
452
  end
426
453
 
454
+ # Emit a message on standard output. The --quiet option suppresses these messages
427
455
  def self.mesg(message, newline: true)
428
456
  method = newline ? :puts : :print
429
- $stdout.send(method, message) if !instance.quiet || !instance.program.__quiet__
457
+ $stdout.send(method, message) if !quiet?
430
458
  end
431
459
 
460
+ # Emit a message on standard output. The --verbose option controls these messages
432
461
  def self.verb(level = 1, message, newline: true)
433
462
  method = newline ? :puts : :print
434
- $stdout.send(method, message) if instance.verbose && level <= instance.program.__verbose__
463
+ $stdout.send(method, message) if verbose?(level)
435
464
  end
436
465
 
437
466
  def self.debug(message, newline: true)
438
467
  method = newline ? :puts : :print
439
- $stdout.send(method, message) if instance.debug && instance.program.__debug__
440
- end
441
-
442
- def self.quiet_flag
443
- end
444
-
445
- def self.verbose_flag
446
- end
447
-
448
- def self.debug_flag
468
+ $stdout.send(method, message) if debug?
449
469
  end
450
470
 
451
471
  module Message
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shellopts
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claus Rasmussen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-01-28 00:00:00.000000000 Z
11
+ date: 2024-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: forward_to