Class: Lilp::Option

Inherits:
Object
  • Object
show all
Defined in:
lib/lilp/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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.banner =
    "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

#filesObject (readonly)

Returns the value of attribute files.



4
5
6
# File 'lib/lilp/base.rb', line 4

def files
  @files
end

#paramsObject (readonly)

Returns the value of attribute params.



4
5
6
# File 'lib/lilp/base.rb', line 4

def params
  @params
end

Instance Method Details

#parseObject



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