Sha256: 2800410b84e31b5f8ed1338ecface59ea2edc08f7c3cdb15dd0a1644bc4455e3

Contents?: true

Size: 1.77 KB

Versions: 9

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

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
activefacts-1.6.0 bin/afgen
activefacts-1.5.3 bin/afgen
activefacts-1.5.2 bin/afgen
activefacts-1.5.1 bin/afgen
activefacts-1.5.0 bin/afgen
activefacts-1.3.0 bin/afgen
activefacts-1.2.1 bin/afgen
activefacts-1.2.0 bin/afgen
activefacts-1.1.0 bin/afgen