Class: Kwalify::MainProgram

Inherits:
Object
  • Object
show all
Defined in:
lib/kwalify/main-program.rb

Overview

ex.

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

Instance Method Summary collapse

Constructor Details

#initialize(argv = ARGV, command = nil) ⇒ MainProgram

Returns a new instance of MainProgram.



32
33
34
35
36
# File 'lib/kwalify/main-program.rb', line 32

def initialize(argv=ARGV, command=nil)
   @command = command || File.basename($0)
   @options, @proerties = _parse_argv(argv)
   @filenames = argv
end

Instance Method Details

#execute(filenames = @filenames) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/kwalify/main-program.rb', line 39

def execute(filenames=@filenames)
   if @options[:help] || @options[:version]
      s = ''
      s << _version() if @options[:version]
      s << _usage()   if @options[:help]
      return s
   end
   if @options[:meta] || @options[:meta2]
      s = _meta_validate(filenames)
   elsif @options[:schema]
      if @options[:debug]
         s = _inspect_schema(@options[:schema])
      else
         s = _validate(filenames)
      end
   else
      #* key=:action_required  msg="command-line option '-f' or '-m' required."
      raise CommandOptionError.new(nil, nil, Kwalify.msg(:action_required))
   end
   return s   # or return (s == nil || s.empty?) ? nil : s
end