Class: JobManager::ApplicationOptionParser
- Inherits:
-
Object
- Object
- JobManager::ApplicationOptionParser
- Defined in:
- lib/jobmanager/applicationoptionparser.rb
Overview
This class is composed of the command line argument parsing code for the jobmanager application.
Class Method Summary collapse
- .get_usage(program_name) ⇒ Object
-
.parse(program_name, args) ⇒ Object
Description: This method parses the command line options and arguments passed in and returns a hash of these values.
Class Method Details
.get_usage(program_name) ⇒ Object
163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/jobmanager/applicationoptionparser.rb', line 163 def self.get_usage(program_name) usage = <<-EOL Usage: #{program_name} [options] <command> See http://jobmanager.rubyforge.com for a more detailed description and usage examples. EOL usage end |
.parse(program_name, args) ⇒ Object
Description:
This method parses the command line options and arguments passed in and returns a hash of these values.
Parameters:
- program_name
-
The program name.
- args
-
The command line arguments.
Returns:
A hash of the command line options and arugments.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 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 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/jobmanager/applicationoptionparser.rb', line 26 def self.parse(program_name, args) = {} opts = OptionParser.new opts.program_name = program_name opts.summary_width = 40 opts. = get_usage(program_name) opts.separator "" opts.separator "Specific options:" is_job_name_set = false opts.on("-j", "--job_name NAME", "The name of the job to be run, and thus the basename of the log file.") do |job_name| ["job_name"] = job_name is_job_name_set = true end opts.on("-l", "--job_logs_directory PATH", "The directory in which the job logs will be kept.") do |logs_directory| ["job_logs_directory"] = logs_directory end conditions = JobManager::ApplicationConfig::EMAIL_CONDITIONS.join(', ') opts.on("-c", "--email_condition CONDITION", "The condition upon which results should be emailed.", "Possible values are:(#{conditions}.") do |condition| ["email_condition"] = condition end modes = JobManager::ApplicationConfig::CENTRAL_LOG_MODES.join(', ') opts.on("-m", "--central_log_mode MODE", "Possible values are #{modes}.") do |mode| ["central_log_mode"] = mode end opts.on("-n", "--number_of_job_logs LOGS", "Number of log files to be kept per job.") do |number_of_logs| ["number_of_job_logs"] = number_of_logs end opts.on("-x", "--[no-]date_time_extension", "Whether to add a date/time extension to the rotated log file.") do |value| ["date_time_extension"] = value end opts.on("-f", "--date_time_extension_format FORMAT", "The date/time format of the rotated log file extension.") do |format| ["date_time_extension_format"] = format end opts.on("-z", "--[no-]zip_rotated_log_file", "Zip the rotated log file.") do |value| ["zip_rotated_log_file"] = value end opts.on("-r", "--central_log_file FILE", "The central log file to which jobmanager writes.", "This field is only valid if central_log_mode is set to \"file\".") do |file| ["central_log_file"] = file end opts.on("-t", "--timeout TIMEOUT", OptionParser::DecimalInteger, "Timeout (in seconds) after which the script is killed.") do |timeout| ["timeout"] = timeout end opts.on("-a", "--[no-]job_log_prepend_date_time", "Whether to prepend the date/time to each line of the job log file.") do |value| ["job_log_prepend_date_time"] = value end opts.on("-g", "--job_log_prepend_date_time_format FORMAT", "The format of the date/time to be prepended to each line of the job log file.") do |format| ["job_log_prepend_date_time_format"] = format end opts.on("-b", "--[no-]rotate_job_log", "Whether the job log file should be rotated.") do |value| ["rotate_job_log"] = value end opts.on("-e", "--email_settings_file PATH", "The configuration file for the simpleemail gem.", "Note: If a relative path is specified, it will be considered to be relative to the", "location of the configuration file.") do |file| ["email_settings_file"] = file end opts.on("-o", "--email_from_address ADDRESS", "The email address from which jobmanager sends results.") do |address| ["email_from_address"] = address end opts.on("-u", "--email_to_address ADDRESS", "The email address to which jobmanager sends results.") do |address| ["email_to_address"] = address end opts.on("-p", "--command_path PATH", "The path to search for the command that jobmanager is invoked with.") do |path| ["command_path"] = path end opts.on("-s", "--email_subject SUBJECT", "The email subject, to be interpreted by ERB.", "Allowed variables: (job_name, command, host_name, result, user_name)") do |subject| ["email_subject"] = subject end opts.on_tail("-d", "--[no-]debug", "Turn on/off debug trace.") do |value| ["debug"] = value end opts.on_tail("-h", "--help", "Show this message.") do puts opts, "\n" exit(0) end opts.parse!(args) if (args.length != 1) puts opts, "\n" raise ArgumentError, "One argument (command) is required!" end ["command"] = args.shift() if (!is_job_name_set) exe = ["command"].split(' ')[0] ["job_name"] = File.basename(exe) end end |