Skip to content

[Console] Options are not recognized if command name is not specified #21317

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Chi-teck opened this issue Jan 17, 2017 · 7 comments
Closed

[Console] Options are not recognized if command name is not specified #21317

Chi-teck opened this issue Jan 17, 2017 · 7 comments

Comments

@Chi-teck
Copy link
Contributor

Q A
Bug report? yes
BC Break report? no
Symfony version 3.2.0

It happens when default command is configured. So that php app.php app:foo --bar example works fine but php app.php --bar example returns CommandNotFoundException exception "Command "example" is not defined. ".

@stof
Copy link
Member

stof commented Jan 17, 2017

this is known (and documented IIRC). There is nothing we can do here in a BC way.

@javiereguiluz
Copy link
Member

@stof do you consider this a bug to be fixed in 3.3 ... or "a broken feature" that won't be fixed? Thanks!

@xabbuh
Copy link
Member

xabbuh commented Jan 17, 2017

@javiereguiluz IIRC there were bug reports in the past and we came to the conclusion that this isn't something that could be fixed without breaking backwards compatibility.

@xabbuh
Copy link
Member

xabbuh commented Jan 17, 2017

And @stof is right that we talk about this limitation in the documentation:

This feature has a limitation: you cannot use it with any Command arguments.

@javiereguiluz
Copy link
Member

@xabbuh thanks for the info. But I still don't know if this is a known bug that won't be fixed until 4.0 ... or a known limitation that will never be fixed.

@ogizanagi
Copy link
Contributor

ogizanagi commented Jan 18, 2017

I think it'll never be fixed. But it can be solved in userland, using a foolish workaround like the following (with some limitations too...):

/**
 * This application aware ArgvInput implementation tries to detect if an existing command name has been provided.
 * If not, it'll add the provided default command name to the tokens.
 */
class DefaultCommandArgvInput extends ArgvInput
{
    public function __construct(Application $application, string $defaultCommand)
    {
        $argv = $_SERVER['argv'];
        $commandName = $argv[1] ?? null;
        if (empty($commandName) || !$application->has($commandName)) {
            array_splice($argv, 1, 0, [$defaultCommand]);
        }

        parent::__construct($argv);
    }
}

(just use an instance of the above along with the Application::run() method instead of an instance of ArgvInput)

@javiereguiluz
Copy link
Member

Closing it as "won't fix" for the reasons given above ... but I've opened symfony/symfony-docs#7545 to improve the docs about this.

xabbuh added a commit to symfony/symfony-docs that referenced this issue Mar 1, 2017
… (javiereguiluz)

This PR was merged into the 2.7 branch.

Discussion
----------

Minor improvement for the default console command article

As seen in symfony/symfony#21317 we didn't mention that options don't work either.

Commits
-------

ff7c62a Minor improvement for the default console command article
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants