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
Merged

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

merged 2 commits into from
Sep 14, 2019

Conversation

svenluijten
Copy link
Contributor

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.

@taylorotwell taylorotwell merged commit 0ef669e into laravel:6.x Sep 14, 2019
@svenluijten svenluijten deleted the commands-arguments-options branch September 15, 2019 12:27
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.

2 participants