Skip to content

Commit

Permalink
fix rdoc formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsdeleo committed Jul 31, 2010
1 parent 2209933 commit 94fa817
Showing 1 changed file with 38 additions and 14 deletions.
52 changes: 38 additions & 14 deletions chef/lib/chef/shell_out.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Chef
# way to inspect the output of the command as it is being read. If you need
# to do that, you have to use popen4 (in Chef::Mixin::Command)
#
# == Platform Support
# === Platform Support
# Chef::ShellOut uses Kernel.fork() and is therefore unsuitable for Windows
# or jruby.
class ShellOut
Expand All @@ -59,23 +59,38 @@ class ShellOut
# === Options:
# If the last argument is a Hash, it is removed from the list of args passed
# to exec and used as an options hash. The following options are available:
# * user: the user the commmand should run as. if an integer is given, it is
# * user::: the user the commmand should run as. if an integer is given, it is
# used as a uid. A string is treated as a username and resolved to a uid
# with Etc.getpwnam
# * group: the group the command should run as. works similarly to +user+
# * group::: the group the command should run as. works similarly to +user+
# * cwd: the directory to chdir to before running the command
# * umask: a umask to set before running the command. If given as an Integer,
# * umask::: a umask to set before running the command. If given as an Integer,
# be sure to use two leading zeros so it's parsed as Octal. A string will
# be treated as an octal integer
# * returns: one or more Integer values to use as valid exit codes for the
# * returns::: one or more Integer values to use as valid exit codes for the
# subprocess. This only has an effect if you call +error!+ after
# +run_command+.
# * environment: a Hash of environment variables to set before the command
# * environment::: a Hash of environment variables to set before the command
# is run. By default, the environment will *always* be set to 'LC_ALL' => 'C'
# to prevent issues with multibyte characters in Ruby 1.8. To avoid this,
# use :environment => nil for *no* extra environment settings, or
# :environment => {'LC_ALL'=>nil, ...} to set other environment settings
# without changing the locale.
# * timeout::: a Numeric value for the number of seconds to wait on the
# child process before raising an Exception. This is calculated as the
# total amount of time that ShellOut waited on the child process without
# receiving any output (i.e., IO.select returned nil). Default is 60
# seconds. Note: the stdlib Timeout library is not used.
# === Examples:
# Invoke find(1) to search for .rb files:
# find = Chef::ShellOut.new("find . -name '*.rb'")
# find.run_command
# # If all went well, the results are on +stdout+
# puts find.stdout
# # find(1) prints diagnostic info to STDERR:
# puts "error messages" + find.stderr
# # Raise an exception if it didn't exit with 0
# find.error!
def initialize(*command_args)
@stdout, @stderr = '', ''
@environment = DEFAULT_ENVIRONMENT
Expand Down Expand Up @@ -107,6 +122,9 @@ def timeout
@timeout || DEFAULT_READ_TIMEOUT
end

# Creates a String showing the output of the command, including a banner
# showing the exact command executed. Used by +invalid!+ to show command
# results when the command exited with an unexpected status.
def format_for_exception
msg = ""
msg << "---- Begin output of #{command} ----\n"
Expand All @@ -127,11 +145,11 @@ def exitstatus
# returns +self+; +stdout+, +stderr+, +status+, and +exitstatus+ will be
# populated with results of the command
# === Raises
# * Errno::EACCES when you are not privileged to execute the command
# * Errno::ENOENT when the command is not available on the system (or not
# * Errno::EACCES::: when you are not privileged to execute the command
# * Errno::ENOENT::: when the command is not available on the system (or not
# in the current $PATH)
# * Chef::Exceptions::CommandTimeout when the command does not complete
# within +timeout+ seconds (default: 60s)
# * Chef::Exceptions::CommandTimeout::: when the command does not complete
# within +timeout+ seconds (default: 60s)
def run_command
Chef::Log.debug("sh(#{@command})")
@child_pid = fork_subprocess
Expand Down Expand Up @@ -185,6 +203,13 @@ def run_command
close_all_pipes
end

# Checks the +exitstatus+ against the set of +valid_exit_codes+. If
# +exitstatus+ is not in the list of +valid_exit_codes+, calls +invalid!+,
# which raises an Exception.
# === Returns
# nil::: always returns nil when it does not raise
# === Raises
# Chef::Exceptions::ShellCommandFailed::: via +invalid!+
def error!
unless Array(valid_exit_codes).include?(exitstatus)
invalid!("Expected process to exit 0, but it exited with #{exitstatus}")
Expand All @@ -194,9 +219,9 @@ def error!
# Raises a Chef::Exceptions::ShellCommandFailed exception, appending the
# command's stdout, stderr, and exitstatus to the exception message.
# === Arguments
# +msg+ A String to use as the basis of the exception message. The
# default explanation is very generic, providing a more
# informative message is highly encouraged.
# +msg+::: A String to use as the basis of the exception message. The
# default explanation is very generic, providing a more informative message
# is highly encouraged.
# === Raises
# Chef::Exceptions::ShellCommandFailed always
def invalid!(msg=nil)
Expand Down Expand Up @@ -281,7 +306,6 @@ def close_all_pipes
child_stdout.close unless child_stdout.closed?
child_stderr.close unless child_stderr.closed?
child_process_status.close unless child_process_status.closed?
#rescue NoMethodError # we blew up before IPC was setup
end

# replace stdout, and stderr with pipes to the parent, and close the
Expand Down

0 comments on commit 94fa817

Please sign in to comment.