Sha256: a4ad05f0edfd68d62b4e977f283bd6928645e98a4a7f6129db8748b625f860b7

Contents?: true

Size: 1.24 KB

Versions: 30

Compression:

Stored size: 1.24 KB

Contents

require "shellwords"

module VagrantPlugins
  module CommunicatorWinRM
    module CommandFilters
      # Converts a *nix 'rm' command to a PowerShell equivalent
      class Rm
        def filter(command)
          # rm -Rf /some/dir
          # rm -R /some/dir
          # rm -R -f /some/dir
          # rm -f /some/dir
          # rm /some/dir
          cmd_parts = Shellwords.split(command.strip)

          # Figure out if we need to do this recursively
          recurse = false
          cmd_parts.each do |k|
            argument = k.downcase
            if argument == '-r' || argument == '-rf' || argument == '-fr'
              recurse = true
              break
            end
          end

          # Figure out which argument is the path
          dir = cmd_parts.pop
          while !dir.nil? && dir.start_with?('-')
            dir = cmd_parts.pop
          end

          ret_cmd = ''
          if recurse
            ret_cmd = "if (Test-Path \"#{dir}\") {Remove-Item \"#{dir}\" -force -recurse}"
          else
            ret_cmd = "if (Test-Path \"#{dir}\") {Remove-Item \"#{dir}\" -force}"
          end
          return ret_cmd
        end

        def accept?(command)
          command.start_with?('rm ')
        end
      end
    end
  end
end

Version data entries

30 entries across 26 versions & 4 rubygems

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