Sha256: 7a672b81bca2d2811a9c41b64e475e592b846c949180f38c4d9bdbb4a3489185

Contents?: true

Size: 780 Bytes

Versions: 5

Compression:

Stored size: 780 Bytes

Contents

# Aruba
module Aruba
  # Platforms
  module Platforms
    # This is a command which should be run
    #
    # This adds `cmd.exec` in front of commmand
    #
    # @private
    class WindowsCommandString
      def initialize(command, *arguments)
        @command = command
        @arguments = arguments
      end

      # Convert to array
      def to_a
        [cmd_path, '/c', [escaped_command, *escaped_arguments].join(' ')]
      end

      private

      def escaped_arguments
        @arguments.map { |arg| arg.gsub(/"/, '"""') }
                  .map { |arg| / /.match?(arg) ? "\"#{arg}\"" : arg }
      end

      def escaped_command
        @command.gsub(/ /, '""" """')
      end

      def cmd_path
        Aruba.platform.which('cmd.exe')
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
aruba-1.0.4 lib/aruba/platforms/windows_command_string.rb
aruba-1.0.3 lib/aruba/platforms/windows_command_string.rb
aruba-1.0.2 lib/aruba/platforms/windows_command_string.rb
aruba-1.0.1 lib/aruba/platforms/windows_command_string.rb
aruba-1.0.0 lib/aruba/platforms/windows_command_string.rb