Repository navigation
enahnce(cli/init): skip prompts automatically in non interactive environments - #15997
Conversation
When running in a non-interactive environment (e.g., CI, scripts), the command still attempted to prompt for input, resulting in an IO error. This change sets when is true, so that --force also skips all prompts and uses defaults, making it safe for automation. Fixes #<issue-number> (if applicable).
fixed bug
When running tauri init in a non-interactive environment (CI, scripts), the command would attempt to prompt for input and fail with an IO error because no terminal was available. This change uses std::io::IsTerminal to detect whether stdin is a real terminal. If not, it behaves as if --ci was passed, skipping all prompts and using defaults. This fixes the crash without altering the semantics of --force (which remains only for overwriting existing files). Also adds a regression test, updates the README with a new "Building from Source" section, and includes a changeset entry.
When running tauri init in a non-interactive environment (CI, scripts), the command would attempt to prompt for input and fail with an IO error because no terminal was available. This change uses std::io::IsTerminal to detect whether stdin is a real terminal. If not, it behaves as if --ci was passed, skipping all prompts and using defaults. This fixes the crash without altering the semantics of --force (which remains only for overwriting existing files). Also adds a regression test, updates the README with a new Building from Source section, and includes a changeset entry.
Package Changes Through fd062afThere are 14 changes which include tauri-cli with minor, @tauri-apps/cli with minor, tauri with minor, tauri-build with minor, tauri-runtime with minor, tauri-runtime-wry with minor, tauri-utils with minor, tauri-bundler with minor, tauri-macos-sign with minor, @tauri-apps/api with minor, tauri-codegen with minor, tauri-macros with minor, tauri-plugin with minor, tauri-driver with minor Planned Package VersionsThe following package releases are the planned based on the context of changes in this pull request.
Add another change file through the GitHub UI by following this link. Read about change files or the docs at github.com/jbolda/covector |
The test was incorrectly looking for the cargo-tauri binary in target/ instead of target/debug/. This caused failures on Windows where the path resolution was off by one level. Reduced the number of parent calls to two, matching the actual layout (target/debug/deps/ -> target/debug/). This works consistently across all platforms.
style: revert unintended indentation changes in init.rs
|
@junaidmirr you need to sign all your commits in the PR otherwise I can't merge the PR. |
I have resigned all the commits in the PR. Thank you! |
When running the tauri init command in environments such as CI systems, automated scripts, or other situations where no interactive terminal is available, the command currently attempts to prompt the user for input. This can result in an I/O error when the prompt cannot read from standard input.
As a result, tauri init cannot be reliably used in non interactive environments unless the --ci flag is explicitly provided. While --ci provides a way to use the command without prompts, requiring it for every automated invocation is easy to overlook.
The current implementation relies on the --ci flag to disable prompts, but does not automatically determine whether standard input is connected to an interactive terminal. The --force flag is separate from this behavior and is intended only to control overwriting of an existing src-tauri directory.
Proposed change
This pull request uses Rust's standard library IsTerminal trait to detect whether standard input is connected to an interactive terminal.
When standard input is not connected to a terminal, tauri init automatically follows the same non interactive path used when --ci is provided. This prevents the command from attempting to prompt for input when there is no user available to respond, while preserving the existing behavior when an interactive terminal is available.
Explicit command line options such as --app-name, --frontend-dist, and --dev-url can still be used to override the default configuration values.
The behavior of --force is unchanged. It continues to control whether an existing src-tauri directory can be overwritten and does not affect prompting behavior.
Design consideration
This change introduces behavior based on whether the process has access to an interactive terminal. In most cases, the absence of a terminal indicates CI or automation, but standard input can also be redirected or piped for other reasons.
The goal is to avoid attempting interactive prompts when there is no user available to respond, while keeping the existing behavior unchanged for normal terminal usage.
I chose terminal detection instead of introducing another flag because it allows non interactive invocations to work without requiring users to remember an additional option.
I am open to feedback on whether detecting a non interactive terminal is the appropriate approach, or whether this behavior would be better controlled through an explicit option.
Testing
• Manually tested tauri init in a non interactive environment and verified that it completes without prompting.
• Verified that explicit command line options continue to override the default values.
• Added a regression test covering non interactive execution.
• The implementation uses Rust's standard IsTerminal API and is cross platform.
Documentation
• Updated the README with a Building from Source section explaining how to build the CLI from source.
• Documented the automatic terminal detection behavior.
• Added a changeset describing the fix for the release notes.
Overall, this makes tauri init more reliable when used in CI and automation while preserving the existing behavior for normal interactive terminal usage.