#!/usr/bin/ruby

require 'pathname'
gem_root = Pathname.new(File.expand_path("../..", __FILE__))
scripts_dir = gem_root + 'share' + 'scripts'

subcommand = ARGV[0] || '__nosuch__'
subcommand_path = scripts_dir + subcommand

if subcommand_path.file?
  ARGV.shift
  Kernel.exec subcommand_path.to_s, *ARGV
else
  home_dir = ENV['HOME']
  home_pat = /^#{home_dir}/
  ENV['PATH'] = ENV['PATH'].split(':').delete_if{ |path| path =~ home_pat }.join(':')
  docker_bin_path = `which docker`.chomp
  Kernel.exec docker_bin_path, *ARGV
end
