Class: Bricolage::GlobalOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/bricolage/application.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ GlobalOptions

Returns a new instance of GlobalOptions.



143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/bricolage/application.rb', line 143

def initialize(app)
  @app = app
  @job_file = nil
  @environment = nil
  @home = nil
  @global_variables = Variables.new
  @dry_run = false
  @explain = false
  @list_global_variables = false
  @list_variables = false
  @list_declarations = false
  @parser = OptionParser.new
  define_options @parser
end

Instance Attribute Details

#environmentObject (readonly)

Returns the value of attribute environment.



229
230
231
# File 'lib/bricolage/application.rb', line 229

def environment
  @environment
end

#global_variablesObject (readonly)

Returns the value of attribute global_variables.



231
232
233
# File 'lib/bricolage/application.rb', line 231

def global_variables
  @global_variables
end

#homeObject (readonly)

Returns the value of attribute home.



230
231
232
# File 'lib/bricolage/application.rb', line 230

def home
  @home
end

#job_fileObject (readonly)

Returns the value of attribute job_file.



233
234
235
# File 'lib/bricolage/application.rb', line 233

def job_file
  @job_file
end

#parserObject (readonly)

Returns the value of attribute parser.



158
159
160
# File 'lib/bricolage/application.rb', line 158

def parser
  @parser
end

Instance Method Details

#define_options(parser) ⇒ Object



164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# File 'lib/bricolage/application.rb', line 164

def define_options(parser)
  parser.banner = "Synopsis:\n  \#{@app.program_name} [global_options] JOB_CLASS [job_options]\n  \#{@app.program_name} [global_options] --job=JOB_FILE -- [job_options]\nGlobal Options:\n  EndBanner\n  parser.on('-f', '--job=JOB_FILE', 'Give job parameters via job file (YAML).') {|path|\n    @job_file = path\n  }\n  parser.on('-e', '--environment=NAME', \"Sets execution environment [default: \#{Context::DEFAULT_ENV}]\") {|env|\n    @environment = env\n  }\n  parser.on('-C', '--home=PATH', 'Sets application home directory.') {|path|\n    @home = Pathname(path)\n  }\n  parser.on('-n', '--dry-run', 'Shows job script without executing it.') {\n    @dry_run = true\n  }\n  parser.on('-E', '--explain', 'Applies EXPLAIN to the SQL.') {\n    @explain = true\n  }\n  parser.on('--list-job-class', 'Lists job class name and (internal) class path.') {\n    JobClass.list.each do |name|\n      puts name\n    end\n    exit 0\n  }\n  parser.on('--list-global-variables', 'Lists global variables.') {\n    @list_global_variables = true\n  }\n  parser.on('--list-variables', 'Lists all variables.') {\n    @list_variables = true\n  }\n  parser.on('--list-declarations', 'Lists script variable declarations.') {\n    @list_declarations = true\n  }\n  parser.on('-r', '--require=FEATURE', 'Requires ruby library.') {|feature|\n    require feature\n  }\n  parser.on('-v', '--variable=NAME=VALUE', 'Set global variable (is different from job-level -v !!).') {|name_value|\n    name, value = name_value.split('=', 2)\n    @global_variables[name] = value\n  }\n  parser.on('--help', 'Shows this message and quit.') {\n    puts parser.help\n    exit 0\n  }\n  parser.on('--version', 'Shows program version and quit.') {\n    puts \"\#{APPLICATION_NAME} version \#{VERSION}\"\n    exit 0\n  }\nend\n"

#dry_run?Boolean

Returns:

  • (Boolean)


239
240
241
# File 'lib/bricolage/application.rb', line 239

def dry_run?
  @dry_run
end

#explain?Boolean

Returns:

  • (Boolean)


243
244
245
# File 'lib/bricolage/application.rb', line 243

def explain?
  @explain
end

#file_mode?Boolean

Returns:

  • (Boolean)


235
236
237
# File 'lib/bricolage/application.rb', line 235

def file_mode?
  !!@job_file
end

#helpObject



160
161
162
# File 'lib/bricolage/application.rb', line 160

def help
  @parser.help
end

#list_declarations?Boolean

Returns:

  • (Boolean)


255
256
257
# File 'lib/bricolage/application.rb', line 255

def list_declarations?
  @list_declarations
end

#list_global_variables?Boolean

Returns:

  • (Boolean)


247
248
249
# File 'lib/bricolage/application.rb', line 247

def list_global_variables?
  @list_global_variables
end

#list_variables?Boolean

Returns:

  • (Boolean)


251
252
253
# File 'lib/bricolage/application.rb', line 251

def list_variables?
  @list_variables
end

#on(*args, &block) ⇒ Object



218
219
220
# File 'lib/bricolage/application.rb', line 218

def on(*args, &block)
  @parser.on(*args, &block)
end

#parse(argv) ⇒ Object



222
223
224
225
226
227
# File 'lib/bricolage/application.rb', line 222

def parse(argv)
  @parser.order! argv
  @rest_args = argv.dup
rescue OptionParser::ParseError => ex
  raise OptionError, ex.message
end