module Bovem::ShellMethods::Execute

Methods to run commands or delete entries.

Public Instance Methods

delete(*files, run: true, show_errors: false, fatal_errors: true) click to toggle source

Deletes a list of files.

@param files [Array] The list of files to remove @param run [Boolean] If `false`, it will just print a list of message that would be deleted. @param show_errors [Boolean] If show errors. @param fatal_errors [Boolean] If quit in case of fatal errors. @return [Boolean] `true` if operation succeeded, `false` otherwise.

# File lib/bovem/shell.rb, line 330
def delete(*files, run: true, show_errors: false, fatal_errors: true)
  rv = true
  files = files.ensure_array(no_duplicates: true, compact: true, flatten: true) { |f| File.expand_path(f.ensure_string) }

  if !run
    show_dry_delete(files)
  else
    rv = perform_delete(files, show_errors, fatal_errors)
  end

  rv
end
run(command, message = nil, run: true, show_exit: true, show_output: false, show_command: false, fatal_errors: true) click to toggle source

Runs a command into the shell.

@param command [String] The string to run. @param message [String] A message to show before running. @param run [Boolean] If `false`, it will just print a message with the full command that will be run. @param show_exit [Boolean] If show the exit status. @param show_output [Boolean] If show command output. @param show_command [Boolean] If show the command that will be run. @param fatal_errors [Boolean] If quit in case of fatal errors. @return [Hash] An hash with `status` and `output` keys.

# File lib/bovem/shell.rb, line 305
def run(command, message = nil, run: true, show_exit: true, show_output: false, show_command: false, fatal_errors: true)
  rv = {status: 0, output: ""}
  command = command.ensure_string

  # Show the command
  @console.begin(message) if message.present?

  if !run # Print a message
    show_dry_run(command, show_exit)
  else # Run
    rv = execute_command(command, show_command, show_output)
  end

  # Return
  handle_command_exit(rv, show_exit, fatal_errors)
  rv
end