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

[0.1.9] Add non-interactive mode #73

Merged
merged 3 commits into from
Sep 20, 2023
Merged

[0.1.9] Add non-interactive mode #73

merged 3 commits into from
Sep 20, 2023

Conversation

jessarcher
Copy link
Member

@jessarcher jessarcher commented Sep 18, 2023

This PR introduces a non-interactive mode for Prompts.

When Prompts are non-interactive, they will attempt to return the configured default value instead of prompting. Most prompts have a safe default when none is provided. An exception will be thrown if the default value does not pass any validation checks.

This is useful when prompts occur in a non-interactive environment, such as a scheduled task, queued job, CI, or deploy script.

The behaviour is currently mixed, depending on the scenario. #63 prevented prompts from waiting indefinitely for input when the fallback was not triggered, but everything now depends on the fallback to handle non-interactive mode. When using a Symfony fallback, there are some inconsistencies. For example, the choice component doesn't allow you to select nothing in interactive mode but will return null in non-interactive mode. With this PR, the fallbacks no longer need to be used for non-interactive mode - just for Windows and when testing (for now).

This is a breaking change because Laravel depends on the fallback when running tests and the non-interactive mode will take over in a CI testing environment. If we release this change in v0.2, Laravel can update its version constraint and ensure interactive mode is enabled when testing. The companion PR is at laravel/framework#48468 Edit: We can release this as 0.1.9 and update the minimum version in the framework. This will avoid conflicts for users that have other packages that currently depend on ^0.1.

In the future, I would like to prevent the need for fallbacks when testing so that fallback mode is only required for Windows environments (and maybe that can even be solved with #17).

This also paves the way for #57, which needs to know when Laravel commands are explicitly told to be non-interactive (via the -n argument), regardless of the presence of a tty.

Fixes #64

@jessarcher jessarcher changed the title Add non-interactive mode [0.2.x] Add non-interactive mode Sep 20, 2023
@jessarcher jessarcher marked this pull request as ready for review September 20, 2023 08:07
@taylorotwell taylorotwell merged commit 0de6548 into main Sep 20, 2023
4 checks passed
@taylorotwell taylorotwell deleted the non-interactive-mode branch September 20, 2023 14:07
@jessarcher jessarcher changed the title [0.2.x] Add non-interactive mode [0.1.9] Add non-interactive mode Sep 22, 2023
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.

Prompts does not check for a TTY
2 participants