nunomaduro / laravel-console-task

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

Support custom task results besides boolean results #10

Closed Namoshek closed 2 years ago

Namoshek commented 4 years ago

Currently, there is only two types of results a task can create in the console:

<info>✔</info>
<error>failed</error>

I came accross situations, where it would be beneficial to be able to display a different result, for example:

<info>nothing to do</info>
<info>already handled</info>
<info>partially updated</info>
...

Quick thinking brought me to the result that all of these situations are success scenarios and no failures. Which means it should be possible to adapt the current code in a way that custom errors are displayed. So my question is: would a change like this be desired? Of course I would prepare a PR for it.


Alternative suggestion: allow tasks to add additional output, which is displayed in a way that makes it obvious to which task it belongs

Updating Model #1: <info>✔</info>
  -> Validation passed
  -> Storage complete
Updating Model #2: <error>failed</error>
  -> Validation failed (The name must be unique)

I'm not yet sure what would be the most practical way of implementing this. Also I'm not sure it would work well with the if ($this->output->isDecorated()) { /* rewrite the line */ } part. But I'm sure there is a way. So what are your opinions on this @nunomaduro?

nunomaduro commented 4 years ago

Sounds promising, sure. Please submit a pull request on it.

Note: Try not to make breaking changes.

Namoshek commented 4 years ago

The second suggestion should be possible without a breaking change, while the former isn't. Reason is this line $result = $task() === false ? false : true;. We implicitely assume everything that isn't exactly false to be true. Even 0 is considered true.

Allowing tasks to return arbitrary content such as return 'nothing to do'; will not break the $result, but it would change the command output from <info>✔</info> to <info>nothing to do</info>. So I guess it's not really BC.