Sha256: 7b3fd87f8d6a6574fdb51449e0a45e35e4e5a7c72de2df698a565570d8c56804

Contents?: true

Size: 1.49 KB

Versions: 2

Compression:

Stored size: 1.49 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.
#

require 'activefacts'
require 'activefacts/metamodel'

# Load the generators:
generators = []
arg = ARGV.shift || "--help"
while arg =~ /^--([^=]*)(?:=(.*))?/
  module_name, options = $1, ($2||"").split(/,/)
  begin
    require "activefacts/generators/#{module_name}"

    generators << [ActiveFacts::Registry.generators[module_name], options]
  rescue LoadError => e
    $stderr.puts "Could not find output module #{module_name}. Try --help"
    exit 1
  end

  arg = ARGV.shift
end

# 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

  exit 0 unless vocabulary

  vocabulary.finalise unless vocabulary == true

  # Generate the output:
  generators.each do |generator, options|
    generator.new(vocabulary, *options).generate
  end
rescue => e
  $stderr.puts "#{e.message}"
  # puts "\t#{e.backtrace*"\n\t"}"
  $stderr.puts "\t#{e.backtrace*"\n\t"}" if trace :exception
  exit 1
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
activefacts-1.9.0 bin/afgen
activefacts-1.8.3 bin/afgen