コード例 #1
0
ファイル: base_command.py プロジェクト: meschac38700/cleo
    def run(self, io: IO) -> int:
        self.merge_application_definition()

        try:
            io.input.bind(self.definition)
        except CleoException:
            if not self._ignore_validation_errors:
                raise

        self.initialize(io)

        if io.is_interactive():
            self.interact(io)

        if io.input.has_argument(
                "command") and io.input.argument("command") is None:
            io.input.set_argument("command", self.name)

        io.input.validate()

        status_code = self.execute(io)

        if status_code is None:
            status_code = 0

        return status_code
コード例 #2
0
    def ask(self, io: IO) -> str:
        """
        Asks the question to the user.
        """
        if not io.is_interactive():
            return self.default

        if not self._validator:
            return self._do_ask(io)

        def interviewer():
            return self._do_ask(io)

        return self._validate_attempts(interviewer, io)