"Fossies" - the Fresh Open Source Software Archive

Member "vagrant-2.2.14/plugins/commands/box/command/add.rb" (20 Nov 2020, 3441 Bytes) of package /linux/misc/vagrant-2.2.14.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Ruby source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 require 'optparse'
    2 
    3 require_relative 'download_mixins'
    4 
    5 module VagrantPlugins
    6   module CommandBox
    7     module Command
    8       class Add < Vagrant.plugin("2", :command)
    9         include DownloadMixins
   10 
   11         def execute
   12           options = {}
   13 
   14           opts = OptionParser.new do |o|
   15             o.banner = "Usage: vagrant box add [options] <name, url, or path>"
   16             o.separator ""
   17             o.separator "Options:"
   18             o.separator ""
   19 
   20             o.on("-c", "--clean", "Clean any temporary download files") do |c|
   21               options[:clean] = c
   22             end
   23 
   24             o.on("-f", "--force", "Overwrite an existing box if it exists") do |f|
   25               options[:force] = f
   26             end
   27 
   28             build_download_options(o, options)
   29 
   30             o.on("--location-trusted", "Trust 'Location' header from HTTP redirects and use the same credentials for subsequent urls as for the initial one") do |l|
   31                 options[:location_trusted] = l
   32             end
   33 
   34             o.on("--provider PROVIDER", String, "Provider the box should satisfy") do |p|
   35               options[:provider] = p
   36             end
   37 
   38             o.on("--box-version VERSION", String, "Constrain version of the added box") do |v|
   39               options[:version] = v
   40             end
   41 
   42             o.separator ""
   43             o.separator "The box descriptor can be the name of a box on HashiCorp's Vagrant Cloud,"
   44             o.separator "or a URL, or a local .box file, or a local .json file containing"
   45             o.separator "the catalog metadata."
   46             o.separator ""
   47             o.separator "The options below only apply if you're adding a box file directly,"
   48             o.separator "and not using a Vagrant server or a box structured like 'user/box':"
   49             o.separator ""
   50 
   51             o.on("--checksum CHECKSUM", String, "Checksum for the box") do |c|
   52               options[:checksum] = c
   53             end
   54 
   55             o.on("--checksum-type TYPE", String, "Checksum type (md5, sha1, sha256)") do |c|
   56               options[:checksum_type] = c.to_sym
   57             end
   58 
   59             o.on("--name BOX", String, "Name of the box") do |n|
   60               options[:name] = n
   61             end
   62           end
   63 
   64           # Parse the options
   65           argv = parse_options(opts)
   66           return if !argv
   67           if argv.empty? || argv.length > 2
   68             raise Vagrant::Errors::CLIInvalidUsage,
   69               help: opts.help.chomp
   70           end
   71 
   72           url = argv[0]
   73           if argv.length == 2
   74             options[:name] = argv[0]
   75             url = argv[1]
   76           end
   77 
   78           @env.action_runner.run(Vagrant::Action.action_box_add, {
   79             box_url: url,
   80             box_name: options[:name],
   81             box_provider: options[:provider],
   82             box_version: options[:version],
   83             box_checksum_type: options[:checksum_type],
   84             box_checksum: options[:checksum],
   85             box_clean: options[:clean],
   86             box_force: options[:force],
   87             box_download_ca_cert: options[:ca_cert],
   88             box_download_ca_path: options[:ca_path],
   89             box_download_client_cert: options[:client_cert],
   90             box_download_insecure: options[:insecure],
   91             box_download_location_trusted: options[:location_trusted],
   92             ui: Vagrant::UI::Prefixed.new(@env.ui, "box"),
   93           })
   94 
   95           # Success, exit status 0
   96           0
   97         end
   98       end
   99     end
  100   end
  101 end