cmds 0.1.5 → 0.2.0

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.
data/lib/cmds.rb CHANGED
@@ -1,3 +1,408 @@
1
+ # deps
2
+ require 'nrser'
3
+
4
+ # project
1
5
  require 'cmds/version'
2
- require 'cmds/cmd'
6
+ require 'cmds/debug'
7
+ require 'cmds/util'
8
+ require 'cmds/spawn'
9
+ require 'cmds/erb_context'
10
+ require 'cmds/shell_eruby'
11
+ require 'cmds/result'
3
12
  require 'cmds/sugar'
13
+
14
+ class Cmds
15
+ # ERB stirng template (with Cmds-specific extensions) for the command.
16
+ #
17
+ # @return [String]
18
+ attr_reader :template
19
+
20
+ # base/common positional parameters to render into the command
21
+ # template.
22
+ #
23
+ # defaults to `[]`.
24
+ #
25
+ # {#prepare} and the methods that invoke it (like {#capture},
26
+ # {#stream}, etc.) accept `*args`, which will be appended to
27
+ # these values to create the final array for rendering.
28
+ #
29
+ # @return [Array<Object>]
30
+ attr_reader :args
31
+
32
+ # base/common keyword parameters to render into the command template.
33
+ #
34
+ # defaults to `{}`.
35
+ #
36
+ # {#prepare} and the methods that invoke it (like {#capture},
37
+ # {#stream}, etc.) accept `**kwds`, which will be merged on top of
38
+ # these values to create the final hash for rendering.
39
+ #
40
+ # @return [Hash{Symbol => Object}]
41
+ attr_reader :kwds
42
+
43
+ # string or readable IO-like object to use as default input to the
44
+ # command.
45
+ #
46
+ # {#prepare} and the methods that invoke it (like {#capture},
47
+ # {#stream}, etc.) accept an optional block that will override this
48
+ # value if present.
49
+ #
50
+ # @return [String | #read]
51
+ attr_reader :input
52
+
53
+ # if `true`, will execution will raise an error on non-zero exit code.
54
+ #
55
+ # defaults to `false`.
56
+ #
57
+ # @return [Boolean]
58
+ attr_reader :assert
59
+
60
+ # environment variables to set for command execution.
61
+ #
62
+ # defaults to `{}`.
63
+ #
64
+ # @return [Hash{String | Symbol => String}]
65
+ attr_reader :env
66
+
67
+ # format specifier symbol:
68
+ #
69
+ # - `:squish`
70
+ # - collapse rendered command string to one line.
71
+ # - `:pretty`
72
+ # - clean up and backslash suffix line endings.
73
+ #
74
+ # defaults to `:squish`.
75
+ #
76
+ # @return [:squish | :pretty]
77
+ attr_reader :format
78
+
79
+
80
+ # directory to run the command in.
81
+ #
82
+ # @return [nil | String]
83
+ attr_reader :chdir
84
+
85
+
86
+ # construct a Cmd.
87
+ #
88
+ # @param [String] template
89
+ # sets the {#template} attribute.
90
+ #
91
+ # @param [Hash] opts
92
+ #
93
+ # @option opts [Array<Object>] :args
94
+ # sets the {#args} attribute.
95
+ #
96
+ # @option opts [Hash{Symbol => Object}] :kwds
97
+ # sets the {#kwds} attribute.
98
+ #
99
+ # @option opts [String | #read] :input
100
+ # sets the {#input} attribute.
101
+ #
102
+ # @option opts [Hash{Symbol => String}] :env
103
+ # sets the {#env} attribute.
104
+ #
105
+ # @option opts [:squish, :pretty] :format
106
+ # sets the {#format} attribute.
107
+ #
108
+ # @option opts [nil | String] :chdir
109
+ # sets the {#chdir} attribute.
110
+ #
111
+ def initialize template, **opts
112
+ Cmds.debug "Cmd constructing...",
113
+ template: template,
114
+ opts: opts
115
+
116
+ @template = template
117
+ @args = (opts[:args] || []).freeze
118
+ @kwds = (opts[:kwds] || {}).freeze
119
+ @input = opts[:input] || nil
120
+ @assert = opts[:assert] || false
121
+ @env = (opts[:env] || {}).freeze
122
+ @format = opts[:format] || :squish
123
+ @env_mode = opts[:env_mode] || :inline
124
+ @chdir = opts[:chdir] || nil
125
+ end # #initialize
126
+
127
+
128
+ # returns a new {Cmd} with the parameters and input merged in
129
+ def curry *args, **kwds, &input_block
130
+ self.class.new @template, {
131
+ args: (@args + args),
132
+ kwds: (@kwds.merge kwds),
133
+ input: (input ? input.call : @input),
134
+ assert: @assert,
135
+ env: @env,
136
+ format: @format,
137
+ chdir: @chdir,
138
+ }
139
+ end
140
+
141
+
142
+ # render parameters into `@template`.
143
+ #
144
+ # @note the returned string is **not** formatted for shell execution.
145
+ # Cmds passes this string through {Cmds.format} before execution,
146
+ # which addresses newlines in the rendered string through "squishing"
147
+ # everything down to one line or adding `\` to line ends.
148
+ #
149
+ # @param args (see #capture)
150
+ # @param kwds (see #capture)
151
+ #
152
+ # @return [String]
153
+ # the rendered command string.
154
+ #
155
+ def render *args, **kwds
156
+ context = Cmds::ERBContext.new((@args + args), @kwds.merge(kwds))
157
+ erb = Cmds::ShellEruby.new Cmds.replace_shortcuts(@template)
158
+ rendered = NRSER.dedent erb.result(context.get_binding)
159
+
160
+ if @env_mode == :inline && !@env.empty?
161
+ rendered = @env.sort_by {|name, value|
162
+ name
163
+ }.map {|name, value|
164
+ "#{ name }=#{ Cmds.esc value }"
165
+ }.join("\n\n") + "\n\n" + rendered
166
+ end
167
+
168
+ rendered
169
+ end
170
+
171
+
172
+ # prepare a shell-safe command string for execution.
173
+ #
174
+ # @param args (see #capture)
175
+ # @param kwds (see #capture)
176
+ #
177
+ # @return [String]
178
+ # the prepared command string.
179
+ #
180
+ def prepare *args, **kwds
181
+ Cmds.format render(*args, **kwds), @format
182
+ end # #prepare
183
+
184
+
185
+ def stream *args, **kwds, &io_block
186
+ Cmds.debug "entering Cmd#stream",
187
+ args: args,
188
+ kwds: kwds,
189
+ io_block: io_block
190
+
191
+ Cmds.spawn prepare(*args, **kwds),
192
+ input: @input,
193
+ # include env if mode is spawn argument
194
+ env: (@env_mode == :spawn_arg ? @env : {}),
195
+ chdir: @chdir,
196
+ &io_block
197
+ end # #stream
198
+
199
+
200
+ # executes the command and returns a {Cmds::Result} with the captured
201
+ # outputs.
202
+ #
203
+ # @param [Array<Object>] args
204
+ # positional parameters to append to those in `@args` for rendering
205
+ # into the command string.
206
+ #
207
+ # @param [Hash{Symbol => Object}] kwds
208
+ # keyword parameters that override those in `@kwds` for rendering
209
+ # into the command string.
210
+ #
211
+ # @param [#call] input_block
212
+ # optional block that returns a string or readable object to override
213
+ # `@input`.
214
+ #
215
+ # @return [Cmds::Result]
216
+ # result of execution with command string, status, stdout and stderr.
217
+ #
218
+ def capture *args, **kwds, &input_block
219
+ Cmds.debug "entering Cmds#capture",
220
+ args: args,
221
+ kwds: kwds,
222
+ input: input
223
+
224
+ # prepare the command string
225
+ cmd = prepare *args, **kwds
226
+
227
+ # extract input from block via `call` if one is provided,
228
+ # otherwise default to instance variable (which may be `nil`)
229
+ input = input_block.nil? ? @input : input_block.call
230
+
231
+ Cmds.debug "prepared",
232
+ cmd: cmd,
233
+ input: input
234
+
235
+ # strings output will be concatenated onto
236
+ out = ''
237
+ err = ''
238
+
239
+ Cmds.debug "calling Cmds.spawn..."
240
+
241
+ status = Cmds.spawn(
242
+ cmd,
243
+ # include env if mode is spawn argument
244
+ env: (@env_mode == :spawn_arg ? @env : {}),
245
+ chdir: @chdir
246
+ ) do |io|
247
+ # send the input to stream, which sends it to spawn
248
+ io.in = input
249
+
250
+ # and concat the output lines as they come in
251
+ io.on_out do |line|
252
+ out += line
253
+ end
254
+
255
+ io.on_err do |line|
256
+ err += line
257
+ end
258
+ end
259
+
260
+ Cmds.debug "Cmds.spawn completed",
261
+ status: status
262
+
263
+ # build a Result
264
+ # result = Cmds::Result.new cmd, status, out_reader.value, err_reader.value
265
+ result = Cmds::Result.new cmd, status, out, err
266
+
267
+ # tell the Result to assert if the Cmds has been told to, which will
268
+ # raise a SystemCallError with the exit status if it was non-zero
269
+ result.assert if @assert
270
+
271
+ return result
272
+ end # #capture
273
+
274
+
275
+ alias_method :call, :capture
276
+
277
+
278
+ # execute command and return `true` if it exited successfully.
279
+ #
280
+ # @param *args (see #capture)
281
+ # @param **kwds (see #capture)
282
+ # @param &input_block (see #capture)
283
+ #
284
+ # @return [Boolean]
285
+ # `true` if exit code was `0`.
286
+ #
287
+ def ok? *args, **kwds, &io_block
288
+ stream(*args, **kwds, &io_block) == 0
289
+ end
290
+
291
+
292
+ # execute command and return `true` if it failed.
293
+ #
294
+ # @param *args (see #capture)
295
+ # @param **kwds (see #capture)
296
+ # @param &input_block (see #capture)
297
+ #
298
+ # @return [Boolean]
299
+ # `true` if exit code was not `0`.
300
+ #
301
+ def error? *args, **kwds, &io_block
302
+ stream(*args, **kwds, &io_block) != 0
303
+ end
304
+
305
+
306
+ # def assert
307
+ # capture.raise_error
308
+ # end
309
+
310
+
311
+ def proxy
312
+ stream do |io|
313
+ io.in = $stdin
314
+ end
315
+ end
316
+
317
+
318
+ # captures and returns stdout
319
+ # (sugar for `#capture(*args, **kwds, &input_block).out`).
320
+ #
321
+ # @see #capture
322
+ # @see Result#out
323
+ #
324
+ # @param *args (see #capture)
325
+ # @param **kwds (see #capture)
326
+ # @param &input_block (see #capture)
327
+ #
328
+ # @return [String]
329
+ # the command's stdout.
330
+ #
331
+ def out *args, **kwds, &input_block
332
+ capture(*args, **kwds, &input_block).out
333
+ end
334
+
335
+
336
+ # captures and returns stdout
337
+ # (sugar for `#capture(*args, **kwds, &input_block).out`).
338
+ #
339
+ # @see #capture
340
+ # @see Result#out
341
+ #
342
+ # @param args [Array] see {.capture}.
343
+ # @param kwds [Proc] see {.capture}.
344
+ #
345
+ # @return [String] the command's stdout.
346
+ #
347
+ # @raise [SystemCallError] if the command fails (non-zero exit status).
348
+ #
349
+ def out! *args, **kwds, &input
350
+ capture(*args, **kwds, &input).assert.out
351
+ end
352
+
353
+
354
+ # captures and chomps stdout
355
+ # (sugar for `#out(*subs, &input_block).chomp`).
356
+ #
357
+ # @see #out
358
+ #
359
+ # @param *args (see #capture)
360
+ # @param **kwds (see #capture)
361
+ # @param &input_block (see #capture)
362
+ #
363
+ # @return [String]
364
+ # the command's chomped stdout.
365
+ #
366
+ def chomp *args, **kwds, &input_block
367
+ out(*args, **kwds, &input_block).chomp
368
+ end
369
+
370
+
371
+ # captures and chomps stdout, raising an error if the command failed.
372
+ # (sugar for `#out!(*subs, &input_block).chomp`).
373
+ #
374
+ # @see #capture
375
+ # @see Result#out
376
+ #
377
+ # @param *args (see #capture)
378
+ # @param **kwds (see #capture)
379
+ # @param &input_block (see #capture)
380
+ #
381
+ # @return [String]
382
+ # the command's chomped stdout.
383
+ #
384
+ # @raise [SystemCallError]
385
+ # if the command fails (non-zero exit status).
386
+ #
387
+ def chomp! *args, **kwds, &input
388
+ out!(*args, **kwds, &input).chomp
389
+ end
390
+
391
+
392
+ # captures and returns stdout
393
+ # (sugar for `#capture(*subs, &input_block).err`).
394
+ #
395
+ # @param *args (see #capture)
396
+ # @param **kwds (see #capture)
397
+ # @param &input_block (see #capture)
398
+ #
399
+ # @see #capture
400
+ # @see Result#err
401
+ #
402
+ # @return [String]
403
+ # the command's stderr.
404
+ #
405
+ def err *args, **kwds, &input_block
406
+ capture(*args, **kwds, &input_block).err
407
+ end
408
+ end # Cmds
data/scratch/proxy.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'cmds'
2
2
 
3
3
  Cmds.enable_debug do
4
- Cmds::Cmd.new("./test/questions.rb").proxy
4
+ Cmds.new("./test/questions.rb").proxy
5
5
  end
@@ -11,6 +11,6 @@ describe "Cmds::assert" do
11
11
 
12
12
  it "should be chainable when the command is ok" do
13
13
  expect( Cmds!("echo hey").out ).to eq "hey\n"
14
- expect( Cmds::Cmd.new("echo hey").capture.assert.out ).to eq "hey\n"
14
+ expect( Cmds.new("echo hey").capture.assert.out ).to eq "hey\n"
15
15
  end
16
16
  end # Cmds::run
@@ -3,13 +3,13 @@ require 'spec_helper'
3
3
  describe "Cmds::capture" do
4
4
  it "captures stdout" do
5
5
  expect(
6
- Cmds::Cmd.new(%{ruby -e '$stdout.puts "hey"'}).capture.out
6
+ Cmds.new(%{ruby -e '$stdout.puts "hey"'}).capture.out
7
7
  ).to eq "hey\n"
8
8
  end
9
9
 
10
10
  it "captures stderr" do
11
11
  expect(
12
- Cmds::Cmd.new(%{ruby -e '$stderr.puts "ho"'}).capture.err
12
+ Cmds.new(%{ruby -e '$stderr.puts "ho"'}).capture.err
13
13
  ).to eq "ho\n"
14
14
  end
15
15
 
@@ -42,8 +42,8 @@ describe "Cmds::capture" do
42
42
  end # context echo_cmd.rb 'hello world!'
43
43
 
44
44
  it "is reusable" do
45
- args_cmd = Cmds::Cmd.new "./test/echo_cmd.rb <%= arg %>"
46
- kwds_cmd = Cmds::Cmd.new "./test/echo_cmd.rb <%= s %>"
45
+ args_cmd = Cmds.new "./test/echo_cmd.rb <%= arg %>"
46
+ kwds_cmd = Cmds.new "./test/echo_cmd.rb <%= s %>"
47
47
 
48
48
  args = ["arg one", "arg two", "arg three"]
49
49
 
@@ -70,12 +70,12 @@ describe "Cmds::capture" do
70
70
  }
71
71
 
72
72
  it "accepts input via options" do
73
- cmd = Cmds::Cmd.new(ECHO_CMD, input: input)
73
+ cmd = Cmds.new(ECHO_CMD, input: input)
74
74
  expect( echo_cmd_stdin cmd.capture ).to eq input
75
75
  end
76
76
 
77
77
  it "accepts input via block" do
78
- cmd = Cmds::Cmd.new ECHO_CMD
78
+ cmd = Cmds.new ECHO_CMD
79
79
  expect( echo_cmd_stdin cmd.capture { input } ).to eq input
80
80
  end
81
81
 
@@ -84,7 +84,7 @@ describe "Cmds::capture" do
84
84
  input = f.read
85
85
  f.rewind
86
86
 
87
- cmd = Cmds::Cmd.new ECHO_CMD
87
+ cmd = Cmds.new ECHO_CMD
88
88
  expect( echo_cmd_stdin cmd.capture { f } ).to eq input
89
89
  end
90
90
  end
@@ -34,12 +34,12 @@ end # Cmds.chomp!
34
34
 
35
35
  describe "Cmds#chomp" do
36
36
  it "gets echo output" do
37
- expect( Cmds::Cmd.new("echo %s").chomp "hey there!" ).to eq "hey there!"
37
+ expect( Cmds.new("echo %s").chomp "hey there!" ).to eq "hey there!"
38
38
  end
39
39
 
40
40
  it "reads input" do
41
41
  expect(
42
- Cmds::Cmd.new("ruby -e %{script}").chomp(script: "puts STDIN.read") {
42
+ Cmds.new("ruby -e %{script}").chomp(script: "puts STDIN.read") {
43
43
  "hey there!"
44
44
  }
45
45
  ).to eq "hey there!"
@@ -48,18 +48,18 @@ end # Cmds#chomp
48
48
 
49
49
  describe "Cmds#chomp!" do
50
50
  it "gets echo output" do
51
- expect( Cmds::Cmd.new("echo %s").chomp! "hey there!" ).to eq "hey there!"
51
+ expect( Cmds.new("echo %s").chomp! "hey there!" ).to eq "hey there!"
52
52
  end
53
53
 
54
54
  it "reads input" do
55
55
  expect(
56
- Cmds::Cmd.new("ruby -e %{script}").chomp!(script: "puts STDIN.read") {
56
+ Cmds.new("ruby -e %{script}").chomp!(script: "puts STDIN.read") {
57
57
  "hey there!"
58
58
  }
59
59
  ).to eq "hey there!"
60
60
  end
61
61
 
62
62
  it "errors when the command fails" do
63
- expect { Cmds::Cmd.new("false").chomp! }.to raise_error SystemCallError
63
+ expect { Cmds.new("false").chomp! }.to raise_error SystemCallError
64
64
  end
65
65
  end # Cmds#chomp!
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe "Cmds::curry" do
4
4
  it "currys" do
5
- base = Cmds::Cmd.new "#{ ECHO_CMD } <%= x %> <%= y %>"
5
+ base = Cmds.new "#{ ECHO_CMD } <%= x %> <%= y %>"
6
6
 
7
7
  x1 = base.curry x: 1
8
8
  x2 = base.curry x: 2
@@ -4,17 +4,17 @@ describe "Cmds ENV vars" do
4
4
  r_echo_cmd = %{ruby -e "puts ENV['BLAH']"}
5
5
 
6
6
  it "sets basic (path-like) string ENV var" do
7
- cmd = Cmds::Cmd.new r_echo_cmd, env: {BLAH: "x:y:z"}
7
+ cmd = Cmds.new r_echo_cmd, env: {BLAH: "x:y:z"}
8
8
  expect(cmd.chomp!).to eq "x:y:z"
9
9
  end
10
10
 
11
11
  it "sets a string with spaces in it correctly" do
12
- cmd = Cmds::Cmd.new r_echo_cmd, env: {BLAH: "hey there"}
12
+ cmd = Cmds.new r_echo_cmd, env: {BLAH: "hey there"}
13
13
  expect(cmd.chomp!).to eq "hey there"
14
14
  end
15
15
 
16
16
  it "accepts string keys" do
17
- cmd = Cmds::Cmd.new r_echo_cmd, env: {
17
+ cmd = Cmds.new r_echo_cmd, env: {
18
18
  'BLAH' => [
19
19
  "/usr/local/bin",
20
20
  "/usr/bin",
@@ -17,13 +17,13 @@ end # Cmds.err
17
17
  describe "Cmds#err" do
18
18
  it "gets echo error output" do
19
19
  expect(
20
- Cmds::Cmd.new("echo %s 1>&2").err "hey there!"
20
+ Cmds.new("echo %s 1>&2").err "hey there!"
21
21
  ).to eq "hey there!\n"
22
22
  end
23
23
 
24
24
  it "reads input" do
25
25
  expect(
26
- Cmds::Cmd.new("ruby -e %{script}").
26
+ Cmds.new("ruby -e %{script}").
27
27
  err(script: "$stderr.puts STDIN.read") {
28
28
  "hey there!"
29
29
  }
@@ -2,8 +2,8 @@ require 'spec_helper'
2
2
 
3
3
  describe "Cmds.error?" do
4
4
  it "works through instance method" do
5
- expect( Cmds::Cmd.new("true").error? ).to be false
6
- expect( Cmds::Cmd.new("false").error? ).to be true
5
+ expect( Cmds.new("true").error? ).to be false
6
+ expect( Cmds.new("false").error? ).to be true
7
7
  end
8
8
 
9
9
  it "works through class method" do
data/spec/cmds/ok_spec.rb CHANGED
@@ -2,8 +2,8 @@ require 'spec_helper'
2
2
 
3
3
  describe "Cmds::ok?" do
4
4
  it "works through instance method" do
5
- expect( Cmds::Cmd.new("true").ok? ).to be true
6
- expect( Cmds::Cmd.new("false").ok? ).to be false
5
+ expect( Cmds.new("true").ok? ).to be true
6
+ expect( Cmds.new("false").ok? ).to be false
7
7
  end
8
8
 
9
9
  it "works through class method" do
@@ -34,12 +34,12 @@ end # Cmds.out!
34
34
 
35
35
  describe "Cmds#out" do
36
36
  it "gets echo output" do
37
- expect( Cmds::Cmd.new("echo %s").out "hey there!" ).to eq "hey there!\n"
37
+ expect( Cmds.new("echo %s").out "hey there!" ).to eq "hey there!\n"
38
38
  end
39
39
 
40
40
  it "reads input" do
41
41
  expect(
42
- Cmds::Cmd.new("ruby -e %{script}").out(script: "puts STDIN.read") {
42
+ Cmds.new("ruby -e %{script}").out(script: "puts STDIN.read") {
43
43
  "hey there!"
44
44
  }
45
45
  ).to eq "hey there!\n"
@@ -48,18 +48,18 @@ end # Cmds#out
48
48
 
49
49
  describe "Cmds#out!" do
50
50
  it "gets echo output" do
51
- expect( Cmds::Cmd.new("echo %s").out! "hey there!" ).to eq "hey there!\n"
51
+ expect( Cmds.new("echo %s").out! "hey there!" ).to eq "hey there!\n"
52
52
  end
53
53
 
54
54
  it "reads input" do
55
55
  expect(
56
- Cmds::Cmd.new("ruby -e %{script}").out!(script: "puts STDIN.read") {
56
+ Cmds.new("ruby -e %{script}").out!(script: "puts STDIN.read") {
57
57
  "hey there!"
58
58
  }
59
59
  ).to eq "hey there!\n"
60
60
  end
61
61
 
62
62
  it "errors when the command fails" do
63
- expect { Cmds::Cmd.new("false").out! }.to raise_error SystemCallError
63
+ expect { Cmds.new("false").out! }.to raise_error SystemCallError
64
64
  end
65
65
  end # Cmds#out!
@@ -17,8 +17,8 @@ describe "Cmds.prepare" do
17
17
  it "should work with a keyword substitutions with String keys" do
18
18
  expect(
19
19
  # NOTE since we use **kwds in #prepare which only accepts symbol keys,
20
- # have to load kwds with string keys in through Cmd.new
21
- Cmds::Cmd.new(
20
+ # have to load kwds with string keys in through Cmds.new
21
+ Cmds.new(
22
22
  "psql <%= opts %> <%= database %> < <%= filepath %>", {
23
23
  kwds: {
24
24
  'database' => "blah",
@@ -199,4 +199,12 @@ describe "Cmds.prepare" do
199
199
  end
200
200
  end # % proceeded by =
201
201
  end # shortcuts
202
+
203
+ context "tokenize multiple args as shell list" do
204
+ it "should expand args as space-separated list" do
205
+ expect(
206
+ Cmds.prepare "git add <%= *args %>", "x", "y", "z"
207
+ ).to eq "git add x y z"
208
+ end
209
+ end
202
210
  end # ::sub
@@ -5,7 +5,7 @@ describe "Cmds::stream" do
5
5
 
6
6
  it "writes to $stdout and $stderr by default" do
7
7
  out, err = temp_outs do
8
- Cmds::Cmd.new('./test/tick.rb <%= times %>').stream times: times
8
+ Cmds.new('./test/tick.rb <%= times %>').stream times: times
9
9
  end
10
10
 
11
11
  expect(out).to eq times.times.map{|_| "#{_}\n"}.join
@@ -15,7 +15,7 @@ describe "Cmds::stream" do
15
15
  it "handles writes in blocks" do
16
16
  out_count = 0
17
17
  err_count = 0
18
- Cmds::Cmd.new('./test/tick.rb <%= times %>').stream(times: times) do |io|
18
+ Cmds.new('./test/tick.rb <%= times %>').stream(times: times) do |io|
19
19
  io.on_out do |line|
20
20
  out_count += 1
21
21
  end
@@ -32,7 +32,7 @@ describe "Cmds::stream" do
32
32
  it "accepts string value input from a block" do
33
33
 
34
34
  out, err = temp_outs do
35
- Cmds::Cmd.new("wc -l").stream do
35
+ Cmds.new("wc -l").stream do
36
36
  <<-BLOCK
37
37
  one
38
38
  two
@@ -47,7 +47,7 @@ describe "Cmds::stream" do
47
47
 
48
48
  it "accepts stream value input from a block" do
49
49
  out, err = temp_outs do
50
- Cmds::Cmd.new("wc -l").stream do
50
+ Cmds.new("wc -l").stream do
51
51
  File.open "./test/lines.txt"
52
52
  end
53
53
  end
data/spec/cmds_spec.rb CHANGED
@@ -9,7 +9,7 @@ describe Cmds do
9
9
  expect(Cmds.chomp! "echo 'here'").to eq 'here'
10
10
 
11
11
  expect(
12
- Cmds::Cmd.new("head %{opts} %s").
12
+ Cmds.new("head %{opts} %s").
13
13
  prepare("/dev/random", opts: {c: 64})
14
14
  ).to eq "head -c 64 /dev/random"
15
15