lib/pec2/cli.rb in pec2-0.3.2 vs lib/pec2/cli.rb in pec2-0.4.0

- old
+ new

@@ -1,7 +1,9 @@ require "thor" require "tempfile" +require "logger" +require 'shellwords' module Pec2 class CLI < Thor map '-v' => :version @@ -9,11 +11,12 @@ def initialize(args = [], options = {}, config = {}) super(args, options, config) @global_options = config[:shell].base.options @core = Core.new - @pssh_path = `which pssh`.strip + @pssh_path = File.expand_path('../../../exe/bin/pssh', __FILE__) + @logger = Logger.new(STDOUT) end desc 'search_tag', 'search tag' option :command, aliases: '-c', type: :string, required: true, desc: 'command' option :sudo_password, aliases: '-s', type: :string, desc: 'sudo_password' @@ -27,11 +30,12 @@ addresses = @core.instances_hash(options[:tag]).map do |instance| instance.private_ip_address end if addresses.empty? - raise "no host." + @logger.error(%Q{no host tag #{options[:tag]}.}) + raise end File.write(f.path, addresses.join("\n")) cmd = "#{@pssh_path} -t 0 -x '-tt' -h #{f.path} -O StrictHostKeyChecking=no" @@ -50,12 +54,12 @@ if options[:parallel] cmd = "#{cmd} -p #{options[:parallel]}" end if options[:sudo_password] - cmd = %Q{(echo #{options[:sudo_password]}) | #{cmd} -I '#{options[:command]}'} + cmd = %Q{(echo #{options[:sudo_password]}) | #{cmd} -I #{Shellwords.escape(options[:command])}} else - cmd = %Q{#{cmd} -i '#{options[:command]}'} + cmd = %Q{#{cmd} -i #{Shellwords.escape(options[:command])}} end system(cmd) end end