Project

dotanuki

0.0
No commit activity in last 3 years
No release in over 3 years
A command executioner which doesn't blindly stumble on when a command fails'
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

~> 0.3.6
 Project Readme

Dotanuki

Simple but effective executioner of commands, which will deal correctly with failed commands.

There are two versions of the Dotanuki gem dotanuki which uses posix-spawn and a pure ruby version dotanuki-ruby which uses open4 instead.

Note that if the pure ruby version can load posix-spawn it will use it.

Examples

In the following example, if the mkdir fails, none of the other commands will be executed.

  require "dotanuki"

  class Example
    include Dotanuki

    def test
      commands = [
        "mkdir /tmp/foo",
        "cp /etc/hosts /tmp/foo",
        "cp /etc/passwd /tmp/foo"
      ]

      result = execute(commands)
      if result.failed?
        puts "execution failed: #{result.fail_message}"
      end
    end
  end

It can also be used with a guard block, which will raise an ExecError if a command fails.

  require "dotanuki"

  class Example
    include Dotanuki

    def test
      guard do
        execute "mkdir /tmp/foo"
        execute "cp /etc/hosts /tmp/foo"
        execute "cp /etc/passwd /tmp/foo"
      end
    end
  end

If you want to use dotanuki in a class method, you have to use the module method

  require "dotanuki"

  class Example
    def self.test?
      Dotanuki.execute("mkdir /tmp/foo").ok?
    end
  end