Module: FerretsOnFire::DSL::ShellDSL

Included in:
FerretsOnFire::DSL
Defined in:
lib/ferrets_on_fire/dsl/shell_dsl.rb

Instance Method Summary collapse

Instance Method Details

#bundle(dir: nil) ⇒ Object



2
3
4
5
6
7
8
9
10
# File 'lib/ferrets_on_fire/dsl/shell_dsl.rb', line 2

public def bundle(dir: nil)
  # Set bundler parallel jobs count
  if run('sysctl -n hw.ncpu', quiet: true, return_exit_code: true).zero?
    number_of_cores = run('sysctl -n hw.ncpu', quiet: true).strip.to_i - 1
    run("bundle config --global jobs #{number_of_cores}", quiet: true)
  end

  run 'bundle', dir: dir, as: 'bundler'
end

#run(cmd, dir: nil, exit_on_failure: true, quiet: false, return_exit_code: false, as: nil, bundler: false, rails_env: nil) ⇒ String

Runs a shell command. Stderr is redirected to Stdout

Parameters:

  • cmd (String)

    Command to run

  • dir (String) (defaults to: nil)

    Directory to run the command in

  • exit_on_failure (Boolean) (defaults to: true)

    Optional (default: true). If true, the script will exited if the command fails

  • quiet (Boolean) (defaults to: false)

    Optional (default: true). If true, the command is not printed

  • return_exit_code (Boolean) (defaults to: false)

    Optional (default: false). If true, the exit code is returned instead of the output

  • as (String) (defaults to: nil)

    Optional. Label for the action output (instead of the command)

  • bundler (Boolean) (defaults to: false)

    Optional. Run with ‘bundle exec`?

  • rails_env (Symbol) (defaults to: nil)

    Optional. Set RAILS_ENV.

Returns:

  • (String)

    Stdout or exit code



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/ferrets_on_fire/dsl/shell_dsl.rb', line 24

public def run(cmd, dir: nil, exit_on_failure: true, quiet: false, return_exit_code: false, as: nil, bundler: false,
               rails_env: nil)

  # Build complete command
  cmd = build_command(cmd, dir, rails_env, bundler)

  # Run the command and print the output if wished
  output, status = execute_shell_cmd(cmd, quiet, as)

  # Error handling
  if status.nonzero? && return_exit_code == false
    crash "Shell command exited with status code #{status}!", output, command: cmd, exit: exit_on_failure
  end

  return_exit_code ? status : output
end