Class Kwalify::Main
In: kwalify/main.rb
Parent: Object

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

Methods

_inspect   debug?   execute   main   new  

Public Class methods

[Source]

# File kwalify/main.rb, line 120
      def self.main(command, argv=ARGV)
         begin
            main = Kwalify::Main.new(command)
            s = main.execute(argv)
            print s if s
         rescue Kwalify::CommandOptionError => ex
            $stderr.puts ex.message
            exit 1
         rescue Kwalify::KwalifyError => ex
            $stderr.puts "ERROR: #{ex.message}"
            exit 1
         #rescue => ex
         #   if main.debug?
         #      raise ex
         #   else
         #      $stderr.puts ex.message
         #      exit 1
         #   end
         end
      end

[Source]

# File 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(?d, tpath)
         end
      end

Public Instance methods

[Source]

# File 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

[Source]

# File kwalify/main.rb, line 57
      def debug?
         @options[:debug]
      end

[Source]

# File 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
            return s
         end

         # validation
         if @options[:meta2]
            s = _quick_meta_validate(filenames)
         elsif @options[:meta]
            s = _meta_validate(filenames)
         elsif @options[:action]
            if !@options[:schema]
               #* key=:command_option_actionnoschema  msg="schema filename is not specified."
               raise option_error(:command_option_actionnoschema, @options[:action])
            end
            s = _perform_action(@options[:action], @options[:schema])
         elsif @options[:schema]
            if @options[:debug]
               s = _inspect_schema(@options[:schema])
            else
               s = _validate(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 s   # or return (s == nil || s.empty?) ? nil : s
      end

[Validate]