Class: Cli
- Inherits:
-
Object
- Object
- Cli
- Includes:
- ClusterBomb::Bomb
- Defined in:
- lib/cluster_bomb/cli.rb
Constant Summary
Constants included from ClusterBomb::Logging
ClusterBomb::Logging::DEFAULT_LOGFILENAME
Instance Attribute Summary
Attributes included from ClusterBomb::Bomb
#auto_reload, #configuration, #env, #interactive, #sudo_mode, #username
Instance Method Summary collapse
-
#initialize ⇒ Cli
constructor
A new instance of Cli.
- #main ⇒ Object
- #process_args ⇒ Object
Methods included from ClusterBomb::Bomb
#clear, #clear_env!, #desc, #disconnect!, #download, #ensure_var, #exec, #exists?, #get_task, #group, #hosts, #interactive?, #load, #load_str, #reconnect!, #reload, #role_list, #run, #server_list_from_options, #set, #switch_user, #task, #task_list, #upload, #valid_task?
Methods included from ClusterBomb::Logging
log, log_disable, log_enable, log_init, puts, #puts
Methods included from Roles
#clear_role, #role, #servers, #valid_role?
Constructor Details
#initialize ⇒ Cli
Returns a new instance of Cli.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/cluster_bomb/cli.rb', line 6 def initialize @execution_environment={} super self.load File.join(File.dirname(__FILE__),'stdtasks.rb') if File.exists? 'Bombfile' self.load 'Bombfile' else puts "WARNING: no Bombfile in current directory" end end |
Instance Method Details
#main ⇒ Object
75 76 77 78 79 |
# File 'lib/cluster_bomb/cli.rb', line 75 def main process_args switch_user(@user) if @user exec @task, {:roles=>@execution_environment[:roles], :hosts=>@execution_environment[:hosts]} end |
#process_args ⇒ Object
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 |
# File 'lib/cluster_bomb/cli.rb', line 16 def process_args if ARGV.length < 1 puts "syntax: cb <task> [options]" puts "available tasks: " @tasks.each do |n,t| puts " #{t.name} - #{t.description}" end exit end @task=ARGV[0].to_sym # Get program opts opts = GetoptLong.new( [ '--logfile', '-l', GetoptLong::REQUIRED_ARGUMENT ], [ '--logmode', GetoptLong::REQUIRED_ARGUMENT ], [ '--user', GetoptLong::REQUIRED_ARGUMENT ], [ '--nolog', GetoptLong::NO_ARGUMENT ] ) logfile=nil logmode=nil nolog=false @user=nil opts.each do |opt, arg| case opt when '--logfile' logfile=arg when '--logmode' raise "valid log modes are a or w" unless ['a','w'].include? arg logmode=arg when '--nolog' nolog=true when '--user' @user=arg end end if logfile && !logmode logmode='a' end unless nolog ClusterBomb::Logging.log_init ClusterBomb::Logging.log_enable(logfile,logmode) end # Set up environment, with special attention to roles ARGV[1..-1].each do |arg| pair = arg.split('=') if pair.length == 2 k = pair[0].strip.to_sym if k == :roles list=pair[1].split(',').collect{|r|r.strip.to_sym} @execution_environment[:roles]=list elsif k == :hosts list=pair[1].split(',').collect{|r|r.strip} @execution_environment[:hosts]=list else self.set(k,pair[1].strip) end end end end |