Sha256: 8d58f9caeb270fdee4710534ef3041bdbb06389138fea7173e445daa8eac2bbe

Contents?: true

Size: 1.4 KB

Versions: 31

Compression:

Stored size: 1.4 KB

Contents

require "shellwords"

module VagrantPlugins
  module CommunicatorWinRM
    module CommandFilters
      # Converts a *nix 'test' command to a PowerShell equivalent
      class Test
        def filter(command)
          # test -d /tmp/dir
          # test -f /tmp/afile
          # test -L /somelink
          # test -x /tmp/some.exe

          cmd_parts = Shellwords.split(command.strip)
          flag = cmd_parts[1]
          path = cmd_parts[2]

          if flag == '-d'
            check_for_directory(path)
          elsif flag == '-f' || flag == '-x'
            check_for_file(path)
          else
            check_exists(path)
          end
        end

        def accept?(command)
          command.start_with?("test ")
        end

        private

        def check_for_directory(path)
          <<-EOH
            $p = "#{path}"
            if ((Test-Path $p) -and (get-item $p).PSIsContainer) {
              exit 0
            }
            exit 1
          EOH
        end

        def check_for_file(path)
          <<-EOH
            $p = "#{path}"
            if ((Test-Path $p) -and (!(get-item $p).PSIsContainer)) {
              exit 0
            }
            exit 1
          EOH
        end

        def check_exists(path)
          <<-EOH
            $p = "#{path}"
            if (Test-Path $p) {
              exit 0
            }
            exit 1
          EOH
        end
      end
    end
  end
end

Version data entries

31 entries across 27 versions & 4 rubygems

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