Sha256: 8959d1ac9b81c71bddc70aa46b19d166286f1083b1bbe932c761cf407ae941cc

Contents?: true

Size: 1.74 KB

Versions: 58

Compression:

Stored size: 1.74 KB

Contents

require "set"

module VagrantPlugins
  module CommandUp
    module StartMixins
      # This adds the standard `start` command line flags to the given
      # OptionParser, storing the result in the `options` dictionary.
      #
      # @param [OptionParser] parser
      # @param [Hash] options
      def build_start_options(parser, options)
        # Setup the defaults
        options[:provision_types] = nil

        # Add the options
        parser.on("--[no-]provision", "Enable or disable provisioning") do |p|
          options[:provision_enabled] = p
          options[:provision_ignore_sentinel] = true
        end

        parser.on("--provision-with x,y,z", Array,
                "Enable only certain provisioners, by type or by name.") do |list|
          options[:provision_types] = list.map { |type| type.to_sym }
          options[:provision_enabled] = true
          options[:provision_ignore_sentinel] = true
        end
      end

      # This validates the provisioner flags and raises an exception
      # if there are invalid ones.
      def validate_provisioner_flags!(options, argv)
        if options[:provision_types].nil?
          return
        end

        provisioner_names = Set.new
        with_target_vms(argv) do |machine|
          machine.config.vm.provisioners.map(&:name).each do |name|
            provisioner_names.add(name)
          end
        end

        if (provisioner_names & options[:provision_types]).empty?
          (options[:provision_types] || []).each do |type|
              klass = Vagrant.plugin("2").manager.provisioners[type]
              if !klass
                raise Vagrant::Errors::ProvisionerFlagInvalid,
                  name: type.to_s
              end
          end
        end
      end
    end
  end
end

Version data entries

58 entries across 54 versions & 6 rubygems

Version Path
vagrant-unbundled-2.3.6.0 plugins/commands/up/start_mixins.rb
tamtam-vagrant-reload-1.2.1 vendor/cache/vagrant-2092df529ae7/plugins/commands/up/start_mixins.rb
vagrant-unbundled-2.3.3.0 plugins/commands/up/start_mixins.rb
vagrant-unbundled-2.3.2.0 plugins/commands/up/start_mixins.rb
vagrant-unbundled-2.2.19.0 plugins/commands/up/start_mixins.rb
vagrant-unbundled-2.2.18.0 plugins/commands/up/start_mixins.rb
vagrant-unbundled-2.2.16.0 plugins/commands/up/start_mixins.rb
vagrant-unbundled-2.2.14.0 plugins/commands/up/start_mixins.rb
vagrant-aws-mkubenka-0.7.2.pre.24 vendor/bundle/ruby/2.7.0/bundler/gems/vagrant-22795b161bf6/plugins/commands/up/start_mixins.rb
vagrant-unbundled-2.2.10.0 plugins/commands/up/start_mixins.rb
vagrant-unbundled-2.2.9.0 plugins/commands/up/start_mixins.rb
vagrant-unbundled-2.2.8.0 plugins/commands/up/start_mixins.rb
vagrant-unbundled-2.2.7.0 plugins/commands/up/start_mixins.rb
vagrant-unbundled-2.2.6.2 plugins/commands/up/start_mixins.rb
vagrant-unbundled-2.2.6.1 plugins/commands/up/start_mixins.rb
vagrant-unbundled-2.2.6.0 plugins/commands/up/start_mixins.rb
vagrant-unbundled-2.2.5.0 plugins/commands/up/start_mixins.rb
vagrant-unbundled-2.2.4.0 plugins/commands/up/start_mixins.rb
vagrant-unbundled-2.2.3.0 plugins/commands/up/start_mixins.rb
vagrant-unbundled-2.2.2.0 plugins/commands/up/start_mixins.rb