Skip to content

Commit 9f44979

Browse files
committed
fix(cli): ignore report dates for statusline
1 parent fb0409f commit 9f44979

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

‎rust/crates/ccusage-cli-parser/src/parser.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,6 +1109,9 @@ fn last_option_error(command: Option<&Command>, root_shared: &SharedArgs) -> Opt
11091109
/// orders them. A reversed window would otherwise load everything and print an
11101110
/// empty report that looks like missing data.
11111111
fn date_window_error(command: Option<&Command>, root_shared: &SharedArgs) -> Option<String> {
1112+
if matches!(command, Some(Command::Statusline(_))) {
1113+
return None;
1114+
}
11121115
let (shared, _) = report_shared(command, root_shared);
11131116
let since = shared.since.as_deref()?;
11141117
let until = shared.until.as_deref()?;

‎rust/crates/ccusage-cli-parser/src/tests.rs‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,30 @@ fn checks_the_date_window_after_config_and_flags_are_merged() {
468468
assert_eq!(args.shared.until.as_deref(), Some("20260930"));
469469
}
470470

471+
#[test]
472+
fn statusline_ignores_reversed_default_date_window() {
473+
let fixture = fs_fixture!({
474+
"ccusage.json": r#"{ "defaults": { "since": "2026-09-14", "until": "2026-09-01" } }"#,
475+
});
476+
let config_path = fixture.path("ccusage.json").to_string_lossy().into_owned();
477+
let args = ["statusline", "--config", config_path.as_str()]
478+
.map(str::to_string)
479+
.to_vec();
480+
let config = ccusage_config::ConfigContext::from_args(&args);
481+
482+
let result = Cli::parse_from_with_config(
483+
std::iter::once(OsString::from("ccusage")).chain(args.iter().map(OsString::from)),
484+
&config,
485+
ccusage_core::DEFAULT_SESSION_DURATION_HOURS,
486+
env!("CARGO_PKG_VERSION"),
487+
);
488+
489+
let Ok(cli) = result else {
490+
panic!("expected statusline to ignore the report date window");
491+
};
492+
assert!(matches!(cli.command, Some(Command::Statusline(_))));
493+
}
494+
471495
#[test]
472496
fn rejects_last_periods_alongside_an_explicit_date_window() {
473497
assert_eq!(

0 commit comments

Comments
 (0)