diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2021-03-02 14:06:03 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2021-03-02 14:11:15 +0100 |
commit | 0d80ba049148706f8cc60404b0629e63e51aa64c (patch) | |
tree | 66f2dacaf6d0043c7ad6b9adb94964784f6cc8d2 | |
parent | a2e8337777242e2d97e4476581a70e2eec4f3cb9 (diff) |
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.
-rw-r--r-- | sq/src/sq.rs | 12 |
1 files 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<Box<dyn io::Write + Sync + Send>> { + 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() { |