Sha256: 89ac638c440bad0c5eeeb44001120f43fa0ae037d0ad35bed2579bca0f459131

Contents?: true

Size: 1.55 KB

Versions: 47

Compression:

Stored size: 1.55 KB

Contents

module Vagrant
  module Util
    # Automatically add deprecation notices to commands
    module CommandDeprecation

      # @return [String] generated name of command
      def deprecation_command_name
        name_parts = self.class.name.split("::")
        [
          name_parts[1].sub('Command', ''),
          name_parts[3]
        ].compact.map(&:downcase).join(" ")
      end

      def self.included(klass)
        klass.class_eval do
          class << self
            if method_defined?(:synopsis)
              alias_method :non_deprecated_synopsis, :synopsis

              def synopsis
                if !non_deprecated_synopsis.to_s.empty?
                  "#{non_deprecated_synopsis} [DEPRECATED]"
                else
                  non_deprecated_synopsis
                end
              end
            end
          end
          alias_method :non_deprecated_execute, :execute

          def execute(*args, &block)
            @env[:ui].warn(I18n.t("vagrant.commands.deprecated",
              name: deprecation_command_name
            ) + "\n")
            non_deprecated_execute(*args, &block)
          end
        end
      end

      # Mark command deprecation complete and fully disable
      # the command's functionality
      module Complete
        def self.included(klass)
          klass.include(CommandDeprecation)
          klass.class_eval do
            def execute(*_)
              raise Vagrant::Errors::CommandDeprecated,
                name: deprecation_command_name
            end
          end
        end
      end
    end
  end
end

Version data entries

47 entries across 43 versions & 5 rubygems

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