bin/i2cssh in i2cssh-1.4.0 vs bin/i2cssh in i2cssh-1.4.1

- old
+ new

@@ -1,11 +1,11 @@ #!/usr/bin/ruby require 'rubygems' require 'optparse' require 'i2cssh' require 'yaml' -require 'pp' + config_file = File.expand_path "~/.i2csshrc" i2_options, ssh_options, servers, clusters, login_from_cli = {}, [], [], {}, false if File.exists?(config_file) @@ -26,11 +26,11 @@ end end optparse = OptionParser.new do |opts| - opts.banner = "Usage: #{File.basename(__FILE__)} [options]" + opts.banner = "Usage: #{File.basename(__FILE__)} [options] [username@host [username@host]]" # Check if we have a cluster. opts.on '-c', '--cluster CLUSTERNAME', 'Name of the cluster specified in ~/.i2csshrc' do |c| @@ -46,27 +46,25 @@ i2_options[:login_override] = cluster["login"] || i2_options[:login_override] i2_options[:login_override] = login_from_cli if login_from_cli i2_options[:broadcast] = cluster["broadcast"] || i2_options[:broadcast] + if i2_options[:login_override] then + cluster_hosts = cluster_hosts.map{|h| "#{i2_options[:login_override]}@#{h}"} + end + servers += cluster_hosts else puts "ERROR: unknown cluster #{c}" puts optparse.help exit 1 end end opts.on '-m', '--machines a,b,c', Array, 'Comma-separated list of hosts' do |h| - h.each do |host| - if host =~ /(.+)@(.+)/ then - i2_options[:login_override] = $1 - host = $2 - end - servers << host - end + servers += h end # Hosts opts.on '-f', '--file FILE', 'Cluster file (one hostname per line)' do |f| @@ -124,11 +122,15 @@ end end optparse.parse! +if ARGV.length > 0 then + servers = ARGV +end + if i2_options[:login_override] then - ssh_options << "-l #{i2_options[:login_override]}" + servers = servers.map{|h| "#{i2_options[:login_override]}@#{h.gsub(/.+@/,'')}"} end if servers.empty? puts "ERROR: no servers given" puts optparse.help