-
Notifications
You must be signed in to change notification settings - Fork 5
/
gen_readme.rb
executable file
·43 lines (30 loc) · 1 KB
/
gen_readme.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#! /usr/bin/env ruby
require 'pathname'
$VERBOSE=nil
def indent s, n = 2
ws = ' ' * n
s.gsub %r/^/, ws
end
template = IO::read 'README.tmpl'
samples = ''
prompt = '~ > '
Dir['sample*/*'].sort.each do |sample|
samples << "\n" << " <========< #{ sample } >========>" << "\n\n"
cmd = "cat #{ sample }"
samples << indent(prompt + cmd, 2) << "\n\n"
samples << indent(`#{ cmd }`, 4) << "\n"
cmd = "ruby #{ sample }"
#samples << indent(prompt + cmd, 2) << "\n\n"
cmd = "ruby -e'STDOUT.sync=true; exec %(ruby -Ilib #{ sample })'"
out = `#{ cmd } 2>&1`
#samples << indent(`#{ cmd } 2>&1`, 4) << "\n"
exitstatus = " #=> exitstatus=#{ $?.exitstatus }"
cmd = "ruby #{ sample }"
samples << indent(prompt + cmd + exitstatus, 2) << "\n\n"
samples << indent(out, 4) << "\n"
#samples << indent("\n#{ prompt } #{ $?.exitstatus } ### exitstatus\n")
end
#samples.gsub! %r/^/, ' '
readme = template.gsub %r/^\s*@samples\s*$/, samples
open('README', 'w'){|fd| fd.write readme}
print readme