Skip to content

Commit 349564a

Browse files
committed
fix: address clippy warnings and env var expansion issues
- Fix collapsible_if and collapsible_else_if clippy warnings - Make config parsing more resilient to missing environment variables - Use shellexpand::env_with_context_no_errors to avoid errors for unused profiles - Allows users to use profiles without having all env vars set
1 parent fb6906f commit 349564a

File tree

2 files changed

+21
-26
lines changed

2 files changed

+21
-26
lines changed

crates/redisctl/src/commands/enterprise/support_package.rs

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -502,16 +502,15 @@ async fn generate_node_package(
502502

503503
// Try to get node info for display
504504
let mut node_address = None;
505-
if let Some(node_uid) = uid {
506-
if let Ok(node_info) = client
505+
if let Some(node_uid) = uid
506+
&& let Ok(node_info) = client
507507
.get::<serde_json::Value>(&format!("/v1/nodes/{}", node_uid))
508508
.await
509-
{
510-
node_address = node_info
511-
.get("addr")
512-
.and_then(|v| v.as_str())
513-
.map(String::from);
514-
}
509+
{
510+
node_address = node_info
511+
.get("addr")
512+
.and_then(|v| v.as_str())
513+
.map(String::from);
515514
}
516515

517516
// Only show interactive output if not in JSON mode
@@ -570,18 +569,16 @@ async fn generate_node_package(
570569
.await
571570
.context("Failed to collect node debug info")?
572571
}
572+
} else if use_new_api {
573+
debuginfo_handler
574+
.nodes_debuginfo_binary()
575+
.await
576+
.context("Failed to collect all nodes debug info")?
573577
} else {
574-
if use_new_api {
575-
debuginfo_handler
576-
.nodes_debuginfo_binary()
577-
.await
578-
.context("Failed to collect all nodes debug info")?
579-
} else {
580-
debuginfo_handler
581-
.node_binary()
582-
.await
583-
.context("Failed to collect node debug info")?
584-
}
578+
debuginfo_handler
579+
.node_binary()
580+
.await
581+
.context("Failed to collect node debug info")?
585582
};
586583

587584
if let Some(spinner) = spinner {

crates/redisctl/src/config.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -337,13 +337,11 @@ impl Config {
337337
/// api_url = "${REDIS_CLOUD_API_URL:-https://api.redislabs.com/v1}"
338338
/// ```
339339
fn expand_env_vars(content: &str) -> Result<String> {
340-
match shellexpand::env(content) {
341-
Ok(expanded) => Ok(expanded.to_string()),
342-
Err(e) => Err(anyhow::anyhow!(
343-
"Environment variable expansion failed: {}",
344-
e
345-
)),
346-
}
340+
// Use shellexpand::env_with_context_no_errors which returns unexpanded vars as-is
341+
// This prevents errors when env vars for unused profiles aren't set
342+
let expanded =
343+
shellexpand::env_with_context_no_errors(content, |var| std::env::var(var).ok());
344+
Ok(expanded.to_string())
347345
}
348346
}
349347

0 commit comments

Comments
 (0)