Class: HanselCore::ArgParser
- Inherits:
-
Object
- Object
- HanselCore::ArgParser
- Defined in:
- lib/hansel/arg_parser.rb
Overview
Parse the command configuration file options and command line arguments. Command line arguments override those from the configuration file See www.ruby-doc.org/stdlib/libdoc/optparse/rdoc/classes/OptionParser.html
Instance Method Summary collapse
-
#initialize(args) ⇒ ArgParser
constructor
Setup default values for the parsed options.
-
#parse ⇒ Object
Uses OptionParser to return an OpenStruct object describing the options.
Constructor Details
#initialize(args) ⇒ ArgParser
Setup default values for the parsed options
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/hansel/arg_parser.rb', line 13 def initialize args @args = args @options = OpenStruct.new( :verbose => false, :output_format => :yaml, :output_dir => File.join(ENV['HOME'], 'hansel_output'), :template_path => 'templates', :template => nil, :exit => false, :master => nil ) end |
Instance Method Details
#parse ⇒ Object
Uses OptionParser to return an OpenStruct object describing the options.
29 30 31 32 33 34 |
# File 'lib/hansel/arg_parser.rb', line 29 def parse # The options specified on the command line will be collected in *options*. # We set default values here. OptionParser.new { || }.parse!(@args) @options end |