class Kwalify::Main

ex.

command = File.basename($0)
begin
  main = Kwalify::Main.new(command)
  s = main.execute
  print s if s
rescue Kwalify::CommandOptionError => ex
  $stderr.puts "ERROR: #{ex.message}"
  exit 1
rescue Kwalify::KwalifyError => ex
  $stderr.puts "ERROR: #{ex.message}"
  exit 1
end

Public Class Methods

main(command, argv=ARGV) click to toggle source
# File lib/kwalify/main.rb, line 121
def self.main(command, argv=ARGV)
  begin
    main = Kwalify::Main.new(command)
    s = main.execute(argv)
    print s if s
  rescue Kwalify::CommandOptionError => ex
    raise ex if main.debug?
    $stderr.puts ex.message
    exit 1
  rescue Kwalify::KwalifyError => ex
    raise ex if main.debug?
    $stderr.puts "ERROR: #{ex.to_s}"
    exit 1
  #rescue => ex
  #  if main.debug?
  #    raise ex
  #  else
  #    $stderr.puts ex.message
  #    exit 1
  #  end
  end
end
new(command=nil) click to toggle source
# File lib/kwalify/main.rb, line 45
def initialize(command=nil)
  @command = command || File.basename($0)
  @options = {}
  @properties   = {}
  @template_path  = []
  $:.each do |path|
    tpath = "#{path}/kwalify/templates"
    @template_path << tpath if test(dd, tpath)
  end
end

Public Instance Methods

_inspect() click to toggle source
# File lib/kwalify/main.rb, line 62
def _inspect()
  sb = []
  sb <<   "command: #{@command}\n"
  sb <<   "options:\n"
  @options.keys.sort {|k1,k2| k1.to_s<=>k2.to_s }.each do |key|
    sb << "  - #{key}: #{@options[key]}\n"
  end
  sb <<   "properties:\n"
  @properties.keys.sort_by {|k| k.to_s}.each do |key|
    sb << "  - #{key}: #{@properties[key]}\n"
  end
  #sb <<   "template_path:\n"
  #@template_path.each do |path|
  #  sb << "  - #{path}\n"
  #end
  return sb.join
end
debug?() click to toggle source
# File lib/kwalify/main.rb, line 57
def debug?
  @options[:debug]
end
execute(argv=ARGV) click to toggle source
# File lib/kwalify/main.rb, line 81
def execute(argv=ARGV)
  ## parse command-line options
  filenames = _parse_argv(argv)

  ## help or version
  if @options[:help] || @options[:version]
    action = @options[:action]
    s = ''
    s << _version() << "\n"           if @options[:version]
    s << _usage()                     if @options[:help] && !action
    s << _describe_properties(action) if @options[:help] && action
    puts s
    return
  end

  # validation
  if @options[:meta2]
    validate_schemafiles2(filenames)
  elsif @options[:meta]
    validate_schemafiles(filenames)
  elsif @options[:action]
    unless @options[:schema]
      #* key=:command_option_actionnoschema  msg="schema filename is not specified."
      raise option_error(:command_option_actionnoschema, @options[:action])
    end
    perform_action(@options[:action], @options[:schema])
  elsif @options[:schema]
    if @options[:debug]
      inspect_schema(@options[:schema])
    else
      validate_files(filenames, @options[:schema])
    end
  else
    #* key=:command_option_noaction  msg="command-line option '-f' or '-m' required."
    raise option_error(:command_option_noaction, @command)
  end
  return
end