Class: VagrantPlugins::RemoteShell
- Inherits:
-
Object
- Object
- VagrantPlugins::RemoteShell
- Defined in:
- lib/niman/vagrant/shell.rb
Instance Method Summary collapse
- #create_file(path, content, use_sudo = false) ⇒ Object
- #exec(command, use_sudo = false) ⇒ Object
-
#initialize(communication, machine) ⇒ RemoteShell
constructor
A new instance of RemoteShell.
- #os ⇒ Object
- #print(message, type) ⇒ Object
Constructor Details
#initialize(communication, machine) ⇒ RemoteShell
Returns a new instance of RemoteShell.
3 4 5 6 7 |
# File 'lib/niman/vagrant/shell.rb', line 3 def initialize(communication, machine) @channel = communication @machine = machine @platform = Niman::Platform.new(ruby_platform) end |
Instance Method Details
#create_file(path, content, use_sudo = false) ⇒ Object
48 49 50 51 52 53 54 55 |
# 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) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# 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? = {} [:color] = :green @machine.ui.info(data.chomp, ) end end if use_sudo @channel.sudo(command, opts, &handler) else @channel.execute(command, opts, &handler) end end |
#os ⇒ Object
9 10 11 12 13 14 15 16 17 |
# 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) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/niman/vagrant/shell.rb', line 39 def print(, type) case type when :error @machine.ui.error(, {:color => :red}) else @machine.ui.info(, {:color => :green}) end end |