frag 0.0.1 → 0.1.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/CHANGELOG +4 -0
- data/README.markdown +7 -7
- data/lib/frag/app.rb +2 -2
- data/lib/frag/version.rb +1 -1
- data/test/test_integration.rb +12 -12
- data/test/unit/test_app.rb +86 -86
- metadata +3 -3
data/CHANGELOG
CHANGED
data/README.markdown
CHANGED
@@ -16,14 +16,14 @@ you might want to generate your `~/.ssh/config` from a list of hosts managed by
|
|
16
16
|
Hostname 123.123.123.2
|
17
17
|
User me
|
18
18
|
|
19
|
-
#
|
20
|
-
#
|
19
|
+
# frag: knife sshgen
|
20
|
+
# frag end
|
21
21
|
|
22
22
|
Now `frag` that file:
|
23
23
|
|
24
24
|
frag ~/.ssh/config
|
25
25
|
|
26
|
-
and the region delimited by the `GEN`..`
|
26
|
+
and the region delimited by the `GEN`..`frag end` lines will be filled in with the
|
27
27
|
output from [knife sshgen][knife-sshgen]. The delimiter lines remain, so you can
|
28
28
|
re-`frag` anytime to bring it up to date.
|
29
29
|
|
@@ -35,15 +35,15 @@ database:
|
|
35
35
|
::1 localhost
|
36
36
|
fe80::1%lo0 localhost
|
37
37
|
|
38
|
-
#
|
39
|
-
#
|
38
|
+
# frag: mysql myapp -Bre 'select subdomain from sites | sed -e 's/.*/127.0.0.1 &.myapp.local/'
|
39
|
+
# frag end
|
40
40
|
|
41
41
|
Pipelines work - woo!
|
42
42
|
|
43
43
|
Or maybe you're authoring this README and want to show all the options `frag`
|
44
44
|
takes:
|
45
45
|
|
46
|
-
<!--
|
46
|
+
<!-- frag: echo; ruby -Ilib bin/frag --help | sed -e 's/^/ /'; echo -->
|
47
47
|
|
48
48
|
USAGE: bin/frag [options] file ...
|
49
49
|
-b, --begin DELIMITER
|
@@ -53,7 +53,7 @@ takes:
|
|
53
53
|
-p, --backup-prefix PREFIX
|
54
54
|
-s, --backup-suffix SUFFIX
|
55
55
|
|
56
|
-
<!--
|
56
|
+
<!-- frag end -->
|
57
57
|
|
58
58
|
(Check the source... ;-)
|
59
59
|
|
data/lib/frag/app.rb
CHANGED
data/lib/frag/version.rb
CHANGED
data/test/test_integration.rb
CHANGED
@@ -12,15 +12,15 @@ describe Frag do
|
|
12
12
|
describe "when a file is frag'd successfully" do
|
13
13
|
it "updates the file, and exits with zero status" do
|
14
14
|
write_file 'input', <<-EOS.demargin
|
15
|
-
|#
|
15
|
+
|# frag: echo new
|
16
16
|
|old
|
17
|
-
|#
|
17
|
+
|# frag end
|
18
18
|
EOS
|
19
19
|
frag('input').must_equal 0
|
20
20
|
File.read('input').must_equal <<-EOS.demargin
|
21
|
-
|#
|
21
|
+
|# frag: echo new
|
22
22
|
|new
|
23
|
-
|#
|
23
|
+
|# frag end
|
24
24
|
EOS
|
25
25
|
end
|
26
26
|
end
|
@@ -28,21 +28,21 @@ describe Frag do
|
|
28
28
|
describe "when options are used succesfully" do
|
29
29
|
it "updates the file, and exits with zero status" do
|
30
30
|
write_file 'input', <<-EOS.demargin
|
31
|
-
|#
|
31
|
+
|# frag: echo new
|
32
32
|
|old
|
33
|
-
|#
|
34
|
-
|//
|
33
|
+
|# frag end
|
34
|
+
|// frag: echo new
|
35
35
|
|old
|
36
|
-
|//
|
36
|
+
|// frag end
|
37
37
|
EOS
|
38
38
|
frag('-l', '//', 'input').must_equal 0
|
39
39
|
File.read('input').must_equal <<-EOS.demargin
|
40
|
-
|#
|
40
|
+
|# frag: echo new
|
41
41
|
|old
|
42
|
-
|#
|
43
|
-
|//
|
42
|
+
|# frag end
|
43
|
+
|// frag: echo new
|
44
44
|
|new
|
45
|
-
|//
|
45
|
+
|// frag end
|
46
46
|
EOS
|
47
47
|
end
|
48
48
|
end
|
data/test/unit/test_app.rb
CHANGED
@@ -14,92 +14,92 @@ describe Frag::App do
|
|
14
14
|
describe "when no options are used" do
|
15
15
|
it "populates the delimited region if it's empty" do
|
16
16
|
write_file 'input', <<-EOS.demargin
|
17
|
-
|#
|
18
|
-
|#
|
17
|
+
|# frag: echo hi
|
18
|
+
|# frag end
|
19
19
|
EOS
|
20
20
|
frag('input').must_equal 0
|
21
21
|
(output.string + error.string).must_equal ''
|
22
22
|
File.read('input').must_equal <<-EOS.demargin
|
23
|
-
|#
|
23
|
+
|# frag: echo hi
|
24
24
|
|hi
|
25
|
-
|#
|
25
|
+
|# frag end
|
26
26
|
EOS
|
27
27
|
end
|
28
28
|
|
29
29
|
it "replaces the delimited region if there's already something there" do
|
30
30
|
write_file 'input', <<-EOS.demargin
|
31
|
-
|#
|
31
|
+
|# frag: echo new
|
32
32
|
|old
|
33
|
-
|#
|
33
|
+
|# frag end
|
34
34
|
EOS
|
35
35
|
frag('input').must_equal 0
|
36
36
|
(output.string + error.string).must_equal ''
|
37
37
|
File.read('input').must_equal <<-EOS.demargin
|
38
|
-
|#
|
38
|
+
|# frag: echo new
|
39
39
|
|new
|
40
|
-
|#
|
40
|
+
|# frag end
|
41
41
|
EOS
|
42
42
|
end
|
43
43
|
|
44
44
|
it "appends a newline if the command output doesn't end in one" do
|
45
45
|
write_file 'input', <<-EOS.demargin
|
46
|
-
|#
|
47
|
-
|#
|
46
|
+
|# frag: echo -n hi
|
47
|
+
|# frag end
|
48
48
|
EOS
|
49
49
|
frag('input').must_equal 0
|
50
50
|
(output.string + error.string).must_equal ''
|
51
51
|
File.read('input').must_equal <<-EOS.demargin
|
52
|
-
|#
|
52
|
+
|# frag: echo -n hi
|
53
53
|
|hi
|
54
|
-
|#
|
54
|
+
|# frag end
|
55
55
|
EOS
|
56
56
|
end
|
57
57
|
|
58
58
|
it "processes multiple regions, and leave surrounding content alone" do
|
59
59
|
write_file 'input', <<-EOS.demargin
|
60
60
|
|before
|
61
|
-
|#
|
62
|
-
|#
|
61
|
+
|# frag: echo one
|
62
|
+
|# frag end
|
63
63
|
|middle
|
64
|
-
|#
|
65
|
-
|#
|
64
|
+
|# frag: echo two
|
65
|
+
|# frag end
|
66
66
|
|after
|
67
67
|
EOS
|
68
68
|
frag('input').must_equal 0
|
69
69
|
(output.string + error.string).must_equal ''
|
70
70
|
File.read('input').must_equal <<-EOS.demargin
|
71
71
|
|before
|
72
|
-
|#
|
72
|
+
|# frag: echo one
|
73
73
|
|one
|
74
|
-
|#
|
74
|
+
|# frag end
|
75
75
|
|middle
|
76
|
-
|#
|
76
|
+
|# frag: echo two
|
77
77
|
|two
|
78
|
-
|#
|
78
|
+
|# frag end
|
79
79
|
|after
|
80
80
|
EOS
|
81
81
|
end
|
82
82
|
|
83
83
|
it "can process multiple files" do
|
84
84
|
write_file 'one', <<-EOS.demargin
|
85
|
-
|#
|
86
|
-
|#
|
85
|
+
|# frag: echo one
|
86
|
+
|# frag end
|
87
87
|
EOS
|
88
88
|
write_file 'two', <<-EOS.demargin
|
89
|
-
|#
|
90
|
-
|#
|
89
|
+
|# frag: echo two
|
90
|
+
|# frag end
|
91
91
|
EOS
|
92
92
|
frag('one', 'two').must_equal 0
|
93
93
|
(output.string + error.string).must_equal ''
|
94
94
|
File.read('one').must_equal <<-EOS.demargin
|
95
|
-
|#
|
95
|
+
|# frag: echo one
|
96
96
|
|one
|
97
|
-
|#
|
97
|
+
|# frag end
|
98
98
|
EOS
|
99
99
|
File.read('two').must_equal <<-EOS.demargin
|
100
|
-
|#
|
100
|
+
|# frag: echo two
|
101
101
|
|two
|
102
|
-
|#
|
102
|
+
|# frag end
|
103
103
|
EOS
|
104
104
|
end
|
105
105
|
end
|
@@ -109,14 +109,14 @@ describe Frag::App do
|
|
109
109
|
it "uses the beginning delimiter given by #{option}" do
|
110
110
|
write_file 'input', <<-EOS.demargin
|
111
111
|
|# BEGIN echo one
|
112
|
-
|#
|
112
|
+
|# frag end
|
113
113
|
EOS
|
114
114
|
frag(option, 'BEGIN', 'input').must_equal 0
|
115
115
|
(output.string + error.string).must_equal ''
|
116
116
|
File.read('input').must_equal <<-EOS.demargin
|
117
117
|
|# BEGIN echo one
|
118
118
|
|one
|
119
|
-
|#
|
119
|
+
|# frag end
|
120
120
|
EOS
|
121
121
|
end
|
122
122
|
end
|
@@ -124,13 +124,13 @@ describe Frag::App do
|
|
124
124
|
['-e', '--end'].each do |option|
|
125
125
|
it "uses the ending delimiter given by #{option}" do
|
126
126
|
write_file 'input', <<-EOS.demargin
|
127
|
-
|#
|
127
|
+
|# frag: echo one
|
128
128
|
|# END
|
129
129
|
EOS
|
130
130
|
frag(option, 'END', 'input').must_equal 0
|
131
131
|
(output.string + error.string).must_equal ''
|
132
132
|
File.read('input').must_equal <<-EOS.demargin
|
133
|
-
|#
|
133
|
+
|# frag: echo one
|
134
134
|
|one
|
135
135
|
|# END
|
136
136
|
EOS
|
@@ -140,15 +140,15 @@ describe Frag::App do
|
|
140
140
|
['-l', '--leader'].each do |option|
|
141
141
|
it "uses the delimiter leader given by #{option}" do
|
142
142
|
write_file 'input', <<-EOS.demargin
|
143
|
-
|//
|
144
|
-
|//
|
143
|
+
|// frag: echo one
|
144
|
+
|// frag end
|
145
145
|
EOS
|
146
146
|
frag(option, '//', 'input').must_equal 0
|
147
147
|
(output.string + error.string).must_equal ''
|
148
148
|
File.read('input').must_equal <<-EOS.demargin
|
149
|
-
|//
|
149
|
+
|// frag: echo one
|
150
150
|
|one
|
151
|
-
|//
|
151
|
+
|// frag end
|
152
152
|
EOS
|
153
153
|
end
|
154
154
|
end
|
@@ -156,15 +156,15 @@ describe Frag::App do
|
|
156
156
|
['-t', '--trailer'].each do |option|
|
157
157
|
it "uses the delimiter trailer given by #{option}" do
|
158
158
|
write_file 'input', <<-EOS.demargin
|
159
|
-
|#
|
160
|
-
|#
|
159
|
+
|# frag: echo one !!
|
160
|
+
|# frag end !!
|
161
161
|
EOS
|
162
162
|
frag(option, '!!', 'input').must_equal 0
|
163
163
|
(output.string + error.string).must_equal ''
|
164
164
|
File.read('input').must_equal <<-EOS.demargin
|
165
|
-
|#
|
165
|
+
|# frag: echo one !!
|
166
166
|
|one
|
167
|
-
|#
|
167
|
+
|# frag end !!
|
168
168
|
EOS
|
169
169
|
end
|
170
170
|
end
|
@@ -188,21 +188,21 @@ describe Frag::App do
|
|
188
188
|
['-p', '--backup-prefix'].each do |option|
|
189
189
|
it "backs up the input file with the prefix given by #{option}" do
|
190
190
|
write_file 'input', <<-EOS.demargin
|
191
|
-
|#
|
191
|
+
|# frag: echo new
|
192
192
|
|old
|
193
|
-
|#
|
193
|
+
|# frag end
|
194
194
|
EOS
|
195
195
|
frag(option, 'path/to/backups', 'input').must_equal 0
|
196
196
|
(output.string + error.string).must_equal ''
|
197
197
|
File.read('input').must_equal <<-EOS.demargin
|
198
|
-
|#
|
198
|
+
|# frag: echo new
|
199
199
|
|new
|
200
|
-
|#
|
200
|
+
|# frag end
|
201
201
|
EOS
|
202
202
|
File.read("path/to/backups/#{File.expand_path('input')}").must_equal <<-EOS.demargin
|
203
|
-
|#
|
203
|
+
|# frag: echo new
|
204
204
|
|old
|
205
|
-
|#
|
205
|
+
|# frag end
|
206
206
|
EOS
|
207
207
|
end
|
208
208
|
end
|
@@ -210,57 +210,57 @@ describe Frag::App do
|
|
210
210
|
['-s', '--backup-suffix'].each do |option|
|
211
211
|
it "backs up the input file with the suffix given by #{option}" do
|
212
212
|
write_file 'input', <<-EOS.demargin
|
213
|
-
|#
|
213
|
+
|# frag: echo new
|
214
214
|
|old
|
215
|
-
|#
|
215
|
+
|# frag end
|
216
216
|
EOS
|
217
217
|
frag(option, '.backup', 'input').must_equal 0
|
218
218
|
(output.string + error.string).must_equal ''
|
219
219
|
File.read('input').must_equal <<-EOS.demargin
|
220
|
-
|#
|
220
|
+
|# frag: echo new
|
221
221
|
|new
|
222
|
-
|#
|
222
|
+
|# frag end
|
223
223
|
EOS
|
224
224
|
File.read('input.backup').must_equal <<-EOS.demargin
|
225
|
-
|#
|
225
|
+
|# frag: echo new
|
226
226
|
|old
|
227
|
-
|#
|
227
|
+
|# frag end
|
228
228
|
EOS
|
229
229
|
end
|
230
230
|
end
|
231
231
|
|
232
232
|
it "supports using --backup-prefix and --backup-suffix together" do
|
233
233
|
write_file 'input', <<-EOS.demargin
|
234
|
-
|#
|
234
|
+
|# frag: echo new
|
235
235
|
|old
|
236
|
-
|#
|
236
|
+
|# frag end
|
237
237
|
EOS
|
238
238
|
frag('-p', 'path/to/backups', '-s', '.backup', 'input').must_equal 0
|
239
239
|
(output.string + error.string).must_equal ''
|
240
240
|
File.read('input').must_equal <<-EOS.demargin
|
241
|
-
|#
|
241
|
+
|# frag: echo new
|
242
242
|
|new
|
243
|
-
|#
|
243
|
+
|# frag end
|
244
244
|
EOS
|
245
245
|
File.read("path/to/backups/#{File.expand_path('input')}.backup").must_equal <<-EOS.demargin
|
246
|
-
|#
|
246
|
+
|# frag: echo new
|
247
247
|
|old
|
248
|
-
|#
|
248
|
+
|# frag end
|
249
249
|
EOS
|
250
250
|
end
|
251
251
|
|
252
252
|
it "does not back up files which produces errors" do
|
253
253
|
write_file 'a', <<-EOS.demargin
|
254
|
-
|#
|
255
|
-
|#
|
254
|
+
|# frag: true
|
255
|
+
|# frag end
|
256
256
|
EOS
|
257
257
|
write_file 'b', <<-EOS.demargin
|
258
|
-
|#
|
259
|
-
|#
|
258
|
+
|# frag: false
|
259
|
+
|# frag end
|
260
260
|
EOS
|
261
261
|
write_file 'c', <<-EOS.demargin
|
262
|
-
|#
|
263
|
-
|#
|
262
|
+
|# frag: true
|
263
|
+
|# frag end
|
264
264
|
EOS
|
265
265
|
frag('-s', '.backup', 'a', 'b', 'c').must_equal 1
|
266
266
|
File.exist?('a.backup').must_equal true
|
@@ -271,27 +271,27 @@ describe Frag::App do
|
|
271
271
|
|
272
272
|
it "prints an error and leaves the input file unchanged if a command fails" do
|
273
273
|
write_file 'input', <<-EOS.demargin
|
274
|
-
|#
|
274
|
+
|# frag: echo new
|
275
275
|
|old
|
276
|
-
|#
|
277
|
-
|#
|
278
|
-
|#
|
276
|
+
|# frag end
|
277
|
+
|# frag: false
|
278
|
+
|# frag end
|
279
279
|
EOS
|
280
280
|
frag('input').must_equal 1
|
281
281
|
output.string.must_equal ''
|
282
282
|
error.string.must_match(/\b4:.*failed/)
|
283
283
|
File.read('input').must_equal <<-EOS.demargin
|
284
|
-
|#
|
284
|
+
|# frag: echo new
|
285
285
|
|old
|
286
|
-
|#
|
287
|
-
|#
|
288
|
-
|#
|
286
|
+
|# frag end
|
287
|
+
|# frag: false
|
288
|
+
|# frag end
|
289
289
|
EOS
|
290
290
|
end
|
291
291
|
|
292
292
|
it "prints an error if there's an unmatched beginning line" do
|
293
293
|
write_file 'input', <<-EOS.demargin
|
294
|
-
|#
|
294
|
+
|# frag: echo one
|
295
295
|
EOS
|
296
296
|
frag('input').must_equal 1
|
297
297
|
output.string.must_equal ''
|
@@ -300,7 +300,7 @@ describe Frag::App do
|
|
300
300
|
|
301
301
|
it "prints an error if there's an unmatched ending line" do
|
302
302
|
write_file 'input', <<-EOS.demargin
|
303
|
-
|#
|
303
|
+
|# frag end
|
304
304
|
EOS
|
305
305
|
frag('input').must_equal 1
|
306
306
|
output.string.must_equal ''
|
@@ -309,36 +309,36 @@ describe Frag::App do
|
|
309
309
|
|
310
310
|
it "continues processing other files if one of them produces an error" do
|
311
311
|
write_file 'a', <<-EOS.demargin
|
312
|
-
|#
|
312
|
+
|# frag: echo new
|
313
313
|
|old
|
314
|
-
|#
|
314
|
+
|# frag end
|
315
315
|
EOS
|
316
316
|
write_file 'b', <<-EOS.demargin
|
317
|
-
|#
|
317
|
+
|# frag: false
|
318
318
|
|old
|
319
|
-
|#
|
319
|
+
|# frag end
|
320
320
|
EOS
|
321
321
|
write_file 'c', <<-EOS.demargin
|
322
|
-
|#
|
322
|
+
|# frag: echo new
|
323
323
|
|old
|
324
|
-
|#
|
324
|
+
|# frag end
|
325
325
|
EOS
|
326
326
|
frag('a', 'b', 'c').must_equal 1
|
327
327
|
output.string.must_equal ''
|
328
328
|
File.read('a').must_equal <<-EOS.demargin
|
329
|
-
|#
|
329
|
+
|# frag: echo new
|
330
330
|
|new
|
331
|
-
|#
|
331
|
+
|# frag end
|
332
332
|
EOS
|
333
333
|
File.read('b').must_equal <<-EOS.demargin
|
334
|
-
|#
|
334
|
+
|# frag: false
|
335
335
|
|old
|
336
|
-
|#
|
336
|
+
|# frag end
|
337
337
|
EOS
|
338
338
|
File.read('c').must_equal <<-EOS.demargin
|
339
|
-
|#
|
339
|
+
|# frag: echo new
|
340
340
|
|new
|
341
|
-
|#
|
341
|
+
|# frag end
|
342
342
|
EOS
|
343
343
|
end
|
344
344
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: frag
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -64,7 +64,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
64
64
|
version: '0'
|
65
65
|
segments:
|
66
66
|
- 0
|
67
|
-
hash:
|
67
|
+
hash: -4503615734379659812
|
68
68
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
69
|
none: false
|
70
70
|
requirements:
|
@@ -73,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
73
73
|
version: '0'
|
74
74
|
segments:
|
75
75
|
- 0
|
76
|
-
hash:
|
76
|
+
hash: -4503615734379659812
|
77
77
|
requirements: []
|
78
78
|
rubyforge_project:
|
79
79
|
rubygems_version: 1.8.24
|