def __init__(
        self,
        input=None,
        output=None,
        error_output=None
    ):  # type: (Optional[Input], Optional[Output], Optional[Output]) -> None
        if input is None:
            input_stream = StandardInputStream()
            input = Input(input_stream)

        if output is None:
            output_stream = StandardOutputStream()
            if output_stream.supports_ansi():
                formatter = AnsiFormatter()
            else:
                formatter = PlainFormatter()

            output = Output(output_stream, formatter)

        if error_output is None:
            error_stream = ErrorOutputStream()
            if error_stream.supports_ansi():
                formatter = AnsiFormatter()
            else:
                formatter = PlainFormatter()

            error_output = Output(error_stream, formatter)

        super(ConsoleIO, self).__init__(input, output, error_output)
    def create_io(
        self,
        application,
        args,
        input_stream=None,
        output_stream=None,
        error_stream=None,
    ):  # type: (Application, RawArgs, InputStream, OutputStream, OutputStream) -> IO
        if input_stream is None:
            input_stream = StandardInputStream()

        if output_stream is None:
            output_stream = StandardOutputStream()

        if error_stream is None:
            error_stream = ErrorOutputStream()

        style_set = application.config.style_set

        if args.has_option_token("--no-ansi"):
            output_formatter = error_formatter = PlainFormatter(style_set)
        elif args.has_option_token("--ansi"):
            output_formatter = error_formatter = AnsiFormatter(style_set, True)
        else:
            if output_stream.supports_ansi():
                output_formatter = AnsiFormatter(style_set)
            else:
                output_formatter = PlainFormatter(style_set)

            if error_stream.supports_ansi():
                error_formatter = AnsiFormatter(style_set)
            else:
                error_formatter = PlainFormatter(style_set)

        io = self.io_class(
            Input(input_stream),
            Output(output_stream, output_formatter),
            Output(error_stream, error_formatter),
        )

        if args.has_option_token("-vvv") or self.is_debug():
            io.set_verbosity(DEBUG)
        elif args.has_option_token("-vv"):
            io.set_verbosity(VERY_VERBOSE)
        elif args.has_option_token("-v"):
            io.set_verbosity(VERBOSE)

        if args.has_option_token("--quiet") or args.has_option_token("-q"):
            io.set_quiet(True)

        if args.has_option_token("--no-interaction") or args.has_option_token(
                "-n"):
            io.set_interactive(False)

        return io
Beispiel #3
0
    def execute(self, args="", **options):  # type: (str, ...) -> int
        """
        Executes the command

        Available options:
            * interactive: Sets the input interactive flag
            * decorated: Sets the output decorated flag
            * verbosity: Sets the output verbosity flag
        """
        args = StringArgs(args)

        if "inputs" in options:
            self._io.set_input(options["inputs"])

        if "interactive" in options:
            self._io.set_interactive(options["interactive"])

        if "verbosity" in options:
            self._io.set_verbosity(options["verbosity"])

        if "decorated" in options and options["decorated"]:
            self._io.set_formatter(AnsiFormatter())

        command = Command(self._command.config, self._command.application)

        self._status_code = command.run(args, self._io)

        return self._status_code
Beispiel #4
0
    def __init__(self, style_set):

        input_stream = StandardInputStream()
        input = Input(input_stream)

        output_stream = StandardOutputStream()
        if output_stream.supports_ansi():
            formatter = AnsiFormatter(style_set)
        else:
            formatter = PlainFormatter(style_set)

        output = Output(output_stream, formatter)

        error_stream = ErrorOutputStream()
        if error_stream.supports_ansi():
            formatter = AnsiFormatter()
        else:
            formatter = PlainFormatter()

        error_output = Output(error_stream, formatter)

        super(GotIO, self).__init__(input, output, error_output)
Beispiel #5
0
    def create_io(
        self,
        application,
        args,
        input_stream=None,
        output_stream=None,
        error_stream=None,
    ):  # type: (Application, RawArgs, InputStream, OutputStream, OutputStream) -> IO
        if input_stream is None:
            input_stream = StandardInputStream()

        if output_stream is None:
            output_stream = StandardOutputStream()

        if error_stream is None:
            error_stream = ErrorOutputStream()

        style_set = application.config.style_set

        if output_stream.supports_ansi():
            output_formatter = AnsiFormatter(style_set)
        else:
            output_formatter = PlainFormatter(style_set)

        if error_stream.supports_ansi():
            error_formatter = AnsiFormatter(style_set)
        else:
            error_formatter = PlainFormatter(style_set)

        io = self.io_class(
            Input(input_stream),
            Output(output_stream, output_formatter),
            Output(error_stream, error_formatter),
        )

        resolved_command = application.resolve_command(args)
        # If the current command is the run one, skip option
        # check and interpret them as part of the executed command
        if resolved_command.command.name == "run":
            return io

        if args.has_option_token("--no-ansi"):
            formatter = PlainFormatter(style_set)
            io.output.set_formatter(formatter)
            io.error_output.set_formatter(formatter)
        elif args.has_option_token("--ansi"):
            formatter = AnsiFormatter(style_set, True)
            io.output.set_formatter(formatter)
            io.error_output.set_formatter(formatter)

        if args.has_option_token("-vvv") or self.is_debug():
            io.set_verbosity(DEBUG)
        elif args.has_option_token("-vv"):
            io.set_verbosity(VERY_VERBOSE)
        elif args.has_option_token("-v"):
            io.set_verbosity(VERBOSE)

        if args.has_option_token("--quiet") or args.has_option_token("-q"):
            io.set_quiet(True)

        if args.has_option_token("--no-interaction") or args.has_option_token(
                "-n"):
            io.set_interactive(False)

        return io
Beispiel #6
0
def ansi_io():
    return BufferedIO(formatter=AnsiFormatter(forced=True))