class VagrantPlugins::RemoteShell
Public Class Methods
new(communication, machine)
click to toggle source
# File lib/niman/vagrant/shell.rb, line 3 def initialize(communication, machine) @channel = communication @machine = machine @platform = Niman::Platform.new(ruby_platform) end
Public Instance Methods
create_file(path, content, use_sudo=false)
click to toggle source
# File lib/niman/vagrant/shell.rb, line 48 def create_file(path, content, use_sudo=false) if content.include?("\n") cmd = "cat > #{path} << EOL\n#{content}\nEOL" else cmd = "echo #{content} > #{path}" end self.exec(cmd, use_sudo) end
exec(command, use_sudo=false)
click to toggle source
# File lib/niman/vagrant/shell.rb, line 19 def exec(command, use_sudo=false) @machine.ui.info(command, {color: :green}) opts = { error_check: false, elevated: use_sudo } handler = Proc.new do |type, data| if [:stderr, :stdout].include?(type) color = type == :stdout ? :green : :red data = data.chomp next if data.empty? options = {} options[:color] = :green @machine.ui.info(data.chomp, options) end end if use_sudo @channel.sudo(command, opts, &handler) else @channel.execute(command, opts, &handler) end end
os()
click to toggle source
# File lib/niman/vagrant/shell.rb, line 9 def os if @platform.linux? variant = @platform.linux_variant(-> (fn){ @machine.communicate.test("cat #{fn}")}, -> (fn){ @channel.execute("cat #{fn}") { |type, data| data.chomp}}) variant[:family] else raise Niman::UnsupportedOSError end end
print(message, type)
click to toggle source
# File lib/niman/vagrant/shell.rb, line 39 def print(message, type) case type when :error @machine.ui.error(message, {:color => :red}) else @machine.ui.info(message, {:color => :green}) end end
Private Instance Methods
ruby_platform()
click to toggle source
# File lib/niman/vagrant/shell.rb, line 59 def ruby_platform @channel.execute("ruby -e 'puts RUBY_PLATFORM'") do |type, data| return data.chomp end end