cmds 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +9 -1
- data/lib/cmds/cmd.rb +3 -3
- data/lib/cmds/spawn.rb +8 -2
- data/lib/cmds/util.rb +1 -1
- data/lib/cmds/version.rb +1 -1
- data/spec/cmds/curry_spec.rb +1 -1
- data/spec/cmds/env_spec.rb +24 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f2767abdf674497cad3cfc8913da88fddcf6cbc
|
4
|
+
data.tar.gz: cd2458c8f02672b9e66d060557e7b996cfc1c8dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 52d88272291712ae57550d0822ae406d9723433866116a2f2802ac65c34423366eef8d1aeb6cb5e6aa778d46abaac3ed830fb96e1060e023f475b9bb4ac86727
|
7
|
+
data.tar.gz: c1125b57ebc1036bec4480bf7b3db332ed75305b65c73933e738a400e85892a0b9dafbb4fe49790042d053f14f4b2ab541e48ec631f80952afca81a744b1ba9e
|
data/.gitignore
CHANGED
@@ -16,4 +16,12 @@ test/tmp
|
|
16
16
|
test/version_tmp
|
17
17
|
tmp
|
18
18
|
|
19
|
-
ref/repos
|
19
|
+
ref/repos
|
20
|
+
##############################################################################
|
21
|
+
# BEGIN Qb.gitingore
|
22
|
+
#
|
23
|
+
# generated qb playbooks
|
24
|
+
.qb-playbook.yml
|
25
|
+
#
|
26
|
+
# END Qb.gitingore
|
27
|
+
##############################################################################
|
data/lib/cmds/cmd.rb
CHANGED
@@ -59,7 +59,7 @@ module Cmds
|
|
59
59
|
#
|
60
60
|
# defaults to `{}`.
|
61
61
|
#
|
62
|
-
# @return [Hash{Symbol => String}]
|
62
|
+
# @return [Hash{String | Symbol => String}]
|
63
63
|
attr_reader :env
|
64
64
|
|
65
65
|
# format specifier symbol:
|
@@ -165,7 +165,7 @@ module Cmds
|
|
165
165
|
kwds: kwds,
|
166
166
|
io_block: io_block
|
167
167
|
|
168
|
-
Cmds.spawn prepare(*args, **kwds), @input, &io_block
|
168
|
+
Cmds.spawn prepare(*args, **kwds), @input, @env, &io_block
|
169
169
|
end # #stream
|
170
170
|
|
171
171
|
|
@@ -210,7 +210,7 @@ module Cmds
|
|
210
210
|
|
211
211
|
Cmds.debug "calling Cmds.spawn..."
|
212
212
|
|
213
|
-
status = Cmds.spawn cmd do |io|
|
213
|
+
status = Cmds.spawn cmd, nil, @env do |io|
|
214
214
|
# send the input to stream, which sends it to spawn
|
215
215
|
io.in = input
|
216
216
|
|
data/lib/cmds/spawn.rb
CHANGED
@@ -29,6 +29,9 @@ module Cmds
|
|
29
29
|
# string or readable input. here so that Cmds instances can pass their
|
30
30
|
# `@input` instance variable -- `&io_block` overrides it.
|
31
31
|
#
|
32
|
+
# @param [Hash{Symbol | String => Object}] env
|
33
|
+
# blah
|
34
|
+
#
|
32
35
|
# @param [#call & (#arity ∈ {0, 1})] &io_block
|
33
36
|
# optional block to handle io. behavior depends on arity:
|
34
37
|
#
|
@@ -42,7 +45,7 @@ module Cmds
|
|
42
45
|
# @raise [ArgumentError]
|
43
46
|
# if `&io_block` has arity greater than 1.
|
44
47
|
#
|
45
|
-
def self.spawn cmd, input = nil, &io_block
|
48
|
+
def self.spawn cmd, input = nil, env = {}, &io_block
|
46
49
|
Cmds.debug "entering Cmds#really_stream",
|
47
50
|
cmd: cmd,
|
48
51
|
input: input,
|
@@ -145,10 +148,13 @@ module Cmds
|
|
145
148
|
end # map outputs
|
146
149
|
|
147
150
|
Cmds.debug "spawning...",
|
151
|
+
env: env,
|
148
152
|
cmd: cmd,
|
149
153
|
opts: spawn_opts
|
150
154
|
|
151
|
-
pid = Process.spawn
|
155
|
+
pid = Process.spawn env.map {|k, v| [k.to_s, v]}.to_h,
|
156
|
+
cmd,
|
157
|
+
spawn_opts
|
152
158
|
|
153
159
|
Cmds.debug "spawned.",
|
154
160
|
pid: pid
|
data/lib/cmds/util.rb
CHANGED
data/lib/cmds/version.rb
CHANGED
data/spec/cmds/curry_spec.rb
CHANGED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Cmds ENV vars" do
|
4
|
+
it "sets basic (path-like) string ENV var" do
|
5
|
+
cmd = Cmds::Cmd.new 'echo "${BLAH}"', env: {BLAH: "x:y:z"}
|
6
|
+
expect(cmd.chomp!).to eq "x:y:z"
|
7
|
+
end
|
8
|
+
|
9
|
+
it "sets a string with spaces in it correctly" do
|
10
|
+
cmd = Cmds::Cmd.new 'echo "${BLAH}"', env: {BLAH: "hey there"}
|
11
|
+
expect(cmd.chomp!).to eq "hey there"
|
12
|
+
end
|
13
|
+
|
14
|
+
it "accepts string keys" do
|
15
|
+
cmd = Cmds::Cmd.new 'echo "${BLAH}"', env: {
|
16
|
+
'BLAH' => [
|
17
|
+
"/usr/local/bin",
|
18
|
+
"/usr/bin",
|
19
|
+
"/bin"
|
20
|
+
].join(':')
|
21
|
+
}
|
22
|
+
expect(cmd.chomp!).to eq "/usr/local/bin:/usr/bin:/bin"
|
23
|
+
end
|
24
|
+
end
|
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.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nrser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03
|
11
|
+
date: 2017-04-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nrser
|
@@ -164,6 +164,7 @@ files:
|
|
164
164
|
- spec/cmds/capture_spec.rb
|
165
165
|
- spec/cmds/chomp_spec.rb
|
166
166
|
- spec/cmds/curry_spec.rb
|
167
|
+
- spec/cmds/env_spec.rb
|
167
168
|
- spec/cmds/erb_context_spec.rb
|
168
169
|
- spec/cmds/err_spec.rb
|
169
170
|
- spec/cmds/error_spec.rb
|
@@ -210,6 +211,7 @@ test_files:
|
|
210
211
|
- spec/cmds/capture_spec.rb
|
211
212
|
- spec/cmds/chomp_spec.rb
|
212
213
|
- spec/cmds/curry_spec.rb
|
214
|
+
- spec/cmds/env_spec.rb
|
213
215
|
- spec/cmds/erb_context_spec.rb
|
214
216
|
- spec/cmds/err_spec.rb
|
215
217
|
- spec/cmds/error_spec.rb
|