nunomaduro / laravel-console-task

✅ Laravel Console Task is a output method for Laravel Console Commands.
MIT License
254 stars 21 forks source link

Allow for custom failed message and custom success messages #11

Closed Namoshek closed 3 years ago

Namoshek commented 4 years ago

As discussed in #10, this PR adds support for custom success messages of tasks. As there is no way to distinguish between success and failure other than checking the result for false, I decided to add a fourth parameter to the macro which allows to set a custom failure message. This message simply allows to customize the currently hardcoded failed response:

class SomeCommand extends Command
{
    public function handle()
    {
        $this->task('Finalizing installation', function () {
            return 'everything is up and running!';
        }, 'loading... (this can take a minute or two)', 'oops, something went wrong and needs manual intervention');
    }
}

/* OUTPUT (same line if decorated output is supported) */
// Finalizing installation: <comment>loading... (this can take a minute or two)</comment>
// Finalizing installation: <info>everything is up and running!</info>
// Finalizing installation: <error>oops, something went wrong and needs manual intervention</error>

In theory, this PR is not backwards compatible, as it changes the output for return 'OK'; compared to the previous version (not the return value of $this->task() though). But as the special scenarios without a return value or something different to a boolean have never been documented, I guess it would still be fine to release it as minor version or so...

Namoshek commented 4 years ago

Build breaks due to PHPUnit version... shouldn't be caused by this PR. Locally, I had no issue installing composer dependencies.

ashleyhood commented 4 years ago

@nunomaduro this would be nice to merge as it can be confusing to have loading... as the description when task is running.

For example I have a task that deletes something and would like to have the word deleting... to display when the task is running.

sergejostir commented 4 years ago

@ashleyhood You can already specify a custom loading text, it's just not documented ;) https://github.com/nunomaduro/laravel-console-task/blob/513746f6809485121898e21c8a5da1ad72dca8aa/src/LaravelConsoleTaskServiceProvider.php#L42