Skip to content

Commit 89a34cf

Browse files
committed
Fix warnings to account for --error
Using `--no-log` without either `--cron` or `--heartbeat` is now a reasonable usage if `--error` is in the mix.
1 parent bfd4bb5 commit 89a34cf

File tree

1 file changed

+34
-11
lines changed

1 file changed

+34
-11
lines changed

src/cli.rs

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,11 @@ impl Cli {
176176
}
177177
}
178178

179-
fn no_log_and_no_checkins_warning(&self) -> Option<String> {
179+
fn no_log_and_no_data_warning(&self) -> Option<String> {
180180
let no_checkins: bool = self.cron.is_none() && self.heartbeat.is_none();
181+
let no_errors: bool = self.error.is_none();
181182

182-
if no_checkins {
183+
if no_checkins && no_errors {
183184
let using: Option<&str> = if self.no_log {
184185
Some("--no-log")
185186
} else if self.no_stdout && self.no_stderr {
@@ -190,7 +191,7 @@ impl Cli {
190191

191192
if let Some(using) = using {
192193
return Some(format!(
193-
"using {using} without either --cron or --heartbeat; \
194+
"using {using} without either --cron, --heartbeat or --error; \
194195
no data will be sent to AppSignal"
195196
));
196197
}
@@ -206,7 +207,7 @@ impl Cli {
206207
warnings.push(warning);
207208
}
208209

209-
if let Some(warning) = self.no_log_and_no_checkins_warning() {
210+
if let Some(warning) = self.no_log_and_no_data_warning() {
210211
warnings.push(warning);
211212
}
212213

@@ -378,24 +379,46 @@ mod tests {
378379
}
379380

380381
#[test]
381-
fn cli_warnings_no_log_and_no_checkins() {
382-
for (args, warning) in [(
382+
fn cli_warnings_no_log_and_no_data() {
383+
for (args, warning) in [
384+
(
383385
vec!["--no-log"],
384-
"using --no-log without either --cron or --heartbeat; no data will be sent to AppSignal"
386+
Some("using --no-log without either --cron, --heartbeat or --error; no data will be sent to AppSignal")
385387
),
386388
(
387389
vec!["--no-stdout", "--no-stderr"],
388-
"using --no-stdout and --no-stderr without either --cron or --heartbeat; no data will be sent to AppSignal"
389-
)] {
390+
Some("using --no-stdout and --no-stderr without either --cron, --heartbeat or --error; no data will be sent to AppSignal")
391+
),
392+
(
393+
vec!["--no-log", "--no-stdout", "--no-stderr"],
394+
Some("using --no-log without either --cron, --heartbeat or --error; no data will be sent to AppSignal")
395+
),
396+
(
397+
vec!["--no-log", "--cron", "some-cron"],
398+
None
399+
),
400+
(
401+
vec!["--no-log", "--heartbeat", "some-hearttbeat"],
402+
None
403+
),
404+
(
405+
vec!["--no-log", "--error", "some-error"],
406+
None
407+
)
408+
] {
390409
let cli = Cli::try_parse_from(
391410
with_required_args(args)
392411

393412
).expect("failed to parse CLI arguments");
394413

395414
let warnings = cli.warnings();
396415

397-
assert_eq!(warnings.len(), 1);
398-
assert_eq!(warnings[0], warning);
416+
if let Some(warning) = warning {
417+
assert_eq!(warnings.len(), 1);
418+
assert_eq!(warnings[0], warning);
419+
} else {
420+
assert!(warnings.is_empty());
421+
}
399422
}
400423
}
401424

0 commit comments

Comments
 (0)