Module: Bovem::ShellMethods::Execute
- Included in:
- Bovem::Shell
- Defined in:
- lib/bovem/shell.rb
Overview
Methods to run commands or delete entries.
Instance Method Summary (collapse)
-
- (Boolean) delete(files, run = true, show_errors = false, fatal = true)
Deletes a list of files.
-
- (Hash) run(command, message = nil, run = true, show_exit = true, show_output = false, show_command = false, fatal = true)
Runs a command into the shell.
Instance Method Details
- (Boolean) delete(files, run = true, show_errors = false, fatal = true)
Deletes a list of files.
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 |
# File 'lib/bovem/shell.rb', line 375 def delete(files, run = true, show_errors = false, fatal = true) rv = true locale = self.i18n.shell files = files.ensure_array.compact.collect {|f| File.(f.ensure_string) } if !run then @console.warn(locale.remove_dry) @console.with_indentation(11) do files.each do |file| @console.write(file) end end else rv = catch(:rv) do begin FileUtils.rm_r(files, {noop: false, verbose: false, secure: true}) throw(:rv, true) rescue => e handle_failure(e, :remove_unwritable, :remove_not_found, :remove_error, files, fatal, show_errors) end false end end rv end |
- (Hash) run(command, message = nil, run = true, show_exit = true, show_output = false, show_command = false, fatal = true)
Runs a command into the shell.
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 |
# File 'lib/bovem/shell.rb', line 347 def run(command, = nil, run = true, show_exit = true, show_output = false, show_command = false, fatal = true) rv = {status: 0, output: ""} command = command.ensure_string locale = self.i18n.shell # Show the command @console.begin() if .present? if !run then # Print a message @console.warn(locale.run_dry(command)) @console.status(:ok) if show_exit else # Run rv = execute_command(command, show_command, show_output) end # Return @console.status(rv[:status] == 0 ? :ok : :fail) if show_exit exit(rv[:status]) if fatal && rv[:status] != 0 rv end |