-
Notifications
You must be signed in to change notification settings - Fork 0
feat(tty): Add --no-input flag and TTY checks for interactive commands #79
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,27 @@ pub fn spinner(msg: &str) -> indicatif::ProgressBar { | |
| pb | ||
| } | ||
|
|
||
| static NO_INPUT: AtomicBool = AtomicBool::new(false); | ||
|
|
||
| pub fn set_no_input(enabled: bool) { | ||
| NO_INPUT.store(enabled, Ordering::Relaxed); | ||
| } | ||
|
|
||
| /// Returns true if interactive prompts are usable. Returns false when: | ||
| /// - the global `--no-input` flag was passed, | ||
| /// - the `CI` env var is set (most CI runners set this), | ||
| /// - stdin is not a TTY (piped, redirected, or invoked by an agent harness). | ||
| pub fn is_interactive() -> bool { | ||
| if NO_INPUT.load(Ordering::Relaxed) { | ||
| return false; | ||
| } | ||
| if std::env::var_os("CI").is_some() { | ||
| return false; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. super nit: (not blocking) The |
||
| } | ||
| use std::io::IsTerminal; | ||
| std::io::stdin().is_terminal() | ||
| } | ||
|
|
||
| static DEBUG: AtomicBool = AtomicBool::new(false); | ||
|
|
||
| pub fn set_debug(enabled: bool) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,6 +43,14 @@ pub fn set(workspace_id: Option<&str>) { | |
| eprintln!("error: no workspaces available."); | ||
| std::process::exit(1); | ||
| } | ||
| if !crate::util::is_interactive() { | ||
| eprintln!( | ||
| "error: stdin is not a TTY; cannot prompt for selection. \ | ||
| Run 'hotdata workspaces list' to see available IDs, \ | ||
| then 'hotdata workspaces set <workspace_id>'." | ||
| ); | ||
| std::process::exit(1); | ||
| } | ||
|
Comment on lines
+46
to
+53
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. super nit: (not blocking) The interactivity check could move above the |
||
| let options: Vec<String> = workspaces | ||
| .iter() | ||
| .map(|w| format!("{} ({})", w.name, w.public_id)) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: (not blocking) The placeholders
<n>and<t>are easy to misread —<name>and<type>would match the actual flag names and be clearer to anyone copy-pasting. Also the nested single quotes in--config '{{…}}'produce a shell-broken example as displayed (terminating then immediately reopening); double-quoting the JSON would be friendlier, e.g.: