cmds 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 60b5fda411ade202d896d087b4104e4db35c3429
4
- data.tar.gz: 4bffbff9d0590beb514ace34ab9bf5c1728b6f81
3
+ metadata.gz: 319129e56b13805451ef585ce44e9aef1029df19
4
+ data.tar.gz: dab4a172aa3f8dcee5f7d73b86b797cccd3e51c6
5
5
  SHA512:
6
- metadata.gz: 0e4a2812bce9c3614664ca89da4145e1fdf01cc4db396095a964af7f9c4a95576dd1b28e209063484aea690b97b011b6e26461dbe3646dcb5907e823615def01
7
- data.tar.gz: 03a78326ea5c2dbd4789513cdcd3b2bf3d94b0b9e6c6b9e3391f61f644a5c155769ea024ca2cc8074998900059719444eaa7bd671ae114c7783c1edd885cd4e7
6
+ metadata.gz: 321c3539eb6b193c3226426aeedeb4cd61088335c20bc247193f7c1b89bd45a9cf20e9f2da88826dd8627dfa15a67632a07e4770107990c01d43a8b9a475d738
7
+ data.tar.gz: 8ac9702dda8dca0f53e1f1f80a64c73ac246d4763d23227ecb3605f82d81a1a74208f64dc83bc97b22990fa6cb572419239abc301af8d4e28f45ae9a3f220544
data/lib/cmds/cmd.rb CHANGED
@@ -79,6 +79,12 @@ module Cmds
79
79
  attr_reader :format
80
80
 
81
81
 
82
+ # directory to run the command in.
83
+ #
84
+ # @return [nil | String]
85
+ attr_reader :chdir
86
+
87
+
82
88
  # construct a Cmd.
83
89
  #
84
90
  # @param [String] template
@@ -101,6 +107,9 @@ module Cmds
101
107
  # @option opts [:squish, :pretty] :format
102
108
  # sets the {#format} attribute.
103
109
  #
110
+ # @option opts [nil | String] :chdir
111
+ # sets the {#chdir} attribute.
112
+ #
104
113
  def initialize template, **opts
105
114
  Cmds.debug "Cmd constructing...",
106
115
  template: template,
@@ -114,6 +123,7 @@ module Cmds
114
123
  @env = opts[:env] || {}
115
124
  @format = opts[:format] || :squish
116
125
  @env_mode = opts[:env_mode] || :inline
126
+ @chdir = opts[:chdir] || nil
117
127
  end # #initialize
118
128
 
119
129
 
@@ -126,6 +136,7 @@ module Cmds
126
136
  assert: @assert,
127
137
  env: @env,
128
138
  format: @format,
139
+ chdir: @chdir,
129
140
  }
130
141
  end
131
142
 
@@ -180,9 +191,10 @@ module Cmds
180
191
  io_block: io_block
181
192
 
182
193
  Cmds.spawn prepare(*args, **kwds),
183
- @input,
194
+ input: @input,
184
195
  # include env if mode is spawn argument
185
- (@env_mode == :spawn_arg ? @env : {}),
196
+ env: (@env_mode == :spawn_arg ? @env : {}),
197
+ chdir: @chdir,
186
198
  &io_block
187
199
  end # #stream
188
200
 
@@ -230,10 +242,9 @@ module Cmds
230
242
 
231
243
  status = Cmds.spawn(
232
244
  cmd,
233
- # we deal with input in the block
234
- nil,
235
245
  # include env if mode is spawn argument
236
- (@env_mode == :spawn_arg ? @env : {}),
246
+ env: (@env_mode == :spawn_arg ? @env : {}),
247
+ chdir: @chdir
237
248
  ) do |io|
238
249
  # send the input to stream, which sends it to spawn
239
250
  io.in = input
data/lib/cmds/spawn.rb CHANGED
@@ -45,11 +45,15 @@ module Cmds
45
45
  # @raise [ArgumentError]
46
46
  # if `&io_block` has arity greater than 1.
47
47
  #
48
- def self.spawn cmd, input = nil, env = {}, &io_block
49
- Cmds.debug "entering Cmds#really_stream",
48
+ def self.spawn cmd, **opts, &io_block
49
+ Cmds.debug "entering Cmds#spawn",
50
50
  cmd: cmd,
51
- input: input,
51
+ opts: opts,
52
52
  io_block: io_block
53
+
54
+ env = opts[:env] || {}
55
+ input = opts[:input]
56
+ chdir = opts[:chdir]
53
57
 
54
58
  # create the handler that will be yielded to the input block
55
59
  handler = Cmds::IOHandler.new
@@ -80,6 +84,9 @@ module Cmds
80
84
 
81
85
  # hash of options that will be passed to `spawn`
82
86
  spawn_opts = {}
87
+
88
+ # add chdir if provided
89
+ spawn_opts[:chdir] = chdir if chdir
83
90
 
84
91
  Cmds.debug "looking at input...",
85
92
  input: input
data/lib/cmds/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Cmds
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -1,18 +1,20 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe "Cmds ENV vars" do
4
+ r_echo_cmd = %{ruby -e "puts ENV['BLAH']"}
5
+
4
6
  it "sets basic (path-like) string ENV var" do
5
- cmd = Cmds::Cmd.new 'echo "${BLAH}"', env: {BLAH: "x:y:z"}
7
+ cmd = Cmds::Cmd.new r_echo_cmd, env: {BLAH: "x:y:z"}
6
8
  expect(cmd.chomp!).to eq "x:y:z"
7
9
  end
8
10
 
9
11
  it "sets a string with spaces in it correctly" do
10
- cmd = Cmds::Cmd.new 'echo "${BLAH}"', env: {BLAH: "hey there"}
12
+ cmd = Cmds::Cmd.new r_echo_cmd, env: {BLAH: "hey there"}
11
13
  expect(cmd.chomp!).to eq "hey there"
12
14
  end
13
15
 
14
16
  it "accepts string keys" do
15
- cmd = Cmds::Cmd.new 'echo "${BLAH}"', env: {
17
+ cmd = Cmds::Cmd.new r_echo_cmd, env: {
16
18
  'BLAH' => [
17
19
  "/usr/local/bin",
18
20
  "/usr/bin",
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cmds
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - nrser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-04 00:00:00.000000000 Z
11
+ date: 2017-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nrser