Class: BrewLib::CLI
- Inherits:
-
Object
- Object
- BrewLib::CLI
- Defined in:
- lib/brew_lib.rb
Overview
BrewLib::CLI
Instance Method Summary collapse
-
#exception_handling ⇒ Object
Provide standard exception handling for the given block.
-
#initialize(argv = ARGV) ⇒ CLI
constructor
A new instance of CLI.
-
#options ⇒ Object
Application options from the command line.
-
#options_set_default ⇒ Object
set default values for options.
-
#options_spec ⇒ Object
A list of all the standard options used in rake, suitable for passing to OptionParser.
Constructor Details
#initialize(argv = ARGV) ⇒ CLI
Returns a new instance of CLI.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/brew_lib.rb', line 41 def initialize(argv = ARGV) exception_handling do OptionParser.new do |opts| # noinspection RubyNilAnalysis opts. = "#{NAME} {options}" opts.separator "" opts.separator "Options:" opts.on_tail("-h", "--help", "-H", "Display this help message.") do puts opts exit end .each { |args| opts.on(*args) } end.parse(argv) end BrewLib.post if .post end |
Instance Method Details
#exception_handling ⇒ Object
Provide standard exception handling for the given block.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/brew_lib.rb', line 90 def exception_handling yield rescue SystemExit # Exit silently with current status raise rescue OptionParser::InvalidOption => e warn e. exit(false) rescue StandardError => e # Exit with error message puts e puts e.backtrace unless e.backtrace.nil? puts e.cause unless e.cause.nil? puts e.chain unless e.chain.nil? exit(false) end |
#options ⇒ Object
Application options from the command line
78 79 80 |
# File 'lib/brew_lib.rb', line 78 def @options ||= OpenStruct.new end |
#options_set_default ⇒ Object
set default values for options
83 84 85 86 87 |
# File 'lib/brew_lib.rb', line 83 def .post = false .silent = false .verbose = false end |
#options_spec ⇒ Object
A list of all the standard options used in rake, suitable for passing to OptionParser.
63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/brew_lib.rb', line 63 def # :nodoc: [ ["--post", "-p", "Post install ", ->(_) { .post = true }], ["--silent", "-s", "Like --quiet, but also suppresses the 'in directory' announcement.", ->(_) { .silent = true }], ["--verbose", "-v", "Log message to standard output.", ->(_) { .verbose = true }], ["--version", "-V", "Display the program version.", lambda { |_| puts BrewLib::VERSION exit }] ] end |