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

Allow options to have default parameters #25

Merged
merged 6 commits into from
Aug 31, 2016

Conversation

thecrypticace
Copy link
Contributor

@thecrypticace thecrypticace commented Aug 22, 2016

I saw #21 after I ran into a need for this today.

  • Default parameters will now also be determined via reflection.
  • Setting defaults via ->defaults(…) will now set defaults for matching options as well.

@mnapoli
Copy link
Owner

mnapoli commented Aug 22, 2016

Hi @thecrypticace, this is awesome!

From reading the code I think I noticed this:

$app->command('greet [firstname] [lastname] [--age=]', function () {
    // ...
})->defaults([
    'firstname' => 'John',
    'lastname'  => 'Doe',
    '--age' => 25,
]);

works but also this:

    'age' => 25,

Is that right?

Maybe we should allow only one of those option to work, because currently there are 3 ways to define a default option value and it's one too much. Can options and arguments have identical names? If there's no chance for a collision we could only allow the simpler version:

})->defaults([
    'age' => 25,
]);

Options and arguments will collide when matching by parameter names so this isn’t something that needs to be supported.
@thecrypticace
Copy link
Contributor Author

… and it's one too much.

Yeah. I agree.

Can options and arguments have identical names?

While it looks like Symfony allows this, I just did a bit of testing and things will get squashed on in the invoker: a later defined argument / option will override an earlier one with the same name.

I've updated the PR to change this.

@mnapoli
Copy link
Owner

mnapoli commented Aug 31, 2016

Thanks! Sorry for the wait

@mnapoli mnapoli merged commit 497f22a into mnapoli:master Aug 31, 2016
@kfriend
Copy link

kfriend commented Aug 31, 2016

Nice work, thanks @thecrypticace!

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.

None yet

3 participants