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

[6.x] Allow adding command arguments and options with objects #29987

Merged
merged 2 commits into from Sep 14, 2019

Conversation

@svenluijten
Copy link
Contributor

commented Sep 13, 2019

This PR will allow the end user to define arguments and options in artisan commands by instantiating objects (more specifically, InputArgument and InputOption objects) instead of using "plain" arrays. The benefit of this is that you won't have to refer back to the documentation to see the order in which the array should be constructed. Instead, you can look at the constructor of the InputArgument/InputOption class.

Before:

protected function getArguments() 
{
    return [
        ['name', InputArgument::REQUIRED, 'the argument\'s description', 'default value'],
    ];
}

After:

protected function getArguments() 
{
    return [
        new InputArgument('name', InputArgument::REQUIRED, 'the argument\'s description', 'default value'),
    ];
}

It should be noted that the "old" way still works, this is simply an extra way of doing it.

I've also added a (hopefully useful) test, though I couldn't figure out how to properly "mock" the $application that should be given to the command via ->setLaravel(). I'd appreciate some pointers about how I should go about doing this without whipping up a full Application object.

svenluijten added 2 commits Sep 13, 2019
@taylorotwell taylorotwell merged commit 0ef669e into laravel:6.x Sep 14, 2019
2 checks passed
2 checks passed
continuous-integration/styleci/pr The analysis has passed
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@svenluijten svenluijten deleted the svenluijten:commands-arguments-options branch Sep 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.