def invoke(
        self,
        cli,
        args=None,
        prog_name=None,
        input=None,
        terminate_input=False,
        env=None,
        _output_lines=None,
        **extra
    ):
        """Like :meth:`CliRunner.invoke` but displays what the user
        would enter in the terminal for env vars, command args, and
        prompts.

        :param terminate_input: Whether to display "^D" after a list of
            input.
        :param _output_lines: A list used internally to collect lines to
            be displayed.
        """
        output_lines = _output_lines if _output_lines is not None else []

        if env:
            for key, value in sorted(env.items()):
                value = shlex.quote(value)
                output_lines.append("$ export {}={}".format(key, value))

        args = args or []

        if prog_name is None:
            prog_name = cli.name.replace("_", "-")

        output_lines.append(
            "$ {} {}".format(prog_name, " ".join(shlex.quote(x) for x in args)).rstrip()
        )
        # remove "python" from command
        prog_name = prog_name.rsplit(" ", 1)[-1]

        if isinstance(input, (tuple, list)):
            input = "\n".join(input) + "\n"

            if terminate_input:
                input += "\x04"

        result = super(ExampleRunner, self).invoke(
            cli=cli, args=args, input=input, env=env, prog_name=prog_name, **extra
        )
        output_lines.extend(result.output.splitlines())
        return result
def invoke ( self , cli , args = None , prog_name = None , input = None , terminate_input = False , env = None , _output_lines = None , ** extra ) : output_lines = _output_lines if _output_lines is not None else [ ] if env : for key , value in sorted ( env . items ( ) ) : value = shlex . quote ( value ) output_lines . append ( "$ export {}={}" . format ( key , value ) ) args = args or [ ] if prog_name is None : prog_name = cli . name . replace ( "_" , "-" ) output_lines . append ( "$ {} {}" . format ( prog_name , " " . join ( shlex . quote ( x ) for x in args ) ) . rstrip ( ) ) prog_name = prog_name . rsplit ( " " , 1 ) [ - 1 ] if isinstance ( input , ( tuple , list ) ) : input = "\n" . join ( input ) + "\n" if terminate_input : input += "\x04" result = super ( ExampleRunner , self ) . invoke ( cli = cli , args = args , input = input , env = env , prog_name = prog_name , ** extra ) output_lines . extend ( result . output . splitlines ( ) ) return result
Like :meth:`CliRunner.invoke` but displays what the user
        would enter in the terminal for env vars, command args, and
        prompts.

        :param terminate_input: Whether to display "^D" after a list of
            input.
        :param _output_lines: A list used internally to collect lines to
            be displayed.