Top Level Namespace

Defined Under Namespace

Modules: SPQR

Instance Method Summary collapse

Instance Method Details

#mainObject



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
58
59
60
61
62
# File 'bin/spqr-gen.rb', line 20

def main
  $OUTDIR = "."
  $DO_RHUBARB = false

  op = OptionParser.new do |opts|
    opts.banner = "Usage spqr.rb [options] schema-file"
    
    opts.on("-n", "--noclobber", "don't overwrite pre-existing output files") do |noclob|
      $PP_WRITEMODE = File::WRONLY|File::EXCL|File::CREAT
    end
    
    opts.on("-d", "--output-dir DIR", "directory in which to place generated app and controllers") do |dir|
      $OUTDIR = dir
    end

    opts.on("-r", "--rhubarb", "enable support for rhubarb in generated code") do
      $DO_RHUBARB = true
    end
  end
  
  begin
    op.parse!
  rescue OptionParser::InvalidOption
    puts op
    exit
  end
    

  begin
    SPQR::QmfSchemaProcessor.new(ARGV[0]).main
  rescue SystemCallError => sce
    if sce.errno == Errno::EEXIST::Errno
      fn = sce.message.split(" ")[-1] # XXX:  won't work for filenames with spaces
      puts "Not overwriting #{fn}; don't use --noclobber if you don't want this behavior"
    elsif sce.errno == Errno::ENOENT::Errno
      fn = sce.message.split(" ")[-1] # XXX:  won't work for filenames with spaces
      puts "File or directory \"#{fn}\" not found"
      puts sce.backtrace
    else
      puts "Failed due to #{sce.inspect}"
    end
  end
end