refactor(auth): replace manual input handling with AsyncPrompt for callback URLs
This commit is contained in:
@@ -329,18 +329,7 @@ waitForCallback:
|
||||
return nil, err
|
||||
default:
|
||||
}
|
||||
inputCh := make(chan string, 1)
|
||||
inputErrCh := make(chan error, 1)
|
||||
go func() {
|
||||
input, err := opts.Prompt("Paste the Gemini callback URL (or press Enter to keep waiting): ")
|
||||
if err != nil {
|
||||
inputErrCh <- err
|
||||
return
|
||||
}
|
||||
inputCh <- input
|
||||
}()
|
||||
manualInputCh = inputCh
|
||||
manualInputErrCh = inputErrCh
|
||||
manualInputCh, manualInputErrCh = misc.AsyncPrompt(opts.Prompt, "Paste the Gemini callback URL (or press Enter to keep waiting): ")
|
||||
continue
|
||||
case input := <-manualInputCh:
|
||||
manualInputCh = nil
|
||||
|
||||
@@ -30,6 +30,23 @@ type OAuthCallback struct {
|
||||
ErrorDescription string
|
||||
}
|
||||
|
||||
// AsyncPrompt runs a prompt function in a goroutine and returns channels for
|
||||
// the result. The returned channels are buffered (size 1) so the goroutine can
|
||||
// complete even if the caller abandons the channels.
|
||||
func AsyncPrompt(promptFn func(string) (string, error), message string) (<-chan string, <-chan error) {
|
||||
inputCh := make(chan string, 1)
|
||||
errCh := make(chan error, 1)
|
||||
go func() {
|
||||
input, err := promptFn(message)
|
||||
if err != nil {
|
||||
errCh <- err
|
||||
return
|
||||
}
|
||||
inputCh <- input
|
||||
}()
|
||||
return inputCh, errCh
|
||||
}
|
||||
|
||||
// ParseOAuthCallback extracts OAuth parameters from a callback URL.
|
||||
// It returns nil when the input is empty.
|
||||
func ParseOAuthCallback(input string) (*OAuthCallback, error) {
|
||||
|
||||
@@ -118,18 +118,7 @@ waitForCallback:
|
||||
break waitForCallback
|
||||
default:
|
||||
}
|
||||
inputCh := make(chan string, 1)
|
||||
inputErrCh := make(chan error, 1)
|
||||
go func() {
|
||||
input, errPrompt := opts.Prompt("Paste the antigravity callback URL (or press Enter to keep waiting): ")
|
||||
if errPrompt != nil {
|
||||
inputErrCh <- errPrompt
|
||||
return
|
||||
}
|
||||
inputCh <- input
|
||||
}()
|
||||
manualInputCh = inputCh
|
||||
manualInputErrCh = inputErrCh
|
||||
manualInputCh, manualInputErrCh = misc.AsyncPrompt(opts.Prompt, "Paste the antigravity callback URL (or press Enter to keep waiting): ")
|
||||
continue
|
||||
case input := <-manualInputCh:
|
||||
manualInputCh = nil
|
||||
|
||||
@@ -152,18 +152,7 @@ waitForCallback:
|
||||
return nil, err
|
||||
default:
|
||||
}
|
||||
inputCh := make(chan string, 1)
|
||||
inputErrCh := make(chan error, 1)
|
||||
go func() {
|
||||
input, errPrompt := opts.Prompt("Paste the Claude callback URL (or press Enter to keep waiting): ")
|
||||
if errPrompt != nil {
|
||||
inputErrCh <- errPrompt
|
||||
return
|
||||
}
|
||||
inputCh <- input
|
||||
}()
|
||||
manualInputCh = inputCh
|
||||
manualInputErrCh = inputErrCh
|
||||
manualInputCh, manualInputErrCh = misc.AsyncPrompt(opts.Prompt, "Paste the Claude callback URL (or press Enter to keep waiting): ")
|
||||
continue
|
||||
case input := <-manualInputCh:
|
||||
manualInputCh = nil
|
||||
|
||||
@@ -155,18 +155,7 @@ waitForCallback:
|
||||
return nil, err
|
||||
default:
|
||||
}
|
||||
inputCh := make(chan string, 1)
|
||||
inputErrCh := make(chan error, 1)
|
||||
go func() {
|
||||
input, errPrompt := opts.Prompt("Paste the Codex callback URL (or press Enter to keep waiting): ")
|
||||
if errPrompt != nil {
|
||||
inputErrCh <- errPrompt
|
||||
return
|
||||
}
|
||||
inputCh <- input
|
||||
}()
|
||||
manualInputCh = inputCh
|
||||
manualInputErrCh = inputErrCh
|
||||
manualInputCh, manualInputErrCh = misc.AsyncPrompt(opts.Prompt, "Paste the Codex callback URL (or press Enter to keep waiting): ")
|
||||
continue
|
||||
case input := <-manualInputCh:
|
||||
manualInputCh = nil
|
||||
|
||||
@@ -131,18 +131,7 @@ waitForCallback:
|
||||
return nil, fmt.Errorf("iflow auth: callback wait failed: %w", err)
|
||||
default:
|
||||
}
|
||||
inputCh := make(chan string, 1)
|
||||
inputErrCh := make(chan error, 1)
|
||||
go func() {
|
||||
input, errPrompt := opts.Prompt("Paste the iFlow callback URL (or press Enter to keep waiting): ")
|
||||
if errPrompt != nil {
|
||||
inputErrCh <- errPrompt
|
||||
return
|
||||
}
|
||||
inputCh <- input
|
||||
}()
|
||||
manualInputCh = inputCh
|
||||
manualInputErrCh = inputErrCh
|
||||
manualInputCh, manualInputErrCh = misc.AsyncPrompt(opts.Prompt, "Paste the iFlow callback URL (or press Enter to keep waiting): ")
|
||||
continue
|
||||
case input := <-manualInputCh:
|
||||
manualInputCh = nil
|
||||
|
||||
Reference in New Issue
Block a user