Class: BrewLib::CLI
- Inherits:
-
Object
- Object
- BrewLib::CLI
- Defined in:
- lib/brew_lib.rb
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.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/brew_lib.rb', line 48 def initialize(argv = ARGV) exception_handling do OptionParser.new do |opts| # noinspection RubyNilAnalysis opts. = "#{BrewLib.name.underscore} {options}" opts.separator "" opts.separator "Options are ..." 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.
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/brew_lib.rb', line 108 def exception_handling # :nodoc: yield rescue SystemExit # Exit silently with current status raise rescue OptionParser::InvalidOption => ex $stderr.puts ex. exit(false) rescue Exception => ex # Exit with error message puts ex puts ex.backtrace unless ex.backtrace.nil? puts ex.cause unless ex.cause.nil? puts ex.chain unless ex.chain.nil? exit(false) end |
#options ⇒ Object
Application options from the command line
96 97 98 |
# File 'lib/brew_lib.rb', line 96 def @options ||= OpenStruct.new end |
#options_set_default ⇒ Object
set default values for options
101 102 103 104 105 |
# File 'lib/brew_lib.rb', line 101 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.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/brew_lib.rb', line 70 def # :nodoc: [ ["--post", "-p", "Post install " , lambda { |_| .post = true } ], ["--silent", "-s", "Like --quiet, but also suppresses the " + "'in directory' announcement.", lambda { |_| .silent = true } ], ["--verbose", "-v", "Log message to standard output.", lambda { |_| .verbose = true } ], ["--version", "-V", "Display the program version.", lambda { |_| puts BrewLib::VERSION exit } ], ] end |