Skip to content

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

@jcoughlin11

Description

@jcoughlin11

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working as expected

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions