Sha256: 6514c8750ad108c29bc663eca3c4d374905c89bda838859d013a50957f04c682

Contents?: true

Size: 1.77 KB

Versions: 4

Compression:

Stored size: 1.77 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 'activefacts'
require 'activefacts/vocabulary'

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

    require "activefacts/generate/#{module_name}"

    # One require may load more than one generator. Extract new ones.
    new_generators = ActiveFacts::Registry.generators
    generators += (new_generators.keys-base_generators).map do |gn|
      [new_generators[gn], options]
    end

  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 debug :exception
  exit 1
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
activefacts-1.0.2 bin/afgen
activefacts-1.0.1 bin/afgen
activefacts-1.0.0 bin/afgen
activefacts-0.8.18 bin/afgen