summaryrefslogtreecommitdiff
path: root/lib/bundler08/commands/exec_command.rb
blob: 5ee1862b6ddd6203fcc35fc6e92f9e1244ba37d4 (plain)
1
2
3
4
5
6
7
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
combined = [File.basename($0)] + ARGV
gem_i  = combined.index("gem")
exec_i = combined.index("exec")

if gem_i && exec_i && gem_i < exec_i
  exec = ARGV.index("exec")
  $command = ARGV[(exec + 1)..-1]
  ARGV.replace ARGV[0..exec]
end

class Gem::Commands::ExecCommand < Gem::Command

  def initialize
    super('exec', 'Run a command in context of a gem bundle', {:manifest => nil})

    add_option('-m', '--manifest MANIFEST', "Specify the path to the manifest file") do |manifest, options|
      options[:manifest] = manifest
    end
  end

  def usage
    "#{program_name} COMMAND"
  end

  def arguments # :nodoc:
    "COMMAND  command to run in context of the gem bundle"
  end

  def description # :nodoc:
    <<-EOF.gsub('      ', '')
      Run in context of a bundle
    EOF
  end

  def execute
    # Prevent the bundler from getting required unless it is actually being used
    require 'bundler08'
    Bundler::CLI.run(:exec, options)
  end

end