File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import { defineCommand , parseArgs , showUsage , type ArgsDef } from "citty"
2+
3+ const args = {
4+ help : {
5+ alias : "h" ,
6+ type : "boolean" ,
7+ default : false ,
8+ description : "Show this help message" ,
9+ } ,
10+ stream : {
11+ alias : "s" ,
12+ type : "boolean" ,
13+ default : false ,
14+ description : "Enable streaming response for chat completions" ,
15+ } ,
16+ port : {
17+ alias : "p" ,
18+ type : "string" ,
19+ default : "4141" ,
20+ description : "Port to listen on" ,
21+ } ,
22+ } satisfies ArgsDef
23+
24+ export interface CliOptions {
25+ help : boolean
26+ stream : boolean
27+ port : string
28+ }
29+
30+ export async function parseCli ( ) {
31+ const command = defineCommand ( { args } )
32+ const options = parseArgs < typeof args > ( Bun . argv , args )
33+
34+ if ( options . help ) {
35+ await showUsage ( command )
36+ process . exit ( )
37+ }
38+
39+ return options
40+ }
Original file line number Diff line number Diff line change 11import type { Serve } from "bun"
22
3- import { defineCommand , parseArgs , showUsage , type ArgsDef } from "citty"
4-
3+ import { parseCli } from "./lib/cli"
54import { initialize } from "./lib/initialization"
65import { server } from "./server"
76
8- const args : ArgsDef = {
9- help : {
10- alias : "h" ,
11- type : "boolean" ,
12- default : false ,
13- description : "Show this help message" ,
14- } ,
15- stream : {
16- alias : "s" ,
17- type : "boolean" ,
18- default : false ,
19- description : "Enable streaming response for chat completions" ,
20- } ,
21- port : {
22- alias : "p" ,
23- type : "string" ,
24- default : "4141" ,
25- description : "Port to listen on" ,
26- } ,
27- }
28-
29- const command = defineCommand ( { args } )
30- const options = parseArgs ( Bun . argv , args )
31-
32- if ( options . help ) {
33- await showUsage ( command )
34- process . exit ( )
35- }
36-
7+ const options = await parseCli ( )
378await initialize ( )
389
3910export default {
4011 fetch : server . fetch ,
41- port : parseInt ( options . port as string ) ,
12+ port : parseInt ( options . port , 10 ) ,
4213} satisfies Serve
You can’t perform that action at this time.
0 commit comments