Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@WendellAdriel
Copy link
Member

Why

Currently, when we need to print something to the terminal, we need to use this approach:

$app->getPrinter()->display('Hello World');
$this->getPrinter()->display('Hello World'); // When extending the CommandController

Also, for interacting with the config in classes extending the CommandController we need to use this approach:

$this->getApp()->config->debug;

It's not bad, but it's also not the best DX.

Solution

I created a PrinterProxy trait that I set the App and CommandController classes to use. With this, now we can simplify how we print something to the terminal:

$app->display('Hello World');
$this->display('Hello World'); // When extending the CommandController

I also created a config property in the CommandController so when we need to interact with the config we can use this approach:

$this->config->debug;

Additional Work

If this get's merged, I'll work on additional PRs for the minicli/application to use this approach and also a new PR to the docs to update the examples to use this approach as well.

Copy link
Collaborator

@JustSteveKing JustSteveKing left a comment

Choose a reason for hiding this comment

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

I like this idea and is something I have been thinking about as well. However I initially thought about just adding a proxy method on the CommandController itself instead of a whole other class with all the additional methods.

@WendellAdriel
Copy link
Member Author

@JustSteveKing I thought about that but I worked on a trait to have it working on the CommandController and on the App instance as well.

But if you think this is too much I can rework the changes. Just let me know what you feel it’s better

@JustSteveKing
Copy link
Collaborator

@JustSteveKing I thought about that but I worked on a trait to have it working on the CommandController and on the App instance as well.

But if you think this is too much I can rework the changes. Just let me know what you feel it’s better

I think what you have done works well, but every new printer command we add we will have to do it twice so that it is accessible

@WendellAdriel
Copy link
Member Author

@JustSteveKing true. I have something in mind, I’ll make some changes tomorrow and update the PR

@WendellAdriel WendellAdriel self-assigned this May 12, 2023
@WendellAdriel WendellAdriel added the enhancement New feature or request label May 12, 2023
@WendellAdriel
Copy link
Member Author

@JustSteveKing I updated how to handle the proxy for the output handler methods, check if this is better now.

@WendellAdriel
Copy link
Member Author

@JustSteveKing after the DI container changes, what should be the approach for this so I can update my PR?

@JustSteveKing
Copy link
Collaborator

@JustSteveKing after the DI container changes, what should be the approach for this so I can update my PR?

This will be interesting actually! I think it needs discussion more than anything. The way the current Minicli application works is very anti-di so we need to figure out what DO stuff we want to use

@WendellAdriel
Copy link
Member Author

This will be interesting actually! I think it needs discussion more than anything. The way the current Minicli application works is very anti-di so we need to figure out what DO stuff we want to use

But should I change anything now or should we merge this to get the DX improvements and work on a refactor in a new PR with other DI stuff?

@WendellAdriel WendellAdriel merged commit 2922ad8 into minicli:main May 18, 2023
@WendellAdriel WendellAdriel deleted the command-dx-improvement branch May 18, 2023 09:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants