Skip to content

Commit dde4d0c

Browse files
authored
Merge pull request #165 from syncable-dev/develop
feat: Removed Update Banner on json outputs
2 parents 518d792 + bdd43bf commit dde4d0c

1 file changed

Lines changed: 34 additions & 10 deletions

File tree

src/main.rs

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,16 @@ async fn run() -> syncable_cli::Result<()> {
3939
println!("✅ Update cache cleared. Checking for updates now...");
4040
}
4141

42-
check_for_update().await;
42+
// Suppress update banner when JSON output is requested
43+
let suppress_update_banner = cli.json || matches!(
44+
&cli.command,
45+
Commands::Analyze { json: true, .. }
46+
| Commands::Dependencies { format: OutputFormat::Json, .. }
47+
| Commands::Vulnerabilities { format: OutputFormat::Json, .. }
48+
| Commands::Security { format: OutputFormat::Json, .. }
49+
| Commands::Tools { command: ToolsCommand::Status { format: OutputFormat::Json, .. } }
50+
);
51+
check_for_update(suppress_update_banner).await;
4352

4453
// Initialize logging
4554
cli.init_logging();
@@ -266,7 +275,10 @@ async fn run() -> syncable_cli::Result<()> {
266275
properties.insert("dev_only".to_string(), json!(true));
267276
}
268277

269-
let format_str = match format {
278+
// Honor global --json flag for output selection
279+
let effective_format = if cli.json { OutputFormat::Json } else { format };
280+
281+
let format_str = match effective_format {
270282
OutputFormat::Table => "table",
271283
OutputFormat::Json => "json",
272284
};
@@ -277,7 +289,7 @@ async fn run() -> syncable_cli::Result<()> {
277289
telemetry_client.track_dependencies(properties);
278290
}
279291

280-
handle_dependencies(path, licenses, vulnerabilities, prod_only, dev_only, format)
292+
handle_dependencies(path, licenses, vulnerabilities, prod_only, dev_only, effective_format)
281293
.await
282294
.map(|_| ())
283295
},
@@ -300,7 +312,10 @@ async fn run() -> syncable_cli::Result<()> {
300312
properties.insert("severity_threshold".to_string(), json!(severity_str));
301313
}
302314

303-
let format_str = match format {
315+
// Honor global --json flag for output selection
316+
let effective_format = if cli.json { OutputFormat::Json } else { format };
317+
318+
let format_str = match effective_format {
304319
OutputFormat::Table => "table",
305320
OutputFormat::Json => "json",
306321
};
@@ -315,7 +330,7 @@ async fn run() -> syncable_cli::Result<()> {
315330
telemetry_client.track_vulnerabilities(properties);
316331
}
317332

318-
handle_vulnerabilities(path, severity, format, output).await
333+
handle_vulnerabilities(path, severity, effective_format, output).await
319334
},
320335
Commands::Security {
321336
path,
@@ -366,7 +381,10 @@ async fn run() -> syncable_cli::Result<()> {
366381
properties.insert("compliance_frameworks".to_string(), json!(frameworks));
367382
}
368383

369-
let format_str = match format {
384+
// Honor global --json flag for output selection
385+
let effective_format = if cli.json { OutputFormat::Json } else { format };
386+
387+
let format_str = match effective_format {
370388
OutputFormat::Table => "table",
371389
OutputFormat::Json => "json",
372390
};
@@ -394,7 +412,7 @@ async fn run() -> syncable_cli::Result<()> {
394412
no_infrastructure,
395413
no_compliance,
396414
frameworks,
397-
format,
415+
effective_format,
398416
output,
399417
fail_on_findings,
400418
)
@@ -506,7 +524,11 @@ fn clear_update_cache() {
506524
}
507525
}
508526

509-
async fn check_for_update() {
527+
async fn check_for_update(suppress_output: bool) {
528+
// In JSON mode (or when suppressed), avoid any banner or network I/O
529+
if suppress_output {
530+
return;
531+
}
510532
let cache_dir_path = cache_dir()
511533
.unwrap_or_else(|| PathBuf::from("."))
512534
.join("syncable-cli");
@@ -617,7 +639,9 @@ async fn check_for_update() {
617639
&& latest != current
618640
&& is_version_newer(current, latest)
619641
{
620-
show_update_notification(current, latest);
642+
if !suppress_output {
643+
show_update_notification(current, latest);
644+
}
621645
}
622646
}
623647
Err(e) => {
@@ -1136,4 +1160,4 @@ pub fn handle_security(
11361160

11371161
async fn handle_tools(command: ToolsCommand) -> syncable_cli::Result<()> {
11381162
syncable_cli::handlers::tools::handle_tools(command).await
1139-
}
1163+
}

0 commit comments

Comments
 (0)