@@ -24,6 +24,8 @@ interface ValueOptionSpec {
2424 | "scrapMode"
2525 | "label"
2626 | "gitTokenLabel"
27+ | "codexTokenLabel"
28+ | "claudeTokenLabel"
2729 | "token"
2830 | "scopes"
2931 | "message"
@@ -53,6 +55,8 @@ const valueOptionSpecs: ReadonlyArray<ValueOptionSpec> = [
5355 { flag : "--mode" , key : "scrapMode" } ,
5456 { flag : "--label" , key : "label" } ,
5557 { flag : "--git-token" , key : "gitTokenLabel" } ,
58+ { flag : "--codex-token" , key : "codexTokenLabel" } ,
59+ { flag : "--claude-token" , key : "claudeTokenLabel" } ,
5660 { flag : "--token" , key : "token" } ,
5761 { flag : "--scopes" , key : "scopes" } ,
5862 { flag : "--message" , key : "message" } ,
@@ -102,6 +106,8 @@ const valueFlagUpdaters: { readonly [K in ValueKey]: (raw: RawOptions, value: st
102106 scrapMode : ( raw , value ) => ( { ...raw , scrapMode : value } ) ,
103107 label : ( raw , value ) => ( { ...raw , label : value } ) ,
104108 gitTokenLabel : ( raw , value ) => ( { ...raw , gitTokenLabel : value } ) ,
109+ codexTokenLabel : ( raw , value ) => ( { ...raw , codexTokenLabel : value } ) ,
110+ claudeTokenLabel : ( raw , value ) => ( { ...raw , claudeTokenLabel : value } ) ,
105111 token : ( raw , value ) => ( { ...raw , token : value } ) ,
106112 scopes : ( raw , value ) => ( { ...raw , scopes : value } ) ,
107113 message : ( raw , value ) => ( { ...raw , message : value } ) ,
@@ -129,47 +135,68 @@ export const applyCommandValueFlag = (
129135 return Either . right ( update ( raw , value ) )
130136}
131137
132- export const parseRawOptions = ( args : ReadonlyArray < string > ) : Either . Either < RawOptions , ParseError > => {
133- let index = 0
134- let raw : RawOptions = { }
138+ type ParseRawOptionsStep =
139+ | { readonly _tag : "ok" ; readonly raw : RawOptions ; readonly nextIndex : number }
140+ | { readonly _tag : "error" ; readonly error : ParseError }
135141
136- while ( index < args . length ) {
137- const token = args [ index ] ?? ""
138- const equalIndex = token . indexOf ( "=" )
139- if ( equalIndex > 0 && token . startsWith ( "-" ) ) {
140- const flag = token . slice ( 0 , equalIndex )
141- const inlineValue = token . slice ( equalIndex + 1 )
142- const nextRaw = applyCommandValueFlag ( raw , flag , inlineValue )
143- if ( Either . isLeft ( nextRaw ) ) {
144- return Either . left ( nextRaw . left )
145- }
146- raw = nextRaw . right
147- index += 1
148- continue
149- }
142+ const parseInlineValueToken = (
143+ raw : RawOptions ,
144+ token : string
145+ ) : Either . Either < RawOptions , ParseError > | null => {
146+ const equalIndex = token . indexOf ( "=" )
147+ if ( equalIndex <= 0 || ! token . startsWith ( "-" ) ) {
148+ return null
149+ }
150150
151- const booleanApplied = applyCommandBooleanFlag ( raw , token )
152- if ( booleanApplied !== null ) {
153- raw = booleanApplied
154- index += 1
155- continue
156- }
151+ const flag = token . slice ( 0 , equalIndex )
152+ const inlineValue = token . slice ( equalIndex + 1 )
153+ return applyCommandValueFlag ( raw , flag , inlineValue )
154+ }
157155
158- if ( ! token . startsWith ( "-" ) ) {
159- return Either . left ( { _tag : "UnexpectedArgument" , value : token } )
160- }
156+ const parseRawOptionsStep = (
157+ args : ReadonlyArray < string > ,
158+ index : number ,
159+ raw : RawOptions
160+ ) : ParseRawOptionsStep => {
161+ const token = args [ index ] ?? ""
162+ const inlineApplied = parseInlineValueToken ( raw , token )
163+ if ( inlineApplied !== null ) {
164+ return Either . isLeft ( inlineApplied )
165+ ? { _tag : "error" , error : inlineApplied . left }
166+ : { _tag : "ok" , raw : inlineApplied . right , nextIndex : index + 1 }
167+ }
161168
162- const value = args [ index + 1 ]
163- if ( value === undefined ) {
164- return Either . left ( { _tag : "MissingOptionValue" , option : token } )
165- }
169+ const booleanApplied = applyCommandBooleanFlag ( raw , token )
170+ if ( booleanApplied !== null ) {
171+ return { _tag : "ok" , raw : booleanApplied , nextIndex : index + 1 }
172+ }
173+
174+ if ( ! token . startsWith ( "-" ) ) {
175+ return { _tag : "error" , error : { _tag : "UnexpectedArgument" , value : token } }
176+ }
177+
178+ const value = args [ index + 1 ]
179+ if ( value === undefined ) {
180+ return { _tag : "error" , error : { _tag : "MissingOptionValue" , option : token } }
181+ }
182+
183+ const nextRaw = applyCommandValueFlag ( raw , token , value )
184+ return Either . isLeft ( nextRaw )
185+ ? { _tag : "error" , error : nextRaw . left }
186+ : { _tag : "ok" , raw : nextRaw . right , nextIndex : index + 2 }
187+ }
188+
189+ export const parseRawOptions = ( args : ReadonlyArray < string > ) : Either . Either < RawOptions , ParseError > => {
190+ let index = 0
191+ let raw : RawOptions = { }
166192
167- const nextRaw = applyCommandValueFlag ( raw , token , value )
168- if ( Either . isLeft ( nextRaw ) ) {
169- return Either . left ( nextRaw . left )
193+ while ( index < args . length ) {
194+ const step = parseRawOptionsStep ( args , index , raw )
195+ if ( step . _tag === "error" ) {
196+ return Either . left ( step . error )
170197 }
171- raw = nextRaw . right
172- index += 2
198+ raw = step . raw
199+ index = step . nextIndex
173200 }
174201
175202 return Either . right ( raw )
0 commit comments