8000 [Console] Warning when command alias is longer than commands name · Issue #15511 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Console] Warning when command alias is longer than commands name #15511

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
madflow opened this issue Aug 11, 2015 · 4 comments
Closed

[Console] Warning when command alias is longer than commands name #15511

madflow opened this issue Aug 11, 2015 · 4 comments

Comments

@madflow
Copy link
madflow commented Aug 11, 2015

symfony git:(2.8)

When an alias of a command is longer than the commands name than there is a warning in the terminal output. The reason seems to be that the maximum width of the command column is only calculated using the "names".

Is this wanted behaviour? Are we using it wrong?

<?php

require_once dirname(__FILE__).'/vendor/autoload.php';

use \Symfony\Component\Console\Application;
use \Symfony\Component\Console\Command\Command;

$app =  new Application();

$command = new Command('huba:huba:haba:haba:huba');
$command->setAliases(['huba:huba:haba:haba:huba:alias:huba']);

$app->add($command);
$app->run();
PHP Warning:  str_repeat(): Second argument has to be greater than or equal to 0 in ...vendor/symfony/console/Descriptor/TextDescriptor.php on line 210

Hackfix while debugging for me was changing TextDescriptor::getColumnWidth

to

     * @param Command[] $commands
     *
     * @return int
     */
    private function getColumnWidth(array $commands)
    {
        $width = 0;
        foreach ($commands as $command) {
            $width = strlen($command->getName()) > $width ? strlen($command->getName()) : $width;
        }

        if(count($command->getAliases()) > 0) {
            $aliasMaxLength = max(array_map('strlen', $command->getAliases()));
            $width = $aliasMaxLength > $width ? $aliasMaxLength : $width;
        }

        return $width + 2;
    }

Tests still pass...

@stof
Copy link
Member
stof commented Aug 11, 2015

your code does not work, because it only reads the aliases of the last command (and it breaks totally if there is no command at all btw, because the $command variable will not be defined in this case).

Anyway, code changes should be submitted as pull requests

@madflow
Copy link
Author
madflow commented Aug 11, 2015

You are right of course about the premature "fix". I should have left it out because it distracted from my intention to find out if it is "bug or not". I will consider a pull request. Thanks.

@dosten
Copy link
Contributor
dosten commented Aug 11, 2015

@madflow can you check if #15515 solves your problem?

@madflow
Copy link
Author
madflow commented Aug 12, 2015

@dosten I did a quick test with the example from above - the warning is not displayed anymore. Problem solved!

fabpot added a commit that referenced this issue Aug 12, 2015
…command name (dosten)

This PR was merged into the 2.7 branch.

Discussion
----------

[Console] Fixed warning when command alias is longer than command name

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #15511
| License       | MIT

Commits
-------

ecfe944 Fixed warning when command alias is longer than command name
@fabpot fabpot closed this as completed Aug 12, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
0