cmds 0.0.7 → 0.0.8
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/lib/cmds/sugar.rb +108 -0
- data/lib/cmds/version.rb +1 -1
- data/spec/cmds/err_spec.rb +29 -0
- data/spec/cmds/out_spec.rb +65 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c6566ed118279014629f7435a6a271de93416f81
|
4
|
+
data.tar.gz: ce308a9251460a2c0d3cf4729aefc50c2e5ff1c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa04300533619aa99726a972ac0cfc8ca0814c40e796a5d926909fc55c7ac1119d9ec47c1b117399c1b51c57ac3b32ad9eed4856a4eb8ad8f975e4987bc910e2
|
7
|
+
data.tar.gz: 80c58ef1c07ab63dd515da61381200a2f5dc1bd47f223d2c6db838dba33a7bf8bae31f21aaa9f8e539915528a17c7f30258e0fa338222d26fbe41afc22067f58
|
data/lib/cmds/sugar.rb
CHANGED
@@ -51,6 +51,57 @@ class Cmds
|
|
51
51
|
Cmds.new(template, assert: true).stream *subs, &input_block
|
52
52
|
end # ::stream!
|
53
53
|
|
54
|
+
|
55
|
+
# @api sugar
|
56
|
+
#
|
57
|
+
# captures and returns stdout (sugar for `Cmds.capture(*args).out`).
|
58
|
+
#
|
59
|
+
# @param template [String] see {.capture}.
|
60
|
+
# @param subs [Array] see {.capture}.
|
61
|
+
# @param input_block [Proc] see {.capture}.
|
62
|
+
#
|
63
|
+
# @see .capture
|
64
|
+
# @see Result#out
|
65
|
+
#
|
66
|
+
def self.out template, *subs, &input_block
|
67
|
+
capture(template, *subs, &input_block).out
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
# @api sugar
|
72
|
+
#
|
73
|
+
# captures and returns stdout, raising an error if the command fails.
|
74
|
+
#
|
75
|
+
# @param template [String] see {.capture}.
|
76
|
+
# @param subs [Array] see {.capture}.
|
77
|
+
# @param input_block [Proc] see {.capture}.
|
78
|
+
#
|
79
|
+
# @see .capture
|
80
|
+
# @see Result#out
|
81
|
+
#
|
82
|
+
def self.out! template, *subs, &input_block
|
83
|
+
Cmds.new(
|
84
|
+
template,
|
85
|
+
options(subs, input_block).merge!(assert: true),
|
86
|
+
).capture.out
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
# @api sugar
|
91
|
+
#
|
92
|
+
# captures and returns stderr (sugar for `Cmds.capture(*args).err`).
|
93
|
+
#
|
94
|
+
# @param template [String] see {.capture}.
|
95
|
+
# @param subs [Array] see {.capture}.
|
96
|
+
# @param input_block [Proc] see {.capture}.
|
97
|
+
#
|
98
|
+
# @see .capture
|
99
|
+
# @see Result#err
|
100
|
+
#
|
101
|
+
def self.err template, *subs, &input_block
|
102
|
+
capture(template, *subs, &input_block).err
|
103
|
+
end
|
104
|
+
|
54
105
|
# instance methods
|
55
106
|
# ================
|
56
107
|
|
@@ -74,4 +125,61 @@ class Cmds
|
|
74
125
|
end
|
75
126
|
end
|
76
127
|
|
128
|
+
|
129
|
+
# @api sugar
|
130
|
+
#
|
131
|
+
# captures and returns stdout
|
132
|
+
# (sugar for `#capture(*subs, &input_block).out`).
|
133
|
+
#
|
134
|
+
# @param subs [Array] see {.capture}.
|
135
|
+
# @param input_block [Proc] see {.capture}.
|
136
|
+
#
|
137
|
+
# @return [String] the command's stdout.
|
138
|
+
#
|
139
|
+
# @see #capture
|
140
|
+
# @see Result#out
|
141
|
+
#
|
142
|
+
def out *subs, &input_block
|
143
|
+
capture(*subs, &input_block).out
|
144
|
+
end
|
145
|
+
|
146
|
+
|
147
|
+
# @api sugar
|
148
|
+
#
|
149
|
+
# captures and returns stdout
|
150
|
+
# (sugar for `#capture(*subs, &input_block).out`).
|
151
|
+
#
|
152
|
+
# @param subs [Array] see {.capture}.
|
153
|
+
# @param input_block [Proc] see {.capture}.
|
154
|
+
#
|
155
|
+
# @return [String] the command's stdout.
|
156
|
+
#
|
157
|
+
# @see #capture
|
158
|
+
# @see Result#out
|
159
|
+
#
|
160
|
+
def out! *subs, &input_block
|
161
|
+
self.class.new(
|
162
|
+
@template,
|
163
|
+
merge_options(subs, input_block).merge!(assert: true),
|
164
|
+
).capture.out
|
165
|
+
end
|
166
|
+
|
167
|
+
|
168
|
+
# @api sugar
|
169
|
+
#
|
170
|
+
# captures and returns stdout
|
171
|
+
# (sugar for `#capture(*subs, &input_block).err`).
|
172
|
+
#
|
173
|
+
# @param subs [Array] see {.capture}.
|
174
|
+
# @param input_block [Proc] see {.capture}.
|
175
|
+
#
|
176
|
+
# @return [String] the command's stdout.
|
177
|
+
#
|
178
|
+
# @see #capture
|
179
|
+
# @see Result#err
|
180
|
+
#
|
181
|
+
def err *subs, &input_block
|
182
|
+
capture(*subs, &input_block).err
|
183
|
+
end
|
184
|
+
|
77
185
|
end # class Cmds
|
data/lib/cmds/version.rb
CHANGED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Cmds.err" do
|
4
|
+
it "gets echo error output" do
|
5
|
+
expect( Cmds.err "echo %s 1>&2", ["hey there!"] ).to eq "hey there!\n"
|
6
|
+
end
|
7
|
+
|
8
|
+
it "reads input" do
|
9
|
+
expect(
|
10
|
+
Cmds.err("ruby -e %{script}", script: "$stderr.puts STDIN.read") {
|
11
|
+
"hey there!"
|
12
|
+
}
|
13
|
+
).to eq "hey there!\n"
|
14
|
+
end
|
15
|
+
end # Cmds.err
|
16
|
+
|
17
|
+
describe "Cmds#err" do
|
18
|
+
it "gets echo error output" do
|
19
|
+
expect( Cmds.new("echo %s 1>&2").err ["hey there!"] ).to eq "hey there!\n"
|
20
|
+
end
|
21
|
+
|
22
|
+
it "reads input" do
|
23
|
+
expect(
|
24
|
+
Cmds.new("ruby -e %{script}").err(script: "$stderr.puts STDIN.read") {
|
25
|
+
"hey there!"
|
26
|
+
}
|
27
|
+
).to eq "hey there!\n"
|
28
|
+
end
|
29
|
+
end # Cmds#err
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Cmds.out" do
|
4
|
+
it "gets echo output" do
|
5
|
+
expect( Cmds.out "echo %s", ["hey there!"] ).to eq "hey there!\n"
|
6
|
+
end
|
7
|
+
|
8
|
+
it "reads input" do
|
9
|
+
expect(
|
10
|
+
Cmds.out("ruby -e %{script}", script: "puts STDIN.read") {
|
11
|
+
"hey there!"
|
12
|
+
}
|
13
|
+
).to eq "hey there!\n"
|
14
|
+
end
|
15
|
+
end # Cmds.out
|
16
|
+
|
17
|
+
describe "Cmds.out!" do
|
18
|
+
it "gets echo output" do
|
19
|
+
expect( Cmds.out! "echo %s", ["hey there!"] ).to eq "hey there!\n"
|
20
|
+
end
|
21
|
+
|
22
|
+
it "reads input" do
|
23
|
+
expect(
|
24
|
+
Cmds.out!("ruby -e %{script}", script: "puts STDIN.read") {
|
25
|
+
"hey there!"
|
26
|
+
}
|
27
|
+
).to eq "hey there!\n"
|
28
|
+
end
|
29
|
+
|
30
|
+
it "errors when the command fails" do
|
31
|
+
expect { Cmds.out! "false" }.to raise_error SystemCallError
|
32
|
+
end
|
33
|
+
end # Cmds.out!
|
34
|
+
|
35
|
+
describe "Cmds#out" do
|
36
|
+
it "gets echo output" do
|
37
|
+
expect( Cmds.new("echo %s").out ["hey there!"] ).to eq "hey there!\n"
|
38
|
+
end
|
39
|
+
|
40
|
+
it "reads input" do
|
41
|
+
expect(
|
42
|
+
Cmds.new("ruby -e %{script}").out(script: "puts STDIN.read") {
|
43
|
+
"hey there!"
|
44
|
+
}
|
45
|
+
).to eq "hey there!\n"
|
46
|
+
end
|
47
|
+
end # Cmds#out
|
48
|
+
|
49
|
+
describe "Cmds#out!" do
|
50
|
+
it "gets echo output" do
|
51
|
+
expect( Cmds.new("echo %s").out! ["hey there!"] ).to eq "hey there!\n"
|
52
|
+
end
|
53
|
+
|
54
|
+
it "reads input" do
|
55
|
+
expect(
|
56
|
+
Cmds.new("ruby -e %{script}").out!(script: "puts STDIN.read") {
|
57
|
+
"hey there!"
|
58
|
+
}
|
59
|
+
).to eq "hey there!\n"
|
60
|
+
end
|
61
|
+
|
62
|
+
it "errors when the command fails" do
|
63
|
+
expect { Cmds.new("false").out! }.to raise_error SystemCallError
|
64
|
+
end
|
65
|
+
end # Cmds#out!
|
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.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nrser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nrser
|
@@ -158,9 +158,11 @@ files:
|
|
158
158
|
- spec/cmds/capture_spec.rb
|
159
159
|
- spec/cmds/curry_spec.rb
|
160
160
|
- spec/cmds/erb_context_spec.rb
|
161
|
+
- spec/cmds/err_spec.rb
|
161
162
|
- spec/cmds/error_spec.rb
|
162
163
|
- spec/cmds/expand_option_hash_spec.rb
|
163
164
|
- spec/cmds/ok_spec.rb
|
165
|
+
- spec/cmds/out_spec.rb
|
164
166
|
- spec/cmds/replace_shortcuts_spec.rb
|
165
167
|
- spec/cmds/stream_spec.rb
|
166
168
|
- spec/cmds/sub_spec.rb
|
@@ -202,9 +204,11 @@ test_files:
|
|
202
204
|
- spec/cmds/capture_spec.rb
|
203
205
|
- spec/cmds/curry_spec.rb
|
204
206
|
- spec/cmds/erb_context_spec.rb
|
207
|
+
- spec/cmds/err_spec.rb
|
205
208
|
- spec/cmds/error_spec.rb
|
206
209
|
- spec/cmds/expand_option_hash_spec.rb
|
207
210
|
- spec/cmds/ok_spec.rb
|
211
|
+
- spec/cmds/out_spec.rb
|
208
212
|
- spec/cmds/replace_shortcuts_spec.rb
|
209
213
|
- spec/cmds/stream_spec.rb
|
210
214
|
- spec/cmds/sub_spec.rb
|