11import { Either , Match } from "effect"
22
33import type { RawOptions } from "@effect-template/lib/core/command-options"
4- import {
5- type AuthCommand ,
6- type Command ,
7- defaultTemplateConfig ,
8- type ParseError
9- } from "@effect-template/lib/core/domain"
4+ import { type AuthCommand , type Command , type ParseError } from "@effect-template/lib/core/domain"
105
116import { parseRawOptions } from "./parser-options.js"
127
138type AuthOptions = {
149 readonly envGlobalPath : string
1510 readonly codexAuthPath : string
11+ readonly claudeAuthPath : string
1612 readonly label : string | null
1713 readonly token : string | null
1814 readonly scopes : string | null
15+ readonly authWeb : boolean
1916}
2017
2118const missingArgument = ( name : string ) : ParseError => ( {
@@ -34,24 +31,32 @@ const normalizeLabel = (value: string | undefined): string | null => {
3431 return trimmed . length === 0 ? null : trimmed
3532}
3633
34+ const defaultEnvGlobalPath = ".docker-git/.orch/env/global.env"
35+ const defaultCodexAuthPath = ".docker-git/.orch/auth/codex"
36+ const defaultClaudeAuthPath = ".docker-git/.orch/auth/claude"
37+
3738const resolveAuthOptions = ( raw : RawOptions ) : AuthOptions => ( {
38- envGlobalPath : raw . envGlobalPath ?? defaultTemplateConfig . envGlobalPath ,
39- codexAuthPath : raw . codexAuthPath ?? defaultTemplateConfig . codexAuthPath ,
39+ envGlobalPath : raw . envGlobalPath ?? defaultEnvGlobalPath ,
40+ codexAuthPath : raw . codexAuthPath ?? defaultCodexAuthPath ,
41+ claudeAuthPath : defaultClaudeAuthPath ,
4042 label : normalizeLabel ( raw . label ) ,
4143 token : normalizeLabel ( raw . token ) ,
42- scopes : normalizeLabel ( raw . scopes )
44+ scopes : normalizeLabel ( raw . scopes ) ,
45+ authWeb : raw . authWeb === true
4346} )
4447
4548const buildGithubCommand = ( action : string , options : AuthOptions ) : Either . Either < AuthCommand , ParseError > =>
4649 Match . value ( action ) . pipe (
4750 Match . when ( "login" , ( ) =>
48- Either . right < AuthCommand > ( {
49- _tag : "AuthGithubLogin" ,
50- label : options . label ,
51- token : options . token ,
52- scopes : options . scopes ,
53- envGlobalPath : options . envGlobalPath
54- } ) ) ,
51+ options . authWeb && options . token !== null
52+ ? Either . left ( invalidArgument ( "--token" , "cannot be combined with --web" ) )
53+ : Either . right < AuthCommand > ( {
54+ _tag : "AuthGithubLogin" ,
55+ label : options . label ,
56+ token : options . authWeb ? null : options . token ,
57+ scopes : options . scopes ,
58+ envGlobalPath : options . envGlobalPath
59+ } ) ) ,
5560 Match . when ( "status" , ( ) =>
5661 Either . right < AuthCommand > ( {
5762 _tag : "AuthGithubStatus" ,
@@ -89,6 +94,29 @@ const buildCodexCommand = (action: string, options: AuthOptions): Either.Either<
8994 Match . orElse ( ( ) => Either . left ( invalidArgument ( "auth action" , `unknown action '${ action } '` ) ) )
9095 )
9196
97+ const buildClaudeCommand = ( action : string , options : AuthOptions ) : Either . Either < AuthCommand , ParseError > =>
98+ Match . value ( action ) . pipe (
99+ Match . when ( "login" , ( ) =>
100+ Either . right < AuthCommand > ( {
101+ _tag : "AuthClaudeLogin" ,
102+ label : options . label ,
103+ claudeAuthPath : options . claudeAuthPath
104+ } ) ) ,
105+ Match . when ( "status" , ( ) =>
106+ Either . right < AuthCommand > ( {
107+ _tag : "AuthClaudeStatus" ,
108+ label : options . label ,
109+ claudeAuthPath : options . claudeAuthPath
110+ } ) ) ,
111+ Match . when ( "logout" , ( ) =>
112+ Either . right < AuthCommand > ( {
113+ _tag : "AuthClaudeLogout" ,
114+ label : options . label ,
115+ claudeAuthPath : options . claudeAuthPath
116+ } ) ) ,
117+ Match . orElse ( ( ) => Either . left ( invalidArgument ( "auth action" , `unknown action '${ action } '` ) ) )
118+ )
119+
92120const buildAuthCommand = (
93121 provider : string ,
94122 action : string ,
@@ -98,6 +126,8 @@ const buildAuthCommand = (
98126 Match . when ( "github" , ( ) => buildGithubCommand ( action , options ) ) ,
99127 Match . when ( "gh" , ( ) => buildGithubCommand ( action , options ) ) ,
100128 Match . when ( "codex" , ( ) => buildCodexCommand ( action , options ) ) ,
129+ Match . when ( "claude" , ( ) => buildClaudeCommand ( action , options ) ) ,
130+ Match . when ( "cc" , ( ) => buildClaudeCommand ( action , options ) ) ,
101131 Match . orElse ( ( ) => Either . left ( invalidArgument ( "auth provider" , `unknown provider '${ provider } '` ) ) )
102132 )
103133
0 commit comments