Class: VagrantPlugins::DockerExec::Command
- Inherits:
-
Object
- Object
- VagrantPlugins::DockerExec::Command
- Defined in:
- lib/vagrant-docker-exec/command/exec.rb,
lib/vagrant-docker-exec/command/shell.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.synopsis ⇒ Object
4 5 6 |
# File 'lib/vagrant-docker-exec/command/exec.rb', line 4 def self.synopsis "run a new command in a running docker container" end |
Instance Method Details
#exec_command(machine, options, command) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/vagrant-docker-exec/command/exec.rb', line 64 def exec_command(machine, , command) exec_cmd = %W(docker exec) exec_cmd << "-i" << "-t" if [:pty] exec_cmd << machine.id.to_s exec_cmd += [:extra_args] if [:extra_args] exec_cmd.concat(command) # Run this interactively if asked. = [:stdin] = true if [:pty] #@env.ui.info(exec_cmd.flatten) output = "" machine.provider.driver.execute(*exec_cmd, ) do |type, data| output += data end = {} machine.ui.output(output.chomp!, **) if !output.empty? end |
#execute ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/vagrant-docker-exec/command/exec.rb', line 8 def execute = {} [:detach] = false [:pty] = false opts = OptionParser.new do |o| o. = "Usage: vagrant docker-exec [command...]" o.separator "" o.separator "Options:" o.separator "" o.on("--[no-]detach", "Run in the background") do |d| [:detach] = d end o.on("-t", "--[no-]tty", "Allocate a pty") do |t| [:pty] = t end end # Parse out the extra args to send to SSH, which is everything # after the "--" command = nil split_index = @argv.index("--") if split_index command = @argv.drop(split_index + 1) @argv = @argv.take(split_index) end # Parse the options argv = (opts) return if !argv # Show the error if we don't have "--" _after_ parse_options # so that "-h" and "--help" work properly. if !split_index @env.ui.error(I18n.t("vagrant_docker_exec.exec_command_required")) return 1 end target_opts = { provider: :docker } target_opts[:single_target] = [:pty] with_target_vms(argv, target_opts) do |machine| if machine.state.id != :running @env.ui.info("#{machine.id} is not running.") next end # Run it! exec_command(machine, , command) end return 0 end |