@@ -67,7 +67,19 @@ impl ConfigContext {
6767 /// so the check runs here and surfaces through `config_error` for every
6868 /// command that applies shared options, not just the pi-store readers.
6969 fn detect_date_bound_error ( & self ) -> Option < String > {
70- self . option_maps ( ) . into_iter ( ) . find_map ( date_bound_error)
70+ self . option_maps ( ) . into_iter ( ) . find_map ( |options| {
71+ let options = SharedOptions :: from_map ( options) ;
72+ [ ( "since" , options. since ) , ( "until" , options. until ) ]
73+ . into_iter ( )
74+ . find_map ( |( key, value) | {
75+ let value = value?;
76+ normalize_date_bound ( & value) . is_none ( ) . then ( || {
77+ config_error ( format ! (
78+ "{key} '{value}' is not a valid date. Expected {DATE_BOUND_FORMATS}"
79+ ) )
80+ } )
81+ } )
82+ } )
7183 }
7284
7385 fn option_maps ( & self ) -> Vec < & Map < String , Value > > {
@@ -341,7 +353,6 @@ fn option_takes_value(arg: &str) -> bool {
341353 "-s" | "--since"
342354 | "-u"
343355 | "--until"
344- | "--last"
345356 | "-m"
346357 | "--mode"
347358 | "--debug-samples"
@@ -369,31 +380,9 @@ fn option_takes_value(arg: &str) -> bool {
369380 | "--refresh-interval"
370381 | "--context-low-threshold"
371382 | "--context-medium-threshold"
372- | "--sections"
373383 )
374384}
375385
376- fn date_bound_error ( options : & Map < String , Value > ) -> Option < String > {
377- [
378- ( "since" , options. get ( "since" ) ) ,
379- ( "until" , options. get ( "until" ) ) ,
380- ]
381- . into_iter ( )
382- . find_map ( |( key, value) | {
383- let value = value?;
384- let Some ( value) = value. as_str ( ) else {
385- return Some ( config_error ( format ! (
386- "{key} must be a string. Expected {DATE_BOUND_FORMATS}"
387- ) ) ) ;
388- } ;
389- normalize_date_bound ( value) . is_none ( ) . then ( || {
390- config_error ( format ! (
391- "{key} '{value}' is not a valid date. Expected {DATE_BOUND_FORMATS}"
392- ) )
393- } )
394- } )
395- }
396-
397386fn is_agent_command ( command : & str ) -> bool {
398387 ccusage_core:: BUILT_IN_AGENT_NAMES . contains ( & command)
399388}
@@ -1231,23 +1220,6 @@ mod tests {
12311220 ) ;
12321221 }
12331222
1234- #[ test]
1235- fn rejects_config_date_bounds_that_are_not_strings ( ) {
1236- let config = config_context_from_json ( r#"{ "defaults": { "since": 20260710 } }"# ) ;
1237-
1238- assert_eq ! (
1239- config. config_error( ) ,
1240- Some ( "Invalid ccusage config: since must be a string. Expected YYYY-MM-DD or YYYYMMDD" )
1241- ) ;
1242-
1243- let config = config_context_from_json ( r#"{ "defaults": { "until": null } }"# ) ;
1244-
1245- assert_eq ! (
1246- config. config_error( ) ,
1247- Some ( "Invalid ccusage config: until must be a string. Expected YYYY-MM-DD or YYYYMMDD" )
1248- ) ;
1249- }
1250-
12511223 #[ test]
12521224 fn rejects_config_date_bounds_for_commands_without_named_pi_stores ( ) {
12531225 for command in [
@@ -1301,31 +1273,6 @@ mod tests {
13011273 assert_eq ! ( shared. until. as_deref( ) , Some ( "20260131" ) ) ;
13021274 }
13031275
1304- #[ test]
1305- fn detects_command_specific_date_bounds_after_root_value_options ( ) {
1306- let config = config_context_for_args (
1307- r#"{ "commands": { "weekly": { "since": "not-a-date" } } }"# ,
1308- & [ "--last" , "1" , "weekly" ] ,
1309- ) ;
1310- assert_eq ! (
1311- config. config_error( ) ,
1312- Some (
1313- "Invalid ccusage config: since 'not-a-date' is not a valid date. Expected YYYY-MM-DD or YYYYMMDD"
1314- )
1315- ) ;
1316-
1317- let config = config_context_for_args (
1318- r#"{ "commands": { "daily": { "until": "not-a-date" } } }"# ,
1319- & [ "--sections" , "monthly,session" ] ,
1320- ) ;
1321- assert_eq ! (
1322- config. config_error( ) ,
1323- Some (
1324- "Invalid ccusage config: until 'not-a-date' is not a valid date. Expected YYYY-MM-DD or YYYYMMDD"
1325- )
1326- ) ;
1327- }
1328-
13291276 fn context ( value : Value , raw : & str , agent : Option < & str > , report : & str ) -> ConfigContext {
13301277 ConfigContext {
13311278 value : Some ( value) ,
@@ -1345,10 +1292,6 @@ mod tests {
13451292 }
13461293
13471294 fn config_context_for_command ( raw : & str , command : & [ & str ] ) -> ConfigContext {
1348- config_context_for_args ( raw, command)
1349- }
1350-
1351- fn config_context_for_args ( raw : & str , command : & [ & str ] ) -> ConfigContext {
13521295 let fixture = fs_fixture ! ( {
13531296 "ccusage.json" : raw,
13541297 } ) ;
0 commit comments