Class: ZTK::Command

Inherits:
Base
  • Object
show all
Includes:
Download, Exec, Private, Upload
Defined in:
lib/ztk/command.rb,
lib/ztk/command/exec.rb,
lib/ztk/command/upload.rb,
lib/ztk/command/private.rb,
lib/ztk/command/download.rb

Overview

Command Execution Class

Examples:

We can get a new instance of Command like so:


cmd = ZTK::Command.new

Run a command and redirect STDOUT and STDERR to a StringIO


std_combo = StringIO.new
ui = ZTK::UI.new(:stdout => std_combo, :stderr => std_combo)
cmd = ZTK::Command.new(:ui => ui, :silence => true)
puts cmd.exec("hostname", :silence => false).inspect

Author:

Defined Under Namespace

Modules: Download, Exec, Private, Upload

Instance Method Summary (collapse)

Methods included from Private

#log_header, #tag

Methods included from Upload

#upload

Methods included from Exec

#exec

Methods included from Download

#download

Methods inherited from Base

build_config, #config, #direct_log, hash_config, log_and_raise, #log_and_raise

Constructor Details

- (Command) initialize(configuration = {})

Returns a new instance of Command

Parameters:

  • configuration (Hash) (defaults to: {})

    Sets the overall default configuration for the class. For example, all calls to exec against this instance will use the configuration options specified here by default. These options can be overriden on a per call basis as well.

Options Hash (configuration):

  • :timeout (Integer) — default: 600

    How long in seconds before the command will timeout.

  • :ignore_exit_status (Boolean) — default: false

    Whether or not we should ignore the exit status of the the process we spawn. By default we do not ignore the exit status and throw an exception if it is non-zero.

  • :exit_code (Integer) — default: 0

    The exit code we expect the process to return. This is ignore if ignore_exit_status is true.

  • :silence (Boolean) — default: false

    Whether or not we should squelch the output of the process. The output will always go to the logging device supplied in the ZTK::UI object. The output is always available in the return value from the method additionally.



52
53
54
55
56
57
58
59
# File 'lib/ztk/command.rb', line 52

def initialize(configuration={})
  super({
    :timeout => 600,
    :ignore_exit_status => false,
    :exit_code => 0,
    :silence => false
  }, configuration)
end