cmds 0.0.8 → 0.0.9
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 +100 -13
- data/lib/cmds/version.rb +1 -1
- data/spec/cmds/chomp_spec.rb +65 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1dd522e09d442b565bd299965feb5568ac5d830e
|
4
|
+
data.tar.gz: 901dde67d7c5f77571539ab2ae8ea7a3b67c9d5d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c5eea2077d11d90db033f8fd98ce2fb8782ac554427676087f1917fdf2f402ff6836089ab03a1e274783108b1acee9a49185e68fc7c46996b0db973c46a9b49
|
7
|
+
data.tar.gz: 85f29ade7132c8c083c94b4e7939aed8be3fe7a1d2153fadff115f581f9d32a43e5a5d5cfcdfe277efc6f641fd2290294e89dce2f5c27c18da6f7b27fc810b50
|
data/lib/cmds/sugar.rb
CHANGED
@@ -54,14 +54,17 @@ class Cmds
|
|
54
54
|
|
55
55
|
# @api sugar
|
56
56
|
#
|
57
|
-
# captures and returns stdout
|
57
|
+
# captures and returns stdout
|
58
|
+
# (sugar for `Cmds.capture(*template, *subs, &input_block).out`).
|
59
|
+
#
|
60
|
+
# @see .capture
|
61
|
+
# @see Result#out
|
58
62
|
#
|
59
63
|
# @param template [String] see {.capture}.
|
60
64
|
# @param subs [Array] see {.capture}.
|
61
65
|
# @param input_block [Proc] see {.capture}.
|
62
66
|
#
|
63
|
-
# @
|
64
|
-
# @see Result#out
|
67
|
+
# @return [String] the command's stdout.
|
65
68
|
#
|
66
69
|
def self.out template, *subs, &input_block
|
67
70
|
capture(template, *subs, &input_block).out
|
@@ -72,12 +75,16 @@ class Cmds
|
|
72
75
|
#
|
73
76
|
# captures and returns stdout, raising an error if the command fails.
|
74
77
|
#
|
78
|
+
# @see .capture
|
79
|
+
# @see Result#out
|
80
|
+
#
|
75
81
|
# @param template [String] see {.capture}.
|
76
82
|
# @param subs [Array] see {.capture}.
|
77
83
|
# @param input_block [Proc] see {.capture}.
|
78
84
|
#
|
79
|
-
# @
|
80
|
-
#
|
85
|
+
# @return [String] the command's stdout.
|
86
|
+
#
|
87
|
+
# @raise [SystemCallError] if the command fails (non-zero exit status).
|
81
88
|
#
|
82
89
|
def self.out! template, *subs, &input_block
|
83
90
|
Cmds.new(
|
@@ -89,15 +96,56 @@ class Cmds
|
|
89
96
|
|
90
97
|
# @api sugar
|
91
98
|
#
|
92
|
-
# captures and
|
99
|
+
# captures and chomps stdout
|
100
|
+
# (sugar for `Cmds.out(*template, *subs, &input_block).chomp`).
|
101
|
+
#
|
102
|
+
# @see .out
|
103
|
+
#
|
104
|
+
# @param template [String] see {.capture}.
|
105
|
+
# @param subs [Array] see {.capture}.
|
106
|
+
# @param input_block [Proc] see {.capture}.
|
107
|
+
#
|
108
|
+
# @return [String] the command's chomped stdout.
|
109
|
+
#
|
110
|
+
def self.chomp template, *subs, &input_block
|
111
|
+
out(template, *subs, &input_block).chomp
|
112
|
+
end
|
113
|
+
|
114
|
+
|
115
|
+
# @api sugar
|
116
|
+
#
|
117
|
+
# captures and chomps stdout, raising an error if the command fails.
|
118
|
+
# (sugar for `Cmds.out!(*template, *subs, &input_block).chomp`).
|
119
|
+
#
|
120
|
+
# @see .out!
|
93
121
|
#
|
94
122
|
# @param template [String] see {.capture}.
|
95
123
|
# @param subs [Array] see {.capture}.
|
96
124
|
# @param input_block [Proc] see {.capture}.
|
97
125
|
#
|
126
|
+
# @return [String] the command's chomped stdout.
|
127
|
+
#
|
128
|
+
# @raise [SystemCallError] if the command fails (non-zero exit status).
|
129
|
+
#
|
130
|
+
def self.chomp! template, *subs, &input_block
|
131
|
+
out!(template, *subs, &input_block).chomp
|
132
|
+
end
|
133
|
+
|
134
|
+
|
135
|
+
# @api sugar
|
136
|
+
#
|
137
|
+
# captures and returns stderr
|
138
|
+
# (sugar for `Cmds.capture(template, *subs, &input_block).err`).
|
139
|
+
#
|
98
140
|
# @see .capture
|
99
141
|
# @see Result#err
|
100
142
|
#
|
143
|
+
# @param template [String] see {.capture}.
|
144
|
+
# @param subs [Array] see {.capture}.
|
145
|
+
# @param input_block [Proc] see {.capture}.
|
146
|
+
#
|
147
|
+
# @return [String] the command's stderr.
|
148
|
+
#
|
101
149
|
def self.err template, *subs, &input_block
|
102
150
|
capture(template, *subs, &input_block).err
|
103
151
|
end
|
@@ -131,14 +179,14 @@ class Cmds
|
|
131
179
|
# captures and returns stdout
|
132
180
|
# (sugar for `#capture(*subs, &input_block).out`).
|
133
181
|
#
|
182
|
+
# @see #capture
|
183
|
+
# @see Result#out
|
184
|
+
#
|
134
185
|
# @param subs [Array] see {.capture}.
|
135
186
|
# @param input_block [Proc] see {.capture}.
|
136
187
|
#
|
137
188
|
# @return [String] the command's stdout.
|
138
189
|
#
|
139
|
-
# @see #capture
|
140
|
-
# @see Result#out
|
141
|
-
#
|
142
190
|
def out *subs, &input_block
|
143
191
|
capture(*subs, &input_block).out
|
144
192
|
end
|
@@ -149,13 +197,15 @@ class Cmds
|
|
149
197
|
# captures and returns stdout
|
150
198
|
# (sugar for `#capture(*subs, &input_block).out`).
|
151
199
|
#
|
200
|
+
# @see #capture
|
201
|
+
# @see Result#out
|
202
|
+
#
|
152
203
|
# @param subs [Array] see {.capture}.
|
153
204
|
# @param input_block [Proc] see {.capture}.
|
154
205
|
#
|
155
206
|
# @return [String] the command's stdout.
|
156
207
|
#
|
157
|
-
# @
|
158
|
-
# @see Result#out
|
208
|
+
# @raise [SystemCallError] if the command fails (non-zero exit status).
|
159
209
|
#
|
160
210
|
def out! *subs, &input_block
|
161
211
|
self.class.new(
|
@@ -165,6 +215,43 @@ class Cmds
|
|
165
215
|
end
|
166
216
|
|
167
217
|
|
218
|
+
# @api sugar
|
219
|
+
#
|
220
|
+
# captures and chomps stdout
|
221
|
+
# (sugar for `#out(*subs, &input_block).chomp`).
|
222
|
+
#
|
223
|
+
# @see #out
|
224
|
+
#
|
225
|
+
# @param subs [Array] see {.capture}.
|
226
|
+
# @param input_block [Proc] see {.capture}.
|
227
|
+
#
|
228
|
+
# @return [String] the command's chomped stdout.
|
229
|
+
#
|
230
|
+
def chomp *subs, &input_block
|
231
|
+
out(*subs, &input_block).chomp
|
232
|
+
end
|
233
|
+
|
234
|
+
|
235
|
+
# @api sugar
|
236
|
+
#
|
237
|
+
# captures and chomps stdout, raising an error if the command failed.
|
238
|
+
# (sugar for `#out!(*subs, &input_block).chomp`).
|
239
|
+
#
|
240
|
+
# @see #capture
|
241
|
+
# @see Result#out
|
242
|
+
#
|
243
|
+
# @param subs [Array] see {.capture}.
|
244
|
+
# @param input_block [Proc] see {.capture}.
|
245
|
+
#
|
246
|
+
# @return [String] the command's chomped stdout.
|
247
|
+
#
|
248
|
+
# @raise [SystemCallError] if the command fails (non-zero exit status).
|
249
|
+
#
|
250
|
+
def chomp! *subs, &input_block
|
251
|
+
out!(*subs, &input_block).chomp
|
252
|
+
end
|
253
|
+
|
254
|
+
|
168
255
|
# @api sugar
|
169
256
|
#
|
170
257
|
# captures and returns stdout
|
@@ -173,11 +260,11 @@ class Cmds
|
|
173
260
|
# @param subs [Array] see {.capture}.
|
174
261
|
# @param input_block [Proc] see {.capture}.
|
175
262
|
#
|
176
|
-
# @return [String] the command's stdout.
|
177
|
-
#
|
178
263
|
# @see #capture
|
179
264
|
# @see Result#err
|
180
265
|
#
|
266
|
+
# @return [String] the command's stderr.
|
267
|
+
#
|
181
268
|
def err *subs, &input_block
|
182
269
|
capture(*subs, &input_block).err
|
183
270
|
end
|
data/lib/cmds/version.rb
CHANGED
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Cmds.chomp" do
|
4
|
+
it "gets echo output" do
|
5
|
+
expect( Cmds.chomp "echo %s", ["hey there!"] ).to eq "hey there!"
|
6
|
+
end
|
7
|
+
|
8
|
+
it "reads input" do
|
9
|
+
expect(
|
10
|
+
Cmds.chomp("ruby -e %{script}", script: "puts STDIN.read") {
|
11
|
+
"hey there!"
|
12
|
+
}
|
13
|
+
).to eq "hey there!"
|
14
|
+
end
|
15
|
+
end # Cmds.chomp
|
16
|
+
|
17
|
+
describe "Cmds.chomp!" do
|
18
|
+
it "gets echo output" do
|
19
|
+
expect( Cmds.chomp! "echo %s", ["hey there!"] ).to eq "hey there!"
|
20
|
+
end
|
21
|
+
|
22
|
+
it "reads input" do
|
23
|
+
expect(
|
24
|
+
Cmds.chomp!("ruby -e %{script}", script: "puts STDIN.read") {
|
25
|
+
"hey there!"
|
26
|
+
}
|
27
|
+
).to eq "hey there!"
|
28
|
+
end
|
29
|
+
|
30
|
+
it "errors when the command fails" do
|
31
|
+
expect { Cmds.chomp! "false" }.to raise_error SystemCallError
|
32
|
+
end
|
33
|
+
end # Cmds.chomp!
|
34
|
+
|
35
|
+
describe "Cmds#chomp" do
|
36
|
+
it "gets echo output" do
|
37
|
+
expect( Cmds.new("echo %s").chomp ["hey there!"] ).to eq "hey there!"
|
38
|
+
end
|
39
|
+
|
40
|
+
it "reads input" do
|
41
|
+
expect(
|
42
|
+
Cmds.new("ruby -e %{script}").chomp(script: "puts STDIN.read") {
|
43
|
+
"hey there!"
|
44
|
+
}
|
45
|
+
).to eq "hey there!"
|
46
|
+
end
|
47
|
+
end # Cmds#chomp
|
48
|
+
|
49
|
+
describe "Cmds#chomp!" do
|
50
|
+
it "gets echo output" do
|
51
|
+
expect( Cmds.new("echo %s").chomp! ["hey there!"] ).to eq "hey there!"
|
52
|
+
end
|
53
|
+
|
54
|
+
it "reads input" do
|
55
|
+
expect(
|
56
|
+
Cmds.new("ruby -e %{script}").chomp!(script: "puts STDIN.read") {
|
57
|
+
"hey there!"
|
58
|
+
}
|
59
|
+
).to eq "hey there!"
|
60
|
+
end
|
61
|
+
|
62
|
+
it "errors when the command fails" do
|
63
|
+
expect { Cmds.new("false").chomp! }.to raise_error SystemCallError
|
64
|
+
end
|
65
|
+
end # Cmds#chomp!
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nrser
|
@@ -156,6 +156,7 @@ files:
|
|
156
156
|
- scratch/proxy.rb
|
157
157
|
- spec/cmds/assert_spec.rb
|
158
158
|
- spec/cmds/capture_spec.rb
|
159
|
+
- spec/cmds/chomp_spec.rb
|
159
160
|
- spec/cmds/curry_spec.rb
|
160
161
|
- spec/cmds/erb_context_spec.rb
|
161
162
|
- spec/cmds/err_spec.rb
|
@@ -202,6 +203,7 @@ summary: helps read, write and remember commands.
|
|
202
203
|
test_files:
|
203
204
|
- spec/cmds/assert_spec.rb
|
204
205
|
- spec/cmds/capture_spec.rb
|
206
|
+
- spec/cmds/chomp_spec.rb
|
205
207
|
- spec/cmds/curry_spec.rb
|
206
208
|
- spec/cmds/erb_context_spec.rb
|
207
209
|
- spec/cmds/err_spec.rb
|