blob: 7b9dffbd688f47680880038548035b529a1ff85a (
plain)
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
|
#!/usr/bin/ruby
%w[socket fileutils yaml]
.map { require _1 }
HOME = ENV["HOME"] or File.expand_path "~/"
HOSTNAME = Socket.gethostname
class Binding
def eval_file(path)
self.eval (File.read path)
end
end
def eval_file(file)
file = File.expand_path file
dir = File.dirname file
binding.eval_file file
end
def ls(dir)
Dir.entries(dir).reject {|d| [".", ".."].include? d }
end
def ln(from, to)
FileUtils.ln_s from, to
end
def write(file, contents)
File.write file, contents
end
def rm(file)
FileUtils.rm file
end
def mkdir(dir)
FileUtils.mkdir_p dir
end
def rmdir(dir)
FileUtils.rmdir dir
end
require_relative "core"
require_relative "stdlib"
$cmds = {
show: lambda {|op|
if op.is_a? Deploy
puts op.ops
else
puts op
end
},
debug: lambda {|op|
puts op.to_yaml
},
check: lambda {|op|
if op.check
puts "nothing left to do"
else
puts "not fully deployed"
end
},
do: lambda {|op| op.do },
undo: lambda {|op| op.undo },
}
def main
command = ARGV.shift.to_sym
file = ARGV.shift || "#{HOSTNAME}.rb"
op = eval_file file
$cmds[command][op]
end
main if __FILE__ == $0
|