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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
# File 'lib/hsdeploy/command.rb', line 37
def self.run(command, args)
if args.include?("--debug")
args.delete("--debug")
$logger.level = Logger::DEBUG
elsif args.include?("-d")
args.delete("-d")
$logger.level = Logger::DEBUG
elsif args.include?("-v")
args.delete("-v")
$logger.level = Logger::DEBUG
else
$logger.level = Logger::INFO
end
change_to_toplevel_dir!
HSDeploy::Config.load(".hsdeployrc")
if command == "help"
print_help
elsif command == "add"
if args[0].nil?
puts "ERROR: Missing target name."
puts ""
puts "Use \"deploy help\" if you're lost."
exit
end
if args[1].nil?
puts "ERROR: Missing target specification."
puts ""
puts "Use \"deploy help\" if you're lost."
exit
end
unless target = HSDeploy::Target.find(args[1])
puts "ERROR: Couldn't find provider for target \"#{args[1]}\""
puts ""
puts "Use \"deploy help\" if you're lost."
exit
end
if target.respond_to?(:verify)
target.verify
end
HSDeploy::Config[args[0]] = target.to_h
elsif command == "list"
puts "Registered Targets:"
HSDeploy::Config.all.each do |target_name, target|
target = HSDeploy::Target.from_config(target)
puts " %s%s" % [target_name.ljust(15), target.to_s]
end
elsif command == "run"
target_name, target = find_target args.shift
begin
command = args.join(' ').strip
if command.empty?
puts "ERROR: Must specify command to be run.\n\n"
print_help
exit 2
end
target.exec(command)
rescue => e
handle_target_exception e
end
else
args.unshift command unless command == "to"
target_name, target = find_target args.shift
opts = {}
opts[:timing] = true if args.include?("--timing")
begin
target.push(opts)
rescue => e
handle_target_exception e
end
end
if target_name and target
HSDeploy::Config[target_name] = target.to_h
end
HSDeploy::Config.save
rescue Net::HTTPServerException => e
$logger.info "ERROR: HTTP call returned %s %s" % [e.response.code, e.response.message]
if target
$logger.debug "\nTarget:"
target.to_h.each do |k, v|
next if k.to_sym == :password
$logger.debug " %s = %s" % [k, v]
end
end
$logger.debug "\nBacktrace:"
$logger.debug " " + e.backtrace.join("\n ")
$logger.debug "\nResponse:"
e.response. do |k, v|
$logger.debug " %s: %s" % [k, v]
end
$logger.debug "\n " + e.response.body.gsub("\n", "\n ")
$logger.info "\nPlease run again with \"--debug\" and report the output at http://j.mp/hsdeploy-issue"
exit 2
end
|