Sha256: 5145f713bd5874424b5e756859ecff7f028cd9d563d257badb61f4137d395cce

Contents?: true

Size: 1.69 KB

Versions: 4

Compression:

Stored size: 1.69 KB

Contents

#! /usr/bin/env ruby
#
#       ActiveFacts: Read a Vocabulary (from a NORMA, CQL or other file) and run a generator
#
# Copyright (c) 2009 Clifford Heath. Read the LICENSE file.
#
$:.unshift File.dirname(File.expand_path(__FILE__))+"/../lib"

require 'rubygems'

require 'activefacts'
require 'activefacts/vocabulary'

arg = ARGV.shift || "--help"

# Load the required generator, or the default "text" generator:
generator = "text"
generator_options = []
if arg =~ /^--([^=]*)(?:=(.*))?/
  generator = $1
  generator_options = ($2||"").split(/,/)
  arg = ARGV.shift
end

output_handler = "activefacts/generate/#{generator.downcase}"
begin
  require output_handler
rescue LoadError
  $stderr.puts "Could not find output generator #{generator}. Try --help"
  exit 1
end
output_class = generator.upcase.gsub(%r{[/\\]+},'::')
output_klass = eval("ActiveFacts::Generate::#{output_class}")
raise "Expected #{output_handler} to define #{output_class}" unless output_klass

# Load the file type input method
if arg
  arg, *options = *arg.split(/=/)
  extension = arg.sub(/\A.*\./,'').downcase
  input_handler = "activefacts/input/#{extension}"
  require input_handler

  input_class = extension.upcase
  input_klass = ActiveFacts::Input.const_get(input_class.to_sym)
  raise "Expected #{input_handler} to define #{input_class}" unless input_klass
end

# Read the input file:
begin
  if input_klass
    vocabulary = input_klass.readfile(arg, *options)
  else
    vocabulary = true
  end

  # Generate the output:
  output_klass.new(vocabulary, *generator_options).generate if vocabulary
rescue => e
  $stderr.puts "#{e.message}"
  # puts "\t#{e.backtrace*"\n\t"}"
  $stderr.puts "\t#{e.backtrace*"\n\t"}" if debug :exception
  exit 1
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
activefacts-0.8.16 bin/afgen
activefacts-0.8.15 bin/afgen
activefacts-0.8.13 bin/afgen
activefacts-0.8.12 bin/afgen