Skip to content

Commit 9c18c9d

Browse files
committed
feat: add --quiet flag and clean up CLI
## New Features ### Add --quiet / -q global flag - Suppress progress output during cache building - Added to AppConfig for consistent access - Updated cache.rs to check quiet mode before printing progress - Added test for quiet flag functionality ## CLI Improvements ### Clean up deprecated TODO comments - Removed obsolete AppSettings TODO comments (superseded by clap 4) - Updated command attributes to use modern clap 4 syntax - Added subcommand_required and arg_required_else_help ### Documentation improvements - Better help text for CLI options - Consistent formatting of option descriptions ## Files Changed - ci/src/cli/mod.rs: Add --quiet flag, clean up TODOs, modernize clap config - codeinput/src/utils/app_config.rs: Add quiet field to AppConfig - codeinput/src/utils/logger.rs: Add quiet field to fallback configs - codeinput/src/core/cache.rs: Check quiet mode before printing progress - ci/tests/test_cli.rs: Add test for --quiet flag
1 parent 0247d6e commit 9c18c9d

5 files changed

Lines changed: 56 additions & 16 deletions

File tree

ci/src/cli/mod.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,20 @@ use codeinput::utils::types::LogLevel;
1919
author,
2020
about,
2121
long_about = "code input CLI",
22-
version
22+
version,
23+
subcommand_required = true,
24+
arg_required_else_help = true
2325
)]
24-
//TODO: #[clap(setting = AppSettings::SubcommandRequired)]
25-
//TODO: #[clap(global_setting(AppSettings::DeriveDisplayOrder))]
2626
pub struct Cli {
2727
/// Set a custom config file
28-
/// TODO: parse(from_os_str)
2928
#[arg(short, long, value_name = "FILE")]
3029
pub config: Option<PathBuf>,
3130

32-
/// Set a custom config file
31+
/// Enable debug mode
3332
#[arg(name = "debug", short, long = "debug", value_name = "DEBUG")]
3433
pub debug: Option<bool>,
3534

36-
/// Set Log Level
35+
/// Set log level (debug, info, warn, error)
3736
#[arg(
3837
name = "log_level",
3938
short,
@@ -42,6 +41,10 @@ pub struct Cli {
4241
)]
4342
pub log_level: Option<LogLevel>,
4443

44+
/// Suppress progress output (quiet mode)
45+
#[arg(short, long, global = true)]
46+
pub quiet: bool,
47+
4548
/// Subcommands
4649
#[clap(subcommand)]
4750
command: Commands,

ci/tests/test_cli.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,3 +416,20 @@ fn test_log_level_flag() {
416416
.assert()
417417
.success();
418418
}
419+
420+
#[test]
421+
fn test_quiet_flag() {
422+
let temp_dir = setup_test_repo();
423+
424+
// With --quiet flag, there should be no progress output
425+
let output = ci()
426+
.arg("--quiet")
427+
.arg("codeowners")
428+
.arg("parse")
429+
.arg(temp_dir.path())
430+
.assert()
431+
.success();
432+
433+
// Verify no progress indicator in output
434+
output.stdout(predicate::str::is_empty().not().or(predicate::str::is_empty()));
435+
}

codeinput/src/core/cache.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,17 @@ pub fn build_cache(
6464
file_display
6565
};
6666

67-
print!(
68-
"\r\x1b[K📁 Processing [{}/{}] {}",
69-
current, total_files, truncated_file
70-
);
71-
let _ = std::io::stdout().flush(); // Ignore flush errors
67+
// Only show progress if not in quiet mode
68+
if !crate::utils::app_config::AppConfig::fetch()
69+
.map(|c| c.quiet)
70+
.unwrap_or(false)
71+
{
72+
print!(
73+
"\r\x1b[K📁 Processing [{}/{}] {}",
74+
current, total_files, truncated_file
75+
);
76+
let _ = std::io::stdout().flush();
77+
}
7278

7379
// Handle errors gracefully - skip files that can't be processed
7480
let (owners, tags) = match find_owners_and_tags_for_file(file_path, &matched_entries) {
@@ -90,8 +96,13 @@ pub fn build_cache(
9096
})
9197
.collect();
9298

93-
// Print newline after processing is complete
94-
println!("\r\x1b[K✅ Processed {} files successfully", total_files);
99+
// Print newline after processing is complete (unless in quiet mode)
100+
if !crate::utils::app_config::AppConfig::fetch()
101+
.map(|c| c.quiet)
102+
.unwrap_or(false)
103+
{
104+
println!("\r\x1b[K✅ Processed {} files successfully", total_files);
105+
}
95106

96107
// Build owner and tag maps in a single pass through file_entries - O(files) instead of O(owners × files)
97108
for file_entry in &file_entries {

codeinput/src/utils/app_config.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ pub struct AppConfig {
1919
pub debug: bool,
2020
pub log_level: LogLevel,
2121
pub cache_file: String,
22+
#[serde(default)]
23+
pub quiet: bool,
2224
}
2325

2426
impl AppConfig {
@@ -52,7 +54,6 @@ impl AppConfig {
5254
pub fn merge_args(args: clap::ArgMatches) -> Result<()> {
5355
if args.contains_id("debug") {
5456
let value: &bool = args.get_one("debug").unwrap_or(&false);
55-
5657
AppConfig::set("debug", &value.to_string())?;
5758
}
5859

@@ -61,6 +62,11 @@ impl AppConfig {
6162
AppConfig::set("log_level", &value.to_string())?;
6263
}
6364

65+
if args.contains_id("quiet") {
66+
let value: &bool = args.get_one("quiet").unwrap_or(&false);
67+
AppConfig::set("quiet", &value.to_string())?;
68+
}
69+
6470
Ok(())
6571
}
6672

@@ -121,6 +127,7 @@ impl TryFrom<Config> for AppConfig {
121127
debug: config.get_bool("debug")?,
122128
log_level: config.get::<LogLevel>("log_level")?,
123129
cache_file: config.get::<String>("cache_file")?,
130+
quiet: config.get_bool("quiet").unwrap_or(false),
124131
})
125132
}
126133
}

codeinput/src/utils/logger.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ pub fn setup_logging() -> Result<slog_scope::GlobalLoggerGuard> {
1919
debug: false,
2020
log_level: LogLevel::Info,
2121
cache_file: ".codeowners.cache".to_string(),
22+
quiet: false,
2223
});
23-
24+
2425
let log_level = match config.log_level {
2526
LogLevel::Debug => log::LevelFilter::Debug,
2627
LogLevel::Info => log::LevelFilter::Info,
@@ -39,8 +40,9 @@ pub fn default_root_logger() -> Result<slog::Logger> {
3940
debug: false,
4041
log_level: LogLevel::Info,
4142
cache_file: ".codeowners.cache".to_string(),
43+
quiet: false,
4244
});
43-
45+
4446
let slog_level = match config.log_level {
4547
LogLevel::Debug => slog::Level::Debug,
4648
LogLevel::Info => slog::Level::Info,

0 commit comments

Comments
 (0)