Sha256: b5047221ab1f6ea7e4397ac7eac5b73d69a34645e6016c4cf2395996e38970af
Contents?: true
Size: 1.79 KB
Versions: 21
Compression:
Stored size: 1.79 KB
Contents
require 'optparse' require "vagrant/util/safe_puts" module VagrantPlugins module CommandWinRM class Command < Vagrant.plugin("2", :command) include Vagrant::Util::SafePuts def self.synopsis "executes commands on a machine via WinRM" end def execute options = { command: [], shell: :powershell } opts = OptionParser.new do |o| o.banner = "Usage: vagrant winrm [options] [name|id]" o.separator "" o.separator "Options:" o.separator "" o.on("-c", "--command COMMAND", "Execute a WinRM command directly") do |c| options[:command] << c end o.on("-e", "--elevated", "Run with elevated credentials") do |e| options[:elevated] = true end o.on("-s", "--shell SHELL", [:powershell, :cmd], "Use specified shell (powershell, cmd)") do |s| options[:shell] = s end end argv = parse_options(opts) return if !argv with_target_vms(argv, single_target: true) do |machine| if machine.config.vm.communicator != :winrm raise Vagrant::Errors::WinRMInvalidCommunicator end opts = { shell: options[:shell], elevated: !!options[:elevated] } options[:command].each do |cmd| begin machine.communicate.execute(cmd, opts) do |type, data| io = type == :stderr ? $stderr : $stdout safe_puts(data, io: io, printer: :print) end rescue VagrantPlugins::CommunicatorWinRM::Errors::WinRMBadExitStatus return 1 end end end # Success, exit status 0 0 end end end end
Version data entries
21 entries across 21 versions & 3 rubygems