Module: ShellOpts

Defined in:
lib/shellopts.rb,
lib/shellopts/ansi.rb,
lib/shellopts/args.rb,
lib/shellopts/dump.rb,
lib/shellopts/lexer.rb,
lib/shellopts/stack.rb,
lib/shellopts/token.rb,
lib/shellopts/option.rb,
lib/shellopts/parser.rb,
lib/shellopts/grammar.rb,
lib/shellopts/program.rb,
lib/shellopts/version.rb,
lib/shellopts/analyzer.rb,
lib/shellopts/renderer.rb,
lib/shellopts/formatter.rb,
lib/shellopts/interpreter.rb,
lib/shellopts/argument_type.rb

Overview

Option rendering

-a, --all                   # Only used in brief and doc formats (enum)
--all                       # Only used in usage (long)
-a                          # Only used in usage (short)

Option group rendering

-a, --all  -b, --beta       # Only used in brief formats (enum)
--all --beta                # Used in usage (long)
-a -b                       # Used in usage (short)

-a, --all                   # Only used in doc format (:multi)
-b, --beta

Command rendering

cmd --all --beta [cmd1|cmd2] ARG1 ARG2    # Single-line formats (:single)
cmd --all --beta [cmd1|cmd2] ARGS...      # Not used
cmd -a -b [cmd1|cmd2] ARG1 ARG2
cmd -a -b [cmd1|cmd2] ARGS...             # Not used

cmd -a -b [cmd1|cmd2] ARG1 ARG2           # One line for each argument description (:enum)
cmd -a -b [cmd1|cmd2] ARG3 ARG4           # (used in the USAGE section)

cmd --all --beta                          # Multi-line formats (:multi)
    [cmd1|cmd2] ARG1 ARG2
cmd --all --beta
    <commands> ARGS

Defined Under Namespace

Modules: Debug, ErrorHandling, Grammar, Message, Stack, Verbose Classes: Analyzer, AnalyzerError, Ansi, Args, Command, CompilerError, Error, Failure, Formatter, InternalError, Interpreter, Lexer, LexerError, Line, Option, Parser, ParserError, Program, ShellOpts, ShellOptsError, Token

Constant Summary collapse

VERSION =
"2.6.4"

Class Method Summary collapse

Class Method Details

.debug(message, newline: true) ⇒ Object



480
481
482
483
484
485
486
# File 'lib/shellopts.rb', line 480

def self.debug(message, newline: true)
  method = newline ? :puts : :print
  if debug?
    $stdout.send(method, message)
    $stdout.flush
  end
end

.debug?Boolean

Returns:

  • (Boolean)


437
# File 'lib/shellopts.rb', line 437

def self.debug?() instance.program.__debug__ end

.error(message) ⇒ Object

Raises:



439
440
441
442
443
444
# File 'lib/shellopts.rb', line 439

def self.error(message)
  raise Error.new(message) if exception
  instance.error(message) if instance? # Never returns
  $stderr.puts "#{File.basename($PROGRAM_NAME)}: #{message}"
  exit 1
end

.exceptionObject



416
# File 'lib/shellopts.rb', line 416

def self.exception = @exception

.exception=(value) ⇒ Object



417
# File 'lib/shellopts.rb', line 417

def self.exception=(value) @exception = value end

.failure(message) ⇒ Object

Raises:



446
447
448
449
450
451
# File 'lib/shellopts.rb', line 446

def self.failure(message)
  raise Error.new(message) if exception
  instance.failure(message) if instance?
  $stderr.puts "#{File.basename($PROGRAM_NAME)}: #{message}"
  exit 1
end

.instanceObject



423
# File 'lib/shellopts.rb', line 423

def self.instance() @instance or raise Error, "ShellOpts is not initialized" end

.instance=(instance) ⇒ Object



424
# File 'lib/shellopts.rb', line 424

def self.instance=(instance) @instance = instance end

.instance?Boolean

Returns:

  • (Boolean)


422
# File 'lib/shellopts.rb', line 422

def self.instance?() !@instance.nil? end

.mesg(message, newline: true) ⇒ Object

Emit a message on standard output. The –quiet option suppresses these messages



463
464
465
466
467
468
469
# File 'lib/shellopts.rb', line 463

def self.mesg(message, newline: true)
  method = newline ? :puts : :print
  if !quiet?
    $stdout.send(method, message)
    $stdout.flush
  end
end

.notice(message, newline: true) ⇒ Object

Emit a message on standard error. The –silent option suppresses these messages



454
455
456
457
458
459
460
# File 'lib/shellopts.rb', line 454

def self.notice(message, newline: true)
  method = newline ? :puts : :print
  if !silent?
    $stderr.send(method, message)
    $stderr.flush
  end
end

.process(spec, argv, silent: nil, quiet: nil, verbose: nil, debug: nil, **opts) ⇒ Object



403
404
405
406
407
408
409
410
411
# File 'lib/shellopts.rb', line 403

def self.process(spec, argv, silent: nil, quiet: nil, verbose: nil, debug: nil, **opts)
  constrain silent, String, true, false, nil
  constrain quiet, String, true, false, nil
  silent = silent.nil? ? Message.is_included? || Verbose.is_included? : silent
  quiet = quiet.nil? ? Message.is_included? || Verbose.is_included? : quiet
  verbose = verbose.nil? ? ::ShellOpts::Verbose.is_included? : verbose
  debug = debug.nil? ? Debug.is_included? : debug
  ShellOpts.process(spec, argv, silent: silent, quiet: quiet, verbose: verbose, debug: debug, **opts)
end

.quiet?Boolean

Returns:

  • (Boolean)


435
# File 'lib/shellopts.rb', line 435

def self.quiet?() silent? || instance.program.__quiet__ end

.shelloptsObject

TODO: Yt



425
# File 'lib/shellopts.rb', line 425

def self.shellopts() instance end

.silent?Boolean

Returns the corresponding option status on the program object. Note that the “bare” ShellOpts standard option methods (eg. ShellOpts.silent) determines if an option can be used while the query methods (eg. ShellOpts.silent?) reports if the option was present on the command line

The methods below are implemented using the name-independent members of Program: __silent__ etc.

Returns:

  • (Boolean)


434
# File 'lib/shellopts.rb', line 434

def self.silent?() instance.program.__silent__ end

.verb(level = 1, message, newline: true) ⇒ Object

Emit a message on standard output. The –verbose option controls these messages



472
473
474
475
476
477
478
# File 'lib/shellopts.rb', line 472

def self.verb(level = 1, message, newline: true)
  method = newline ? :puts : :print
  if verbose?(level)
    $stdout.send(method, message)
    $stdout.flush
  end
end

.verbose?(level = 1) ⇒ Boolean

Returns:

  • (Boolean)


436
# File 'lib/shellopts.rb', line 436

def self.verbose?(level = 1) level <= instance.program.__verbose__ end