Skip to content

Commit cfdb42b

Browse files
committed
fix(cli): suppress dead_code and unused_mut warnings under test cfg
Gate file I/O imports and config-loading functions with #[cfg(not(test))] since they are only reachable from the non-test code path, and move the mut rebinding of cli inside that block to silence the unused_mut warning. Signed-off-by: Sam Betts <1769706+Tehsmash@users.noreply.github.com>
1 parent 17267ed commit cfdb42b

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

a2acli/src/config.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright AGNTCY Contributors (https://github.com/agntcy)
22
// SPDX-License-Identifier: Apache-2.0
3+
#[cfg(not(test))]
34
use std::fs::File;
5+
#[cfg(not(test))]
46
use std::io::BufReader;
57
use std::path::{Path, PathBuf};
68

@@ -34,6 +36,7 @@ pub enum ConfigError {
3436

3537
const CONFIG_FILENAME: &str = ".a2a.yaml";
3638

39+
#[cfg(not(test))]
3740
pub fn find_config_file() -> Option<PathBuf> {
3841
let cwd = std::env::current_dir().ok()?;
3942
let home = home_dir();
@@ -44,6 +47,7 @@ pub fn find_config_file() -> Option<PathBuf> {
4447
})
4548
}
4649

50+
#[cfg(not(test))]
4751
fn home_dir() -> Option<PathBuf> {
4852
std::env::var_os("HOME")
4953
.or_else(|| std::env::var_os("USERPROFILE"))
@@ -68,6 +72,7 @@ fn find_config_file_from(start: &Path, home: Option<&Path>) -> Option<PathBuf> {
6872
None
6973
}
7074

75+
#[cfg(not(test))]
7176
pub fn load_config() -> Result<(Config, Option<PathBuf>), ConfigError> {
7277
match find_config_file() {
7378
Some(path) => {

a2acli/src/lib.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,12 +354,14 @@ pub enum CliError {
354354
Config(#[from] config::ConfigError),
355355
}
356356

357-
pub async fn run(mut cli: Cli) -> Result<(), CliError> {
357+
pub async fn run(cli: Cli) -> Result<(), CliError> {
358358
#[cfg(not(test))]
359-
{
359+
let cli = {
360+
let mut cli = cli;
360361
let (cfg, cfg_path) = config::load_config()?;
361362
config::apply_config(&mut cli, &cfg, &cfg_path)?;
362-
}
363+
cli
364+
};
363365
let compact = cli.output.unwrap_or(OutputFormat::Pretty) == OutputFormat::Json;
364366

365367
match &cli.command {

0 commit comments

Comments
 (0)