From 0d80ba049148706f8cc60404b0629e63e51aa64c Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Tue, 2 Mar 2021 14:06:03 +0100 Subject: sq: Be smarter about emitting the unstable CLI warning. - Only emit the warning if we detect non-interactive use and are emitting data that could be scraped resulting in fragile constructs. - Fixes #653. --- sq/src/sq.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/sq/src/sq.rs b/sq/src/sq.rs index 7eaef9d3..55995c34 100644 --- a/sq/src/sq.rs +++ b/sq/src/sq.rs @@ -343,6 +343,8 @@ fn emit_unstable_cli_warning() { pub struct Config<'a> { force: bool, policy: P<'a>, + /// Have we emitted the warning yet? + unstable_cli_warning_emitted: bool, } impl Config<'_> { @@ -362,8 +364,12 @@ impl Config<'_> { /// /// If our heuristic detects non-interactive use, we will emit a /// warning. - fn create_or_stdout_unsafe(&self, f: Option<&str>) + fn create_or_stdout_unsafe(&mut self, f: Option<&str>) -> Result> { + if ! self.unstable_cli_warning_emitted { + emit_unstable_cli_warning(); + self.unstable_cli_warning_emitted = true; + } #[allow(deprecated)] create_or_stdout(f, self.force) } @@ -391,7 +397,6 @@ fn main() -> Result<()> { policy.accept_critical_subpacket(SubpacketTag::RegularExpression); let matches = sq_cli::build().get_matches(); - emit_unstable_cli_warning(); let known_notations: Vec<&str> = matches.values_of("known-notation") .unwrap_or_default() @@ -400,9 +405,10 @@ fn main() -> Result<()> { let force = matches.is_present("force"); - let config = Config { + let mut config = Config { force, policy: policy.clone(), + unstable_cli_warning_emitted: false, }; match matches.subcommand() { -- cgit v1.2.3