Sha256: c17ee40f8ad70e664f461f8203fb4a099a3b5b35e5fed5dab7734b4faff27c34
Contents?: true
Size: 1.33 KB
Versions: 2
Compression:
Stored size: 1.33 KB
Contents
require 'scmd' module CapUtil def self.run_locally(cmd_str) cmd = Scmd.new(cmd_str) say_bulleted "running `#{cmd}'" cmd.run say_error(cmd.stderr) if !cmd.success? cmd end def self.run_locally_with_stdin(cmd_str, input) cmd = Scmd.new(cmd_str) say_bulleted "running `#{cmd}'" cmd.run(input) say_error(cmd.stderr) if !cmd.success? cmd end module Run def self.included(receiver) receiver.send(:extend, RunLocalMethods) receiver.send(:include, RunLocalMethods) receiver.send(:include, InstanceMethods) end module RunLocalMethods def run_locally(*args); CapUtil.run_locally(*args); end def run_locally_with_stdin(*args); CapUtil.run_locally_with_stdin(*args); end end module InstanceMethods def run(*args, &block) cap.run(*args, &block) end def run_with_stdin(cmd_str, input, opts={}) run(cmd_str, opts.merge(:pty => true)) {|ch, stream, out| ch.send_data(input + "\n")} end def run_as(user, cmd_str, opts={}, &block) as_cmd_str = "su #{user} -lc '#{cmd_str.gsub("'", "\\'")}'" run(as_cmd_str, opts, &block) end def run_as_with_stdin(user, cmd_str, input, opts={}) run_as(user, cmd_str, opts) {|ch, stream, out| ch.send_data(input + "\n")} end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
cap-util-0.4.0 | lib/cap-util/run.rb |
cap-util-0.3.0 | lib/cap-util/run.rb |