Class: VagrantPlugins::DockerNSEnter::Command::NSEnter

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-docker-nsenter/command/nsenter.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.synopsisObject



5
6
7
# File 'lib/vagrant-docker-nsenter/command/nsenter.rb', line 5

def self.synopsis
  "Use nsenter to start a command in a running container."
end

Instance Method Details

#executeObject



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
# File 'lib/vagrant-docker-nsenter/command/nsenter.rb', line 9

def execute
  options = {}
  options[:interactive] = true
  options[:prefix] = true

  opts = OptionParser.new do |o|
    o.banner = "Usage: vagrant docker-nsenter [command...]"
    o.separator ""
    o.separator "Options:"
    o.separator ""

    o.on("--[no-]interactive", "Run the command interactively") do |i|
      options[:interactive] = i
    end

    o.on("--[no-]prefix", "Prefix the output with the machine name") do |p|
      options[:prefix] = p
    end

  end

  # Parse out the extra args to send to nsenter, 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 = parse_options(opts)
  return if !argv

  # Assume /bin/bash if no command is provided.
  if !split_index
    command = ["/bin/bash"]
  end

  target_opts = { provider: :docker }
  target_opts[:single_target] = options[:pty]

  with_target_vms(argv, target_opts) do |machine|
    # Run it!
    execute_single(machine, options, command)
  end
  0
end