Remove the unstable CLI warning.

This commit is contained in:
Justus Winter 2024-12-14 12:20:44 +01:00
parent 68e355690b
commit 69e21afd60
No known key found for this signature in database
GPG Key ID: 686F55B4AB2B3386

View File

@ -38,14 +38,10 @@ impl FileOrStdout {
/// Opens the file (or stdout) for writing data that is NOT safe /// Opens the file (or stdout) for writing data that is NOT safe
/// for non-interactive use. /// for non-interactive use.
///
/// If our heuristic detects non-interactive use, we will emit a
/// warning once.
pub fn create_unsafe( pub fn create_unsafe(
&self, &self,
sq: &Sq, sq: &Sq,
) -> Result<Box<dyn Write + Sync + Send>> { ) -> Result<Box<dyn Write + Sync + Send>> {
CliWarningOnce::warn();
self.create(sq) self.create(sq)
} }
@ -170,27 +166,3 @@ impl<W: io::Write + Send + Sync> SecretLeakDetector<W> {
Ok(()) Ok(())
} }
} }
struct CliWarningOnce(());
impl CliWarningOnce {
/// Emit a warning message only once
pub fn warn() {
use std::sync::Once;
static WARNING: Once = Once::new();
WARNING.call_once(|| {
// stdout is connected to a terminal, assume interactive use.
use std::io::IsTerminal;
if ! std::io::stdout().is_terminal()
// For bash shells, we can use a very simple heuristic.
// We simply look at whether the COLUMNS variable is defined in
// our environment.
&& std::env::var_os("COLUMNS").is_none() {
eprintln!(
"\nWARNING: sq does not have a stable CLI interface, \
and the human-readable output should not be parsed.\n\
Use with caution in scripts.\n"
);
}
});
}
}