/
jello
executable file
·85 lines (69 loc) · 2.05 KB
/
jello
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env ruby -Ku
($:.unshift File.expand_path(File.join( File.dirname(__FILE__), '..', 'lib' ))).uniq!
%w[jello rubygems optparse].each {|dep| require dep }
options = Hash.new
OptionParser.new do |opts|
opts.banner = "\
= Jello =
Moulds may be any string that matches a part of a path of a Ruby file relative\
to one of the entries in the Jello search path:
- ~/.jello
- /etc/jello
- <`gem contents jello`>/moulds
If a file matches earlier in the search path, later ones that also match will\
be ignored.
A directory may match, in which case all Ruby files in that directory will be\
utilized.
The follow moulds are included for your enjoyment:
- jello say
- jello grabup_fixer
- jello shortener
== Usage ==
`jello [options] <mould> (<mould> <mould> …)`
"
opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
options[:verbose] = v
end
opts.on("-d", "--[no-]debug", "Run extremely verbosely") do |d|
$-d = d
end
opts.on("-f", "--[no-]feedback", "Feedback on successful process") do |f|
options[:feedback] = f
end
opts.on("-p", "--period PERIOD", "Period over which to cycle watcher process") do |p|
options[:period] = p
end
opts.on("-D", "--[no-]daemonize", "Fork the process") do |dd|
options[:daemonize] = dd
end
opts.on_tail("--help", "Show this help") do
puts opts
exit
end
opts.on_tail("--version", "Show version") do
puts "I'm Jello #{Jello::Version}!"
exit
end
end.parse!
ARGV.each do |mould|
mould_file = Jello::Mould.find(mould)
require mould_file if mould_file
puts "!! Unable to locate any moulds matching '#{mould}'!" unless mould_file
end
# http://github.com/chneukirchen/rack/tree/ed86dfd676dcb46e276b6906f017df514e5632f9/bin/rackup#L153-164
if options[:daemonize]
if RUBY_VERSION < "1.9"
exit if fork
Process.setsid
exit if fork
Dir.chdir "/"
File.umask 0000
STDIN.reopen "/dev/null"
STDOUT.reopen "/dev/null", "a"
STDERR.reopen "/dev/null", "a"
else
Process.daemon
end
end
$0 = "jello: #{ARGV.join ', '}"
Jello.start! options