StdlibDoc::Status::App (Class)

In: StdlibDoc/Status/App.rb
Parent: Object

This class implements the application itself. It is run, it parses arguments, and it decides what needs to be done.

Only intended usage: StdlibDoc::Status::App.new.run(ARGV)

Methods

_parse   new   run  

Constants

REPORTS = Report.reports

Public Class methods

[Source]

# File StdlibDoc/Status/App.rb, line 46
    def initialize
    end

Public Instance methods

Parse the command-line options, load the database, and execute a report.

[Source]

# File StdlibDoc/Status/App.rb, line 52
    def run(args)
      options = _parse(args)
      records = Database.new.records

      # Restrict the records to those matching given paths.

      unless options.paths.empty?
        records = records.select { |f|
          options.paths.map { |regex| f.path =~ regex }.any?
        }
      end

      puts Report.execute(options.report_num, records, options)
    end

Private Instance methods

[Source]

# File StdlibDoc/Status/App.rb, line 68
    def _parse(args) # :doc:

      options = Options.new do |o|
        o.report_num = nil
        o.paths = []
        o.report_type = nil
        o.color = false
      end

      parser = OptionParser.new do |p|
        p.summary_indent = "    "
        p.banner = %{
          | 
          | Usage:
          |   ruby stdlib-doc.rb status <command> [options]
          |
          | Commands:
        }.trim('|')
        p.on("-r", "--report N", Integer, "Display report number N") do |n|
          options.report_num = n - 1
        end
        p.on("-l", "--list", "Display list of available reports") do
          _show_report_list
          exit
        end
        p.on("-v", "--verify", "Verify the contents of the stataus database") do
          raise "Verification not yet implemented"
        end
        p.on("-u", "--update-loc", "Update the LOC values in the status database") do
          raise "Update LOC not yet implemented"
        end
        p.on("-h", "--help", "Show this message") do
          _show_usage(p, STDOUT, 0)
          exit
        end
        p.separator("")
        p.separator("Options:")
        p.on("-p", "--path PATH", String, "Only show paths matching PATH regex",
                "  (may be given more than once)") do |path|
          regex = Regexp.compile(Regexp.escape(path))
          options.paths << regex
        end
        # For --type, we only accept valid arguments.  They can be abbreviated.

        p.on("-t", "--type TYPE", String, tgts = Report.types,
                "Use given kind of report (TYPE) instead of default",
                "  TYPE = [ #{tgts.join(' | ')} ]") do |rtype|
          options.report_type = rtype
        end
        p.on("-c", "--color", "Use color output (terminal only)") do
          options.color = true
        end
      end

      begin
        begin
          parser.parse!(args)
        rescue OptionParser::ParseError => err
          raise err.message
        end
        raise "No command given." if options.report_num.nil?
        raise "Report number out of range." if REPORTS[options.report_num].nil?
        return options
      rescue => err
        msg = "\nError:\n" + err.message.tabto(2)
        begin
          require 'text/highlight'
          String.highlighter = "ANSI"
          msg = msg.red.on_white
        rescue LoadError
        end
        STDERR.puts msg
        _show_usage(parser, STDERR, 1)
      end
    end

[Validate]