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/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.3.0"
Class Method Summary
collapse
-
.debug(message, newline: true) ⇒ Object
-
.debug_flag ⇒ Object
-
.error(subject = nil, message) ⇒ Object
-
.failure(message) ⇒ Object
-
.instance ⇒ Object
-
.instance=(instance) ⇒ Object
-
.instance? ⇒ Boolean
-
.mesg(message, newline: true) ⇒ Object
-
.notice(message, newline: true) ⇒ Object
-
.process(spec, argv, quiet: nil, verbose: nil, debug: nil, **opts) ⇒ Object
-
.quiet_flag ⇒ Object
-
.shellopts ⇒ Object
-
.verb(level = 1, message, newline: true) ⇒ Object
-
.verbose_flag ⇒ Object
Class Method Details
.debug(message, newline: true) ⇒ Object
437
438
439
440
|
# File 'lib/shellopts.rb', line 437
def self.debug(message, newline: true)
method = newline ? :puts : :print
$stdout.send(method, message) if instance.debug && instance.program.__debug__
end
|
.debug_flag ⇒ Object
448
449
|
# File 'lib/shellopts.rb', line 448
def self.debug_flag
end
|
.error(subject = nil, message) ⇒ Object
410
411
412
413
414
|
# File 'lib/shellopts.rb', line 410
def self.error(subject = nil, message)
instance.error(subject, message) if instance? $stderr.puts "#{File.basename($PROGRAM_NAME)}: #{message}"
exit 1
end
|
.failure(message) ⇒ Object
416
417
418
419
420
|
# File 'lib/shellopts.rb', line 416
def self.failure(message)
instance.failure(message) if instance?
$stderr.puts "#{File.basename($PROGRAM_NAME)}: #{message}"
exit 1
end
|
.instance ⇒ Object
406
|
# File 'lib/shellopts.rb', line 406
def self.instance() @instance or raise Error, "ShellOpts is not initialized" end
|
.instance=(instance) ⇒ Object
407
|
# File 'lib/shellopts.rb', line 407
def self.instance=(instance) @instance = instance end
|
.instance? ⇒ Boolean
405
|
# File 'lib/shellopts.rb', line 405
def self.instance?() !@instance.nil? end
|
.mesg(message, newline: true) ⇒ Object
427
428
429
430
|
# File 'lib/shellopts.rb', line 427
def self.mesg(message, newline: true)
method = newline ? :puts : :print
$stdout.send(method, message) if !instance.quiet || !instance.program.__quiet__
end
|
.notice(message, newline: true) ⇒ Object
422
423
424
425
|
# File 'lib/shellopts.rb', line 422
def self.notice(message, newline: true)
method = newline ? :puts : :print
$stderr.send(method, message) if !instance.quiet || !instance.program.quiet? end
|
.process(spec, argv, quiet: nil, verbose: nil, debug: nil, **opts) ⇒ Object
396
397
398
399
400
401
402
|
# File 'lib/shellopts.rb', line 396
def self.process(spec, argv, quiet: nil, verbose: nil, debug: nil, **opts)
constrain quiet, String, true, false, nil
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, quiet: quiet, verbose: verbose, debug: debug, **opts)
end
|
.quiet_flag ⇒ Object
442
443
|
# File 'lib/shellopts.rb', line 442
def self.quiet_flag
end
|
.shellopts ⇒ Object
408
|
# File 'lib/shellopts.rb', line 408
def self.shellopts() instance end
|
.verb(level = 1, message, newline: true) ⇒ Object
432
433
434
435
|
# File 'lib/shellopts.rb', line 432
def self.verb(level = 1, message, newline: true)
method = newline ? :puts : :print
$stdout.send(method, message) if instance.verbose && level <= instance.program.__verbose__
end
|
.verbose_flag ⇒ Object
445
446
|
# File 'lib/shellopts.rb', line 445
def self.verbose_flag
end
|