feat(opencode): add search to auth logout command (#31053)
This commit is contained in:
parent
fa2b63f850
commit
3f0ef9b71c
2 changed files with 33 additions and 14 deletions
|
|
@ -505,11 +505,16 @@ export const ProvidersLoginCommand = effectCmd({
|
||||||
})
|
})
|
||||||
|
|
||||||
export const ProvidersLogoutCommand = effectCmd({
|
export const ProvidersLogoutCommand = effectCmd({
|
||||||
command: "logout",
|
command: "logout [provider]",
|
||||||
describe: "log out from a configured provider",
|
describe: "log out from a configured provider",
|
||||||
|
builder: (yargs) =>
|
||||||
|
yargs.positional("provider", {
|
||||||
|
describe: "provider id or name to log out from",
|
||||||
|
type: "string",
|
||||||
|
}),
|
||||||
// Removes a global auth credential; no project instance needed.
|
// Removes a global auth credential; no project instance needed.
|
||||||
instance: false,
|
instance: false,
|
||||||
handler: Effect.fn("Cli.providers.logout")(function* (_args) {
|
handler: Effect.fn("Cli.providers.logout")(function* (args) {
|
||||||
const authSvc = yield* Auth.Service
|
const authSvc = yield* Auth.Service
|
||||||
const modelsDev = yield* ModelsDev.Service
|
const modelsDev = yield* ModelsDev.Service
|
||||||
|
|
||||||
|
|
@ -521,14 +526,25 @@ export const ProvidersLogoutCommand = effectCmd({
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const database = yield* modelsDev.get()
|
const database = yield* modelsDev.get()
|
||||||
const selected = yield* Prompt.select({
|
const options = credentials.map(([key, value]) => ({
|
||||||
message: "Select provider",
|
label: (database[key]?.name || key) + UI.Style.TEXT_DIM + " (" + value.type + ")",
|
||||||
options: credentials.map(([key, value]) => ({
|
value: key,
|
||||||
label: (database[key]?.name || key) + UI.Style.TEXT_DIM + " (" + value.type + ")",
|
}))
|
||||||
value: key,
|
const provider = args.provider
|
||||||
})),
|
? options.find(
|
||||||
})
|
(option) =>
|
||||||
yield* Effect.orDie(authSvc.remove(yield* promptValue(selected)))
|
option.value === args.provider ||
|
||||||
|
database[option.value]?.name?.toLowerCase() === args.provider?.toLowerCase(),
|
||||||
|
)?.value
|
||||||
|
: yield* promptValue(
|
||||||
|
yield* Prompt.autocomplete({
|
||||||
|
message: "Select provider",
|
||||||
|
maxItems: 8,
|
||||||
|
options,
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
if (!provider) return yield* fail(`Unknown configured provider "${args.provider}"`)
|
||||||
|
yield* Effect.orDie(authSvc.remove(provider))
|
||||||
yield* Prompt.outro("Logout successful")
|
yield* Prompt.outro("Logout successful")
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -149,9 +149,9 @@ exports[`opencode CLI help-text snapshots every documented command emits stable
|
||||||
manage AI providers and credentials
|
manage AI providers and credentials
|
||||||
|
|
||||||
Commands:
|
Commands:
|
||||||
opencode providers list list providers and credentials [aliases: ls]
|
opencode providers list list providers and credentials [aliases: ls]
|
||||||
opencode providers login [url] log in to a provider
|
opencode providers login [url] log in to a provider
|
||||||
opencode providers logout log out from a configured provider
|
opencode providers logout [provider] log out from a configured provider
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
-h, --help show help [boolean]
|
-h, --help show help [boolean]
|
||||||
|
|
@ -504,10 +504,13 @@ Options:
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`opencode CLI help-text snapshots every documented command emits stable help text: opencode providers logout --help 1`] = `
|
exports[`opencode CLI help-text snapshots every documented command emits stable help text: opencode providers logout --help 1`] = `
|
||||||
"opencode providers logout
|
"opencode providers logout [provider]
|
||||||
|
|
||||||
log out from a configured provider
|
log out from a configured provider
|
||||||
|
|
||||||
|
Positionals:
|
||||||
|
provider provider id or name to log out from [string]
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
-h, --help show help [boolean]
|
-h, --help show help [boolean]
|
||||||
-v, --version show version number [boolean]
|
-v, --version show version number [boolean]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue