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
86
87
88
89
90
|
# File 'lib/octosh/cli.rb', line 18
def self.start
options = OpenStruct.new
optparse = OptionParser.new do|opts|
opts.banner = "Usage: octosh [options] [octo config file]"
opts.on('-c', '--config FILE', 'Octo config file') do |file|
options.config = file
end
opts.on('-b', '--bash COMMAND', 'Explicitly define a command(s) to run on all hosts (Requires --hosts switch)') do |bash|
options.bash = bash
end
opts.on('-s', '--script SCRIPT', 'Path to script to run on all hosts (Requires --hosts switch)') do |script|
options.script = script
end
opts.on('-r', '--hosts USER@HOST,USER@HOST', Array, 'Lists of hosts to use when using inline execution (with -b or -s switches)') do |list|
options.hosts = list
end
options.default_user = "root"
opts.on('-u', '--user USER', 'User to use when a user isn\'t defined in the --hosts list (ie. just IP address)') do |user|
options.default_user = user
end
options.password_prompt = true
options.uniform_password = false
opts.on('-p', '--uniform-password', 'Uniform password') do
options.uniform_password = true
end
opts.on_tail('-h', '--help', 'Display this screen' ) do
puts opts
exit
end
end.parse!
if not ARGV.empty? and not options.config
puts "Using config file"
options.config = ARGV[0]
options.mode = Octosh::CLI::MODE::CONFIG
elsif ARGV.empty? and options.config
puts "Using config file"
options.mode = Octosh::CLI::MODE::CONFIG
elsif not ARGV.empty? and options.config
puts "Two config files specified (#{options.config} and #{ARGV[0]}), using explicit config file (#{options.config})"
options.mode = Octosh::CLI::MODE::CONFIG
elsif (options.bash or options.script) and options.hosts
puts "Using inline execution"
options.mode = Octosh::CLI::MODE::INLINE
if options.bash and options.script
"Error -- Cannot specify both an inline command to run (-b) and a script file (-s)"
exit
elsif options.bash
puts "Inline bash"
self.inline_bash(options.hosts, options.bash, options.default_user, options.password_prompt, options.uniform_password)
elsif options.script
puts "Call script on each server"
self.exec_script(options.hosts, options.script, options.default_user, options.password_prompt, options.uniform_password)
else
"Error -- Something broke"
exit
end
else
puts "Error -- Must either provide an Octo config file or arguments for inline execution (--hosts along with -b or -s)"
exit
end
end
|