Class: Apollo::ConsoleProgram
- Inherits:
-
BaseProgram
- Object
- BaseProgram
- Apollo::ConsoleProgram
- Defined in:
- lib/apollo_crawler/program/console_program.rb
Constant Summary
Constants inherited from BaseProgram
BaseProgram::CONFIG_DIR, BaseProgram::DEFAULT_OPTIONS
Instance Attribute Summary
Attributes inherited from BaseProgram
#amqp, #config, #mongo, #options, #optparser
Instance Method Summary collapse
-
#init_options ⇒ Object
Initialize command-line options.
- #init_options_parser ⇒ Object
-
#init_program(args) ⇒ Object
Init program.
-
#initialize ⇒ ConsoleProgram
constructor
Initializer - Constructor.
-
#parse_options(args = ARGV) ⇒ Object
Parse the options passed to command-line.
- #process_options(args) ⇒ Object
- #request_exit(code = 0) ⇒ Object
-
#run(args = ARGV) ⇒ Object
Run Program.
Methods inherited from BaseProgram
get_config_path, #init_amqp, #init_mongo, #init_seeds, #init_seeds_crawlers, #load_config, #load_config_file, #load_configs, require_files
Constructor Details
#initialize ⇒ ConsoleProgram
Initializer - Constructor
59 60 61 62 63 |
# File 'lib/apollo_crawler/program/console_program.rb', line 59 def initialize super @options = {} end |
Instance Method Details
#init_options ⇒ Object
Initialize command-line options
66 67 68 69 70 71 |
# File 'lib/apollo_crawler/program/console_program.rb', line 66 def () @options[:env] = Apollo::ENV @options[:verbose] = false @options[:version] = nil end |
#init_options_parser ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/apollo_crawler/program/console_program.rb', line 73 def () @optparser = OptionParser.new do | opts | opts. = "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) ⇒ Object
Init program
130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/apollo_crawler/program/console_program.rb', line 130 def init_program(args) () () (args) res = (args) if res != nil return res end return nil end |
#parse_options(args = ARGV) ⇒ Object
Parse the options passed to command-line
105 106 107 108 109 110 111 112 |
# File 'lib/apollo_crawler/program/console_program.rb', line 105 def (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) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/apollo_crawler/program/console_program.rb', line 114 def (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) ⇒ Object
167 168 169 170 171 172 173 174 175 |
# 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) ⇒ Object
Run Program
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# 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 |