File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import Table from "cli-table3";
33import { define } from "gunshi" ;
44import pc from "picocolors" ;
55import { type LoadOptions , loadUsageData } from "../data-loader.ts" ;
6+ import { parseDateArg } from "../date-validation.ts" ;
67import { log , logger } from "../logger.ts" ;
78import { formatCurrency , formatNumber } from "../utils.ts" ;
89
@@ -11,14 +12,16 @@ export const dailyCommand = define({
1112 description : "Show usage report grouped by date" ,
1213 args : {
1314 since : {
14- type : "string " ,
15+ type : "custom " ,
1516 short : "s" ,
1617 description : "Filter from date (YYYYMMDD format)" ,
18+ parse : parseDateArg ,
1719 } ,
1820 until : {
19- type : "string " ,
21+ type : "custom " ,
2022 short : "u" ,
2123 description : "Filter until date (YYYYMMDD format)" ,
24+ parse : parseDateArg ,
2225 } ,
2326 path : {
2427 type : "string" ,
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import Table from "cli-table3";
33import { define } from "gunshi" ;
44import pc from "picocolors" ;
55import { type LoadOptions , loadSessionData } from "../data-loader.ts" ;
6+ import { parseDateArg } from "../date-validation.ts" ;
67import { log , logger } from "../logger.ts" ;
78import { formatCurrency , formatNumber } from "../utils.ts" ;
89
@@ -11,14 +12,16 @@ export const sessionCommand = define({
1112 description : "Show usage report grouped by conversation session" ,
1213 args : {
1314 since : {
14- type : "string " ,
15+ type : "custom " ,
1516 short : "s" ,
1617 description : "Filter from date (YYYYMMDD format)" ,
18+ parse : parseDateArg ,
1719 } ,
1820 until : {
19- type : "string " ,
21+ type : "custom " ,
2022 short : "u" ,
2123 description : "Filter until date (YYYYMMDD format)" ,
24+ parse : parseDateArg ,
2225 } ,
2326 path : {
2427 type : "string" ,
Original file line number Diff line number Diff line change 1+ import * as v from "valibot" ;
2+ import { dateSchema } from "./types" ;
3+
4+ export const parseDateArg = ( value : string ) : string => {
5+ const result = v . safeParse ( dateSchema , value ) ;
6+ if ( ! result . success ) {
7+ throw new TypeError ( result . issues [ 0 ] . message ) ;
8+ }
9+ return result . output ;
10+ } ;
Original file line number Diff line number Diff line change @@ -34,3 +34,8 @@ export type ModelSpec = v.InferOutput<typeof ModelSpecSchema>;
3434export const LiteLLMModelPricesSchema = v . record ( v . string ( ) , ModelSpecSchema ) ;
3535
3636export type LiteLLMModelPrices = v . InferOutput < typeof LiteLLMModelPricesSchema > ;
37+
38+ export const dateSchema = v . pipe (
39+ v . string ( ) ,
40+ v . regex ( / ^ \d { 8 } $ / , "Date must be in YYYYMMDD format" ) ,
41+ ) ;
You can’t perform that action at this time.
0 commit comments