Skip to content
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

[5.5] Adds task command output to Artisan commands #22351

Closed
wants to merge 1 commit into from
Closed

[5.5] Adds task command output to Artisan commands #22351

wants to merge 1 commit into from

Conversation

nunomaduro
Copy link
Member

@nunomaduro nunomaduro commented Dec 8, 2017

This PR addresses a creation of new command output. Adding a new method to the Artisan Illuminate\Console\Command class that allows the an user to understand the result of the given task.

  • The task method code
    /**
     * Write a string as task output.
     *
     * @param  string  $string
     * @param  callable  $callable
     * @return void
     */
    public function task($string, callable $callable)
    {
        $result = $callable() ? '<info>✔</info>' : '<error>fail</error>';

        $this->output->writeln("$string: $result");
    }
  • Usage example
    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $this->task('Downloading Laravel', function () {
            $response = Client::download('cabinet.laravel.com/latest.zip', storage_path('latest.zip'))

            return response->success();
        });
    }
  • Result

task

@phanan
Copy link
Contributor

phanan commented Dec 8, 2017

This should be in your own extending class IMO.

@taylorotwell
Copy link
Member

I do kind of like it but also agree that probably we should leave it up to the developer to add this helper to their own class. Thanks!

@deleugpn
Copy link
Contributor

deleugpn commented Dec 8, 2017

Pretty cool, indeed.

@OwenMelbz
Copy link
Contributor

Is the command macroable to allow this method to get added? And if not - is that more of a solution to enable this functionality for people?

@nunomaduro
Copy link
Member Author

@OwenMelbz I may create a package for this. I keep you posted 🙂

@nunomaduro
Copy link
Member Author

@OwenMelbz @m1guelpf Just created a package with this feature: https://github.com/nunomaduro/laravel-console-task

@deleugpn
Copy link
Contributor

@nunomaduro maybe you could even look at how spatie implemented the parallelMap in order to try parallel task.

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

Successfully merging this pull request may close these issues.

6 participants