Sha256: 5e91651e557888c228f199bc274f9ed28c02e764967c45bcf1108ca6bf46026c

Contents?: true

Size: 1.96 KB

Versions: 5

Compression:

Stored size: 1.96 KB

Contents

require 'optparse'

module Vagrant
  module Command
    class Package < Base
      def execute
        options = {}

        opts = OptionParser.new do |opts|
          opts.banner = "Usage: vagrant package [vm-name] [--base name] [--output name.box]"
          opts.separator "                       [--include one,two,three] [--vagrantfile file]"

          opts.separator ""

          opts.on("--base NAME", "Name of a VM in virtualbox to package as a base box") do |b|
            options[:base] = b
          end

          opts.on("--output NAME", "Name of the file to output") do |o|
            options[:output] = o
          end

          opts.on("--include x,y,z", Array, "Additional files to package with the box.") do |i|
            options[:include] = i
          end

          opts.on("--vagrantfile file", "Vagrantfile to package with the box.") do |v|
            options[:vagrantfile] = v
          end
        end

        # Parse the options
        argv = parse_options(opts)
        return if !argv

        @logger.debug("package options: #{options.inspect}")
        if options[:base]
          package_base(options)
        else
          package_target(argv[0], options)
        end
      end

      protected

      def package_base(options)
        vm = VM.new(options[:base], @env, @env.config.global, :base => true)
        raise Errors::BaseVMNotFound, :name => options[:base] if !vm.created?
        @logger.debug("Packaging base VM: #{vm.name}")
        package_vm(vm, options)
      end

      def package_target(name, options)
        with_target_vms(name, :single_target => true) do |vm|
          raise Errors::VMNotCreatedError if !vm.created?
          @logger.debug("Packaging VM: #{vm.name}")
          package_vm(vm, options)
        end
      end

      def package_vm(vm, options)
        opts = options.inject({}) do |acc, data|
          k,v = data
          acc["package.#{k}"] = v
          acc
        end

        vm.package(opts)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
vagrantup-1.0.1 lib/vagrant/command/package.rb
vagrantup-1.0.0 lib/vagrant/command/package.rb
vagrantup-0.9.99.2 lib/vagrant/command/package.rb
vagrant-1.0.1 lib/vagrant/command/package.rb
vagrant-1.0.0 lib/vagrant/command/package.rb