Module: Fop::CLI

Defined in:
lib/fop/cli.rb

Defined Under Namespace

Classes: Options

Class Method Summary collapse

Class Method Details

.options!Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/fop/cli.rb', line 7

def self.options!
  options = Options.new
  OptionParser.new do |opts|
    opts.banner = "Usage: fop [options] [ 'prog' | -f progfile ] [ file ... ]"

    opts.on("-fFILE", "--file=FILE", "Read program from file instead of first argument") do |f|
      options.src = File.open(f)
      options.src.advise(:sequential)
    end

    opts.on("-c", "--check", "Perform a syntax check on the program and exit") do
      options.check = true
    end

    opts.on("-q", "--quiet", "Only print errors and output") do
      options.quiet = true
    end

    opts.on("--version", "Print version and exit") do
      options.version = true
    end
  end.parse!

  options.src ||= StringIO.new(ARGV.shift || "")
  options
end