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

RFC: Widgets / Plugins / Middleware / Argument Injector thingie #4

Conversation

przemyslaw-przylucki
Copy link
Contributor

Good morning!

I've been tinkering with the idea from the initial PR a bit more and came up with this initial concept.

Note: I haven't spent much time on this, let's treat this as a draft of functionality that we want to have.

So, as the title suggests - not sure about name, I'll just stick with widgets for now which is probably the worst name but 🤷

The goal of widgets is to create a way to inject additional arguments into the console.
This can be useful for example when our command requires an API key, that could be automatically injected if not provided, or it'd use the passed one.

Widgets can be defined both globally (maybe it'd be nice to add "namespace" param for the #[GlobalConsoleWidget] so all commands within i.e db: namespace would be affected) and locally in command definition.

I think the biggest place for discussion is what contract the invoke method should have and what should be modifiable - but this would require validation to run twice:

  1. after resolving the passed arguments
  2. after running invoke on all widgets

@coveralls
Copy link

coveralls commented Apr 10, 2024

Pull Request Test Coverage Report for Build 8638167516

Details

  • 27 of 55 (49.09%) changed or added relevant lines in 9 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-1.4%) to 56.614%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/ConsoleCommand.php 1 2 50.0%
src/ConsoleConfig.php 0 2 0.0%
src/Exceptions/ConsoleExitException.php 0 2 0.0%
src/Widgets/ForceWidget.php 0 3 0.0%
src/Discovery/ConsoleWidgetDiscovery.php 4 9 44.44%
src/ConsoleInputBuilder.php 18 33 54.55%
Totals Coverage Status
Change from base Build 8614878437: -1.4%
Covered Lines: 321
Relevant Lines: 567

💛 - Coveralls

@przemyslaw-przylucki przemyslaw-przylucki marked this pull request as draft April 10, 2024 21:28

use Attribute;

#[Attribute(Attribute::TARGET_CLASS)]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These globals should probably never be used for anything other than --help, --verbosity --silent etc.

@@ -4,13 +4,18 @@

namespace Tempest\Console;

use ReflectionClass;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this obviously needs a refactor before it gets merged =)

) {
}

public static function fromParameter(ReflectionParameter $parameter): ConsoleArgumentDefinition
public static function fromParameter(ReflectionParameter $parameter, bool $asPositional = true): ConsoleArgumentDefinition
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Injected arguments always have to be named arguments to avoid collisions

@przemyslaw-przylucki przemyslaw-przylucki marked this pull request as ready for review April 14, 2024 21:45
@przemyslaw-przylucki
Copy link
Contributor Author

@brendt do we want to salvage anything out of this or should I close it?

I think you already handled some of the global options in a different way on stream but can't remember the deets

@brendt
Copy link
Member

brendt commented May 4, 2024

I think there's still room for improvement to what I did, but maybe it's best to take more incremental steps.

In truth, I haven't been able to look at this PR in depth. Maybe keep it open for now, I'll definitely go through it and might cherry-pick some stuff straight into main when #21 is merged

@brendt
Copy link
Member

brendt commented May 8, 2024

So, I really like the widget approach, but I feel like we need to get middleware straight first. I'll take care of that, and then we can revisit this idea

@brendt brendt closed this May 8, 2024
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.

3 participants