cleo icon indicating copy to clipboard operation
cleo copied to clipboard

Using Call on a Command that Uses Confirm Doesn't Work

Open jcoughlin11 opened this issue 2 years ago • 0 comments

Hello! When using call from inside a command, if the command being called uses confirm, there's an error that says 'NoneType' object has no attribute 'readline'. It appears that this is because _stream is still None in this case.

I'm using cleo v2.0.1. Here's a minimum working example:

import sys

from cleo.application import Application as BaseApplication
from cleo.commands.command import Command as BaseCommand
from cleo.helpers import argument


class FirstCommand(BaseCommand):
    name = "first cmd"
    description = "Stuff"
    help = "Stuff"
    arguments = [argument("firstArg", "First argument.")]

    def handle(self) -> int:
        self.call("second cmd", f"PLACEHOLDER {self.argument('firstArg')}")

        return 0


class SecondCommand(BaseCommand):
    name = "second cmd"
    description = "Stuff"
    help = "Stuff"
    arguments = [argument("secondArg", "Second argument.")]

    def handle(self) -> int:
        self.line(f"Arg = {self.argument('secondArg')}")
        if not self.confirm("Proceed?"):
            self.line("Quitting")
            sys.exit(1)

        return 0


class Application(BaseApplication):
    def __init__(self) -> None:
        super().__init__()
        self.add(FirstCommand())
        self.add(SecondCommand())


if __name__ == "__main__":
    Application().run()

and then running via python3 ./main.py first cmd 42

The use of PLACEHOLDER is because of this isue.

jcoughlin11 avatar Jun 21 '23 18:06 jcoughlin11