Class: Lilp::Option
- Inherits:
-
Object
- Object
- Lilp::Option
- Defined in:
- lib/lilp/base.rb
Instance Attribute Summary collapse
-
#files ⇒ Object
readonly
Returns the value of attribute files.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
-
#initialize(args) ⇒ Option
constructor
A new instance of Option.
- #parse ⇒ Object
Constructor Details
#initialize(args) ⇒ Option
Returns a new instance of Option.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/lilp/base.rb', line 6 def initialize( args ) @params = {} @parser = OptionParser.new @args = args @parser. = "Usage: lilp file_name.pl [other_file.pl] [-o output_dir]" @parser.on("-o", "--output D", String, "Output directory") do |val| @params[:output] = File.join('.', "#{val}") end @parser.on("-v", "--version", "Version number") do puts "lilp version " + Lilp::VERSION exit end end |
Instance Attribute Details
#files ⇒ Object (readonly)
Returns the value of attribute files.
4 5 6 |
# File 'lib/lilp/base.rb', line 4 def files @files end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
4 5 6 |
# File 'lib/lilp/base.rb', line 4 def params @params end |
Instance Method Details
#parse ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/lilp/base.rb', line 24 def parse begin @files = @parser.parse(@args) if @files.empty? puts "Missing file names" puts @parser exit end rescue OptionParser::InvalidOption => opt puts "Unknown option #{opt}" puts @parser exit rescue OptionParser::MissingArgument => opt puts opt puts @parser exit end end |