Sha256: 94dbc826ae8fee943065b28de15280fa13b297d158b7b989d015a9d0fff88f63

Contents?: true

Size: 1.37 KB

Versions: 31

Compression:

Stored size: 1.37 KB

Contents

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 = command.strip.split(/\s+/)
          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 28 versions & 5 rubygems

Version Path
vagrant-unbundled-2.0.3.0 plugins/communicators/winrm/command_filters/test.rb
vagrant-aws-detiber-0.7.2.pre.4 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-419afb4dcffe/plugins/communicators/winrm/command_filters/test.rb
vagrant-aws-detiber-0.7.2.pre.3 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-419afb4dcffe/plugins/communicators/winrm/command_filters/test.rb
vagrant-aws-detiber-0.7.2.pre.2 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-419afb4dcffe/plugins/communicators/winrm/command_filters/test.rb
vagrant-unbundled-2.0.2.0 plugins/communicators/winrm/command_filters/test.rb
vagrant-unbundled-2.0.1.0 plugins/communicators/winrm/command_filters/test.rb
vagrant-aws-mkubenka-0.7.2.pre.22 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-f3fdbf414272/plugins/communicators/winrm/command_filters/test.rb
vagrant-aws-mkubenka-0.7.2.pre.16 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-1ee58c40e3f5/plugins/communicators/winrm/command_filters/test.rb
vagrant-unbundled-2.0.0.1 plugins/communicators/winrm/command_filters/test.rb
vagrant-unbundled-1.9.8.1 plugins/communicators/winrm/command_filters/test.rb
vagrant-unbundled-1.9.7.1 plugins/communicators/winrm/command_filters/test.rb
vagrant-aws-mkubenka-0.7.2.pre.14 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-5333e60e2d38/plugins/communicators/winrm/command_filters/test.rb
vagrant-aws-mkubenka-0.7.2.pre.11 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-5333e60e2d38/plugins/communicators/winrm/command_filters/test.rb
vagrant-aws-mkubenka-0.7.2.pre.10 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-5333e60e2d38/plugins/communicators/winrm/command_filters/test.rb
vagrant-aws-mkubenka-0.7.2.pre.9 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-5333e60e2d38/plugins/communicators/winrm/command_filters/test.rb
vagrant-unbundled-1.9.5.1 plugins/communicators/winrm/command_filters/test.rb
vagrant-unbundled-1.9.1.1 plugins/communicators/winrm/command_filters/test.rb
vagrant-compose-yaml-0.1.3 vendor/bundle/ruby/2.2.0/bundler/gems/vagrant-dbb756c7b6da/plugins/communicators/winrm/command_filters/test.rb
vagrant-compose-yaml-0.1.2 vendor/bundle/ruby/2.2.0/bundler/gems/vagrant-dbb756c7b6da/plugins/communicators/winrm/command_filters/test.rb
vagrant-compose-yaml-0.1.1 vendor/bundle/ruby/2.2.0/bundler/gems/vagrant-dbb756c7b6da/plugins/communicators/winrm/command_filters/test.rb