Sha256: d36b0783036b369361efc69d5464cba5e320079353a994295a6eedbbbe9db24a

Contents?: true

Size: 775 Bytes

Versions: 1

Compression:

Stored size: 775 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| 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

1 entries across 1 versions & 1 rubygems

Version Path
aruba-1.0.0.pre.alpha.5 lib/aruba/platforms/windows_command_string.rb