public static function escapeArguments(array $arguments, $command = null)
    {
        $processedArguments = array();
        foreach ($arguments as $key => $value) {
            if (is_string($key) && substr($key, 0, 1) === '-') {
                if (is_array($value) === false) {
                    $value = array($value);
                }

                foreach ($value as $optionValue) {
                    if ($optionValue === null) {
                        $processedArguments[] = $key;
                    } elseif (is_string($optionValue)) {
                        $processedArguments[] = trim(sprintf('%s=%s', $key, $optionValue));
                    }
                }
            } elseif (is_scalar($value)) {
                $processedArguments[] = $value;
            }
        }

        if ($command !== null) {
            array_unshift($processedArguments, $command);
        }

        return implode(' ', array_map(array(__CLASS__, 'escapeArgument'), $processedArguments));
    }