Class: Dockerchain::CLI::OptionParser
- Inherits:
-
Object
- Object
- Dockerchain::CLI::OptionParser
- Defined in:
- lib/dockerchain/cli/option_parser.rb
Instance Attribute Summary collapse
-
#opt_parser ⇒ Object
Returns the value of attribute opt_parser.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #help ⇒ Object
-
#initialize ⇒ OptionParser
constructor
A new instance of OptionParser.
-
#parse(args) ⇒ Object
Return a structure describing the options.
Constructor Details
#initialize ⇒ OptionParser
Returns a new instance of OptionParser.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/dockerchain/cli/option_parser.rb', line 10 def initialize # The options specified on the command line will be collected in *options*. # We set default values here. @options = ::OpenStruct.new .chain_file = '' .log_file = '' .src_path = '' .build_path = '' @opt_parser = ::OptionParser.new do |opts| opts. = 'Usage: dockerchain CHAINFILE [options]' opts.separator '' opts.separator 'Specific options:' opts.on('-l', '--logfile LOGFILE', 'Specify the LOGFILE to log output to') do |log_file| .log_file = log_file end opts.on('-s', '--srcpath SRCPATH', 'Specify the SRCPATH for where to download repositories') do |src_path| .src_path = src_path end opts.on('-b', '--buildpath BUILDPATH', 'Specify the BUILDPATH for where to do work') do |build_path| .build_path = build_path end opts.separator '' opts.separator 'Common options:' # No argument, shows at tail. This will print an options summary. # Try it and see! opts.on_tail('-h', '--help', 'Show this message') do puts opts exit end # Another typical switch to print the version. opts.on_tail('-v', '--version', 'Show version') do puts Dockerchain::VERSION exit end end end |
Instance Attribute Details
#opt_parser ⇒ Object
Returns the value of attribute opt_parser.
8 9 10 |
# File 'lib/dockerchain/cli/option_parser.rb', line 8 def opt_parser @opt_parser end |
#options ⇒ Object
Returns the value of attribute options.
8 9 10 |
# File 'lib/dockerchain/cli/option_parser.rb', line 8 def @options end |
Instance Method Details
#help ⇒ Object
59 60 61 |
# File 'lib/dockerchain/cli/option_parser.rb', line 59 def help opt_parser.help end |
#parse(args) ⇒ Object
Return a structure describing the options.
66 67 68 69 70 71 72 73 74 |
# File 'lib/dockerchain/cli/option_parser.rb', line 66 def parse(args) begin opt_parser.parse!(args) rescue ::OptionParser::InvalidOption => e puts help exit(1) end end |