Skip to content

Setting Contexts

mosop edited this page Jan 28, 2017 · 4 revisions

The context is a main concept in this library. A context has several attributes, command names, arguments, working directories..., etc.

Contexts can be nested. For example, you can separately configure a base directory and relative directories to the base directory.

cmd = Run::Command.new(chdir: "/path/to/base")
cmd.run "pwd", chdir: "relative" # => prints "/path/to/base/relative"
cmd.run "pwd", chdir: "../sibling" # => prints "/path/to/sibling"
cmd.run "pwd", chdir: "/path/to/absolute" # => prints "/path/to/absolute"

You can set nested contexts using command groups, ad infinitum.

cg = Run::CommandGroup.new(chdir: "/path/to/base") do |g|
  g.group(chdir: "foo") do |g|
    g.group(chdir: "bar") do |g|
      g.group(chdir: "baz") do |g|
        # ...
      end
    end
  end
end
Clone this wiki locally