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

Instance Method Details

#delete(*files, run: true, show_errors: false, fatal_errors: true) ⇒ Boolean

Deletes a list of files.

Parameters:

  • files (Array)

    The list of files to remove

  • run (Boolean)

    If false, it will just print a list of message that would be deleted.

  • show_errors (Boolean)

    If show errors.

  • fatal_errors (Boolean)

    If quit in case of fatal errors.

Returns:

  • (Boolean)

    true if operation succeeded, false otherwise.



330
331
332
333
334
335
336
337
338
339
340
341
# 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) ⇒ Hash

Runs a command into the shell.

Parameters:

  • command (String)

    The string to run.

  • message (String) (defaults to: nil)

    A message to show before running.

  • run (Boolean)

    If false, it will just print a message with the full command that will be run.

  • show_exit (Boolean)

    If show the exit status.

  • show_output (Boolean)

    If show command output.

  • show_command (Boolean)

    If show the command that will be run.

  • fatal_errors (Boolean)

    If quit in case of fatal errors.

Returns:

  • (Hash)

    An hash with status and output keys.



305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
# 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