Class RVM::Shell::AbstractWrapper
In: lib/rvm/shell/abstract_wrapper.rb
Parent: Object

Provides the most common functionality expected of a shell wrapper. Namely, implements general utility methods and tools to extract output from a given command but doesn‘t actually run any commands itself, leaving that up to concrete implementations.

Usage

Commands are run inside of a shell (usually bash) and can either be exectuted in two situations (each with wrapper methods available) - silently or verbosely.

Silent commands (via run_silently and run_command) do exactly as they say - that can modify the environment etc but anything they print (to stdout or stderr) will be discarded.

Verbose commands will run the command and then print the command epilog (which contains the output stastus and the current env in yaml format). This allows us to not only capture all output but to also return the exit status and environment variables in a way that makes persisted shell sessions possible.

Under the hood, run and run_silently are the preferred ways of invoking commands - if passed a single command, they‘ll run it as is (much like system in ruby) but when given multiple arguments anything after the first will be escaped (e.g. you can hence pass code etc). run will also parse the results of this epilog into a usable RVM::Shell::Result object.

run_command and run_command_silently do the actual hard work for these behind the scenes, running a string as the shell command. Hence, these two commands are what must be implemented in non-abstract wrappers.

For an example of the shell wrapper functionality in action, see RVM::Environment which delegates most of the work to a shell wrapper.

Methods

Included Modules

RVM::Shell::Utility

Constants

COMMAND_EPILOG_START = "---------------RVM-RESULTS-START---------------"   Used the mark the end of a commands output and the start of the rvm env.
COMMAND_EPILOG_END = "----------------RVM-RESULTS-END----------------"   Used to mark the end of the commands epilog.
WRAPPER_LOCATION = File.expand_path('./shell_wrapper.sh', File.dirname(__FILE__))   The location of the shell file with the epilog function definition.

Attributes

shell_executable  [R]  Defines the shell exectuable.

Public Class methods

Initializes a new shell wrapper, including setting the default setup block. Implementations must override this method but must ensure that they call super to perform the expected standard setup.

Public Instance methods

Returns a given environment variables’ value.

Runs the gives command (with optional arguments), returning an RVM::Shell::Result object, including stdout / stderr streams. Under the hood, uses run_command to actually process it all.

Given a command, it will execute it in the current wrapper and once done, will return:

  • the hash from the epilog output.
  • a string representing stdout.
  • a string representing stderr.

Like run_command, but doesn‘t care about output.

Wrapper around run_command_silently that correctly escapes arguments. Essentially, run but using run_command_silently.

Defines a setup block to be run when initiating a wrapper session. Usually used for doing things such as sourcing the rvm file. Please note that the wrapper file is automatically source.

The setup block should be automatically run by wrapper implementations.

Protected Instance methods

Checks whether the given command includes a epilog, marked by epilog start and end lines.

When called, will use the current environment to source the wrapper scripts as well as invoking the current setup block. as defined on initialization / via setup.

Takes a raw string from a processes STDIO and returns three things:

  1. The actual stdout, minus epilogue.
  2. YAML output of the process results.
  3. Any left over from the STDIO text.

Wraps a command in a way that it prints no output.

Uses run_silently to source the wrapper file.

Returns a command followed by the call to show the epilog.

[Validate]