Sha256: 57c1af64d9540e549f74fbab2df778d5de533c114a94bfdcfd5129cfaa5493b6

Contents?: true

Size: 1.46 KB

Versions: 2

Compression:

Stored size: 1.46 KB

Contents

require 'optparse'

module VagrantPlugins
  module CommandBox
    module Command
      class Add < Vagrant.plugin("2", :command)
        def execute
          options = {}

          opts = OptionParser.new do |o|
            o.banner = "Usage: vagrant box add <name> <url> [--provider provider] [-h]"
            o.separator ""

            o.on("-f", "--force", "Overwrite an existing box if it exists.") do |f|
              options[:force] = f
            end

            o.on("--provider provider", String,
                 "The provider that backs the box.") do |p|
              options[:provider] = p
            end
          end

          # Parse the options
          argv = parse_options(opts)
          return if !argv
          raise Vagrant::Errors::CLIInvalidUsage, :help => opts.help.chomp if argv.length < 2

          # If we're force adding, then be sure to destroy any existing box if it
          # exists.
          if options[:force]
            existing = @env.boxes.find(argv[0], :virtualbox)
            existing.destroy! if existing
          end

          # Get the provider if one was set
          provider = nil
          provider = options[:provider].to_sym if options[:provider]

          @env.action_runner.run(Vagrant::Action.action_box_add, {
            :box_name     => argv[0],
            :box_provider => provider,
            :box_url      => argv[1]
          })

          # Success, exit status 0
          0
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
vagrant-actionio-0.0.9 vendor/bundle/bundler/gems/vagrant-c74251a1d9c0/plugins/commands/box/command/add.rb
vagrant-lxc-0.0.1 vendor/vagrant/plugins/commands/box/command/add.rb