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

Use Prompts #328

Open
wants to merge 56 commits into
base: main
Choose a base branch
from
Open

Use Prompts #328

wants to merge 56 commits into from

Conversation

gcavanunez
Copy link
Contributor

@gcavanunez gcavanunez commented Oct 27, 2023

Changed

  • Drops the nunomaduro/laravel-console-menu dependency together with the ext-posix and ext-pcntl extensions requirement (posix was only used by the menu, not sure why we had pcntl listed since we're not using process signals)
  • Adds Laravel Prompts and replaces our outputs in most places (some places, like the process output, were kinda weird when trying to use prompts... we also tried Termwind, but we figured it wasn't worth it for now... at least until we figure out a better TUI for this). We're using prompts for the enable menu, but also for the "prompts" (our own additional questions were called that), which makes a nice experience. We have also converted the functions to use Prompts validations.
  • We're also changing how we detect if a port is available. Previously, we were relying on netstat being installed. Instead, we will switch to attempting to do a fsockopen() on the port. If it returns a resource, it means something is running on that port, so it's NOT available. Otherwise, it returns false, which means nothing is running on it so the port is available. We're using the TAKEOUT_CONTAINER=1 environment variable (already present in Takeout's Docker image) to detect if we should check localhost or host.docker.internal host instead. We're also updating the docs to add the --add-host option needed for this to work on Linux (it already works without it on Windows and Mac).
  • The logs command now accepts the name of the service... and when passed nothing, it will prompt the user with the options of running Takeout containers

closes #324
closes #282

@gcavanunez gcavanunez changed the title feat: prompts working state Change the terminal enable list view for the Prompts combo box Nov 9, 2023
@gcavanunez gcavanunez changed the title Change the terminal enable list view for the Prompts combo box (WIP) Change the terminal enable list view for the Prompts combo box Nov 9, 2023
@gcavanunez
Copy link
Contributor Author

After upgrading to "laravel/prompts": "^0.1.13" the error with the console being prompted during tests go away

This upgrade does require "laravel-zero/framework": "^10.1.1"

@gcavanunez gcavanunez changed the base branch from main to tm/upgrade-laravel-zero May 3, 2024 17:46
@mattstauffer
Copy link
Member

@gcavanunez I'm super interested in getting this merged. The install box has gotten out of hand! Do you need any help to get this moved forward?

@gcavanunez
Copy link
Contributor Author

@mattstauffer 100%!! Since this guy depends on bumping up to the latest version of laravel-zero, taking a look at this PR could trickle this one out

@gcavanunez gcavanunez changed the title (WIP) Change the terminal enable list view for the Prompts combo box Change the terminal enable list view for the Prompts combo box Aug 15, 2024
@gcavanunez gcavanunez marked this pull request as ready for review August 15, 2024 14:34
Base automatically changed from tm/upgrade-laravel-zero to main December 16, 2024 18:15
@tonysm tonysm marked this pull request as draft December 17, 2024 14:29
@tonysm tonysm assigned tonysm and unassigned tonysm Dec 17, 2024
@tonysm tonysm changed the title Change the terminal enable list view for the Prompts combo box Use Prompts Dec 18, 2024
…host instead of localhost

This works on Windows and Mac, but will require Linux users to add
`--add-host=docker.internal.host:host-gateway` to their aliases. The
docs was updated.
@tonysm tonysm marked this pull request as ready for review December 18, 2024 15:25
Copy link
Contributor Author

@gcavanunez gcavanunez left a comment

Choose a reason for hiding this comment

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

Pulled it in and tested things 💪

@tonysm tonysm marked this pull request as draft December 18, 2024 15:46
@tonysm tonysm marked this pull request as ready for review December 18, 2024 18:40
Copy link
Member

@mattstauffer mattstauffer left a comment

Choose a reason for hiding this comment

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

Incredible work! This is so exciting! Just a few notes.

app/Commands/DisableCommand.php Outdated Show resolved Hide resolved
app/Exceptions/DockerMissingException.php Outdated Show resolved Hide resolved
app/Exceptions/DockerNotAvailableException.php Outdated Show resolved Hide resolved

foreach ($questions as $prompt) {
$items[] = match (true) {
Str::contains($prompt['shortname'], 'port') => $this->askQuestion($prompt, $this->useDefaults, validate: function (string $port) {
Copy link
Member

Choose a reason for hiding this comment

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

Why are we moving to Str::contains? It makes it less clear what we're doing.

Copy link
Contributor

@tonysm tonysm Dec 19, 2024

Choose a reason for hiding this comment

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

This was duplicated. For the default prompts we were checking shortname === port but for the custom prompts (the services might have other port prompts that are called something_port, for instance), we were checking Str::contains(shortname, 'port'), so I figured it would be better to merge the prompts and just check once with Str::contains, which handles both cases.

Comment on lines 31 to 34
// To check if the socket is available, we'll attempt to open a socket on the port.
// If we cannot open the socket, it means there's nothing running on it, so the
// port is available. If we are successful, that means it is already in use.

Copy link
Member

Choose a reason for hiding this comment

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

Drop the line after the comment block.

Also, I like that you made the fun Laravel -style three comments lines.. but unfortunately, I think we need a bit more -- or a bit different -- explanation. What's missing here is context for anyone who doesn't understand sockets. The natural expectation is that if I try to do a thing on a port and it works, that means the port was available, and if it fails, that means the port wasn't available. But this is the opposite. I think a good comment would explain that, more than explaining exactly what the following few lines do.

Copy link
Contributor

Choose a reason for hiding this comment

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

I've changed the comments

app/Shell/Environment.php Outdated Show resolved Hide resolved
@tonysm tonysm requested a review from mattstauffer December 19, 2024 15:39
@tonysm
Copy link
Contributor

tonysm commented Dec 19, 2024

@mattstauffer ready for another review

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.

Add Prompt interface to stock enable command Menu too tall for some screens
3 participants