class Apollo::ConsoleProgram

Public Class Methods

new() click to toggle source

Initializer - Constructor

Calls superclass method Apollo::BaseProgram::new
# File lib/apollo_crawler/program/console_program.rb, line 59
def initialize
        super
        
        @options = {}
end

Public Instance Methods

init_options() click to toggle source

Initialize command-line options

# File lib/apollo_crawler/program/console_program.rb, line 66
def init_options()
        @options[:env] = Apollo::ENV 

        @options[:verbose] = false
        @options[:version] = nil
end
init_options_parser() click to toggle source
# File lib/apollo_crawler/program/console_program.rb, line 73
def init_options_parser()
        @optparser = OptionParser.new do | opts |
                opts.banner = "Usage: apollo-console [OPTIONS]"

                opts.separator ""
        opts.separator "Specific options:"

                # This displays the help screen, all programs are
                # assumed to have this option.
                opts.on('-h', '--help', 'Display this screen') do
                        @options[:show_help] = true
                end

                opts.on('-e', '--environment [NAME]', "Environment used, default '#{@options[:env]}'") do |name|
                        @options[:env] = name
                end

                opts.on('-v', '--verbose', 'Enable verbose output') do
                        @options[:verbose] = true
                end

                opts.on('-V', '--version', 'Show version info') do
                        @options[:version] = true
                end

                opts.on('-s', '--silent', 'Silent mode - do not print processed document') do
                        @options[:silent] = true
                end 
        end
end
init_program(args) click to toggle source

Init program

# File lib/apollo_crawler/program/console_program.rb, line 130
def init_program(args)
        init_options()
        init_options_parser()


        parse_options(args)

        res = process_options(args)
        if res != nil
                return res
        end

        return nil
end
parse_options(args = ARGV) click to toggle source

Parse the options passed to command-line

# File lib/apollo_crawler/program/console_program.rb, line 105
def parse_options(args = ARGV)
        # Parse the command-line. Remember there are two forms
        # of the parse method. The 'parse' method simply parses
        # ARGV, while the 'parse!' method parses ARGV and removes
        # any options found there, as well as any parameters for
        # the options. What's left is the list of files to resize.
        @optparser.parse!(args)
end
process_options(args) click to toggle source
# File lib/apollo_crawler/program/console_program.rb, line 114
def process_options(args)
        if(@options[:version])
                puts Apollo::VERSION
                return 0
        end

        if(@options[:show_help])
                puts @optparser
                return 0
        end

        return nil
end
request_exit(code = 0) click to toggle source
# File lib/apollo_crawler/program/console_program.rb, line 167
def request_exit(code = 0)
        begin
                exit(0)
        rescue SystemExit => e
                # puts "rescued a SystemExit exception, reason: '#{e.to_s}'"
        end

        return code
end
run(args = ARGV) click to toggle source

Run Program

# File lib/apollo_crawler/program/console_program.rb, line 146
def run(args = ARGV)
        res_code = init_program(args)

        if res_code.nil? == false
                return request_exit(res_code)
        end

        if(@options[:verbose])
                puts "Running environment '#{@options[:env]}'"
        end

        # if(ARGV.length < 1)
        #    puts @optparser
        #    return 0
        # end

        # Here we start

        return request_exit(res_code)
end