def shell2(
        self,
        cmdargs: Union[str, list, tuple],
        timeout: Optional[float] = _DEFAULT_SOCKET_TIMEOUT,
        encoding: str | None = "utf-8",
        rstrip=False,
        v2=False,
    ) -> Union[ShellReturn, ShellReturnRaw]:
        """
        Run shell command with detail output
        Args:
            cmdargs (str | list | tuple): command args
            timeout (float): set shell timeout, seconds
            encoding (str): set output encoding (Default: utf-8), set None to make return bytes
            rstrip (bool): strip the last empty line, only work when encoding is set
            shell_v2 (bool): attempt to use the shell_v2 protocol (and fail if not supported by device)

        Returns:
            ShellOutput

        Raises:
            AdbTimeout
        """
        if isinstance(cmdargs, (list, tuple)):
            cmdargs = list2cmdline(cmdargs)

        if v2:
            if not self._features:
                self._features = set(self.get_features().split(','))
            if "shell_v2" not in self._features:
                v2 = False
                logger.warning("shell_v2 specified but not supported by device")

        if v2:
            result = self._shell_v2(cmdargs, timeout)
        else:
            result = self._shell_v1(cmdargs, timeout)

        if encoding:
            result = ShellReturn(
                command=result.command,
                returncode=result.returncode,
                output=result.output.decode(encoding, errors="replace"),
                stderr=result.stderr.decode(encoding, errors="replace"),
                stdout=result.stdout.decode(encoding, errors="replace"),
            )
            if rstrip:
                result.output = result.output.rstrip()
                result.stderr = result.stderr.rstrip()
                result.stdout = result.stdout.rstrip()
        return result

        Run shell command with detail output
        Args:
            cmdargs (str | list | tuple): command args
            timeout (float): set shell timeout, seconds
            encoding (str): set output encoding (Default: utf-8), set None to make return bytes
            rstrip (bool): strip the last empty line, only work when encoding is set
            shell_v2 (bool): attempt to use the shell_v2 protocol (and fail if not supported by device)

        Returns:
            ShellOutput

        Raises:
            AdbTimeout
        
adbutils/_device_base.py