lib/backticks/runner.rb in backticks-1.0.0rc1 vs lib/backticks/runner.rb in backticks-1.0.0rc2
- old
+ new
@@ -22,23 +22,27 @@
attr_accessor :interactive
# List of I/O streams that should be captured using a pipe instead of
# a pseudoterminal.
#
- # This may be a Boolean, or it may be an Array of stream names from the
- # set [:stdin, :stdout, :stderr].
+ # When read, this attribute is always an Array of stream names from the
+ # set `[:stdin, :stdout, :stderr]`.
#
- # Note: if you set `interactive` to true, then stdin and stdout will be
+ # **Note**: if you set `interactive` to true, then stdin and stdout are
# unbuffered regardless of how you have set `buffered`!
#
# @return [Array] list of symbolic stream names
attr_reader :buffered
+ # @return [String,nil] PWD for new child processes, default is Dir.pwd
+ attr_accessor :chdir
+
# @return [#parameters] the CLI-translation object used by this runner
attr_reader :cli
# Create an instance of Runner.
+ #
# @option [#include?,Boolean] buffered list of names; true/false for all/none
# @option [#parameters] cli command-line parameter translator
# @option [Boolean] interactive true to tie parent stdout/stdin to child
#
# @example buffer stdout
@@ -53,10 +57,17 @@
@cli = options[:cli]
self.buffered = options[:buffered]
self.interactive = options[:interactive]
end
+ # Control which streams are buffered (i.e. use a pipe) and which are
+ # unbuffered (i.e. use a pseudo-TTY).
+ #
+ # If you pass a Boolean argument, it is converted to an Array; therefore,
+ # the reader for this attribute always returns a list even if you wrote
+ # a boolean value.
+ #
# @param [Array,Boolean] buffered list of symbolic stream names; true/false for all/none
def buffered=(b)
@buffered = case b
when true then BUFFERED
when false, nil then []
@@ -107,18 +118,19 @@
IO.pipe
else
PTY.open
end
- pid = spawn(*argv, in: stdin_r, out: stdout_w, err: stderr_w)
+ dir = @chdir || Dir.pwd
+ pid = spawn(*argv, in: stdin_r, out: stdout_w, err: stderr_w, chdir: dir)
stdin_r.close
stdout_w.close
stderr_w.close
unless interactive
stdin.close
stdin = nil
end
- Command.new(pid, stdin, stdout, stderr)
+ Command.new(pid, stdin, stdout, stderr, interactive:interactive)
end
end
end