fix(cli): avoid AppRuntime re-entry for network options (#26052)
This commit is contained in:
@@ -22,7 +22,7 @@ export const AcpCommand = effectCmd({
|
|||||||
},
|
},
|
||||||
handler: Effect.fn("Cli.acp")(function* (args) {
|
handler: Effect.fn("Cli.acp")(function* (args) {
|
||||||
process.env.OPENCODE_CLIENT = "acp"
|
process.env.OPENCODE_CLIENT = "acp"
|
||||||
const opts = yield* Effect.promise(() => resolveNetworkOptions(args))
|
const opts = yield* resolveNetworkOptions(args)
|
||||||
const server = yield* Effect.promise(() => Server.listen(opts))
|
const server = yield* Effect.promise(() => Server.listen(opts))
|
||||||
|
|
||||||
const sdk = createOpencodeClient({
|
const sdk = createOpencodeClient({
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ export const ServeCommand = effectCmd({
|
|||||||
if (!Flag.OPENCODE_SERVER_PASSWORD) {
|
if (!Flag.OPENCODE_SERVER_PASSWORD) {
|
||||||
console.log("Warning: OPENCODE_SERVER_PASSWORD is not set; server is unsecured.")
|
console.log("Warning: OPENCODE_SERVER_PASSWORD is not set; server is unsecured.")
|
||||||
}
|
}
|
||||||
const opts = yield* Effect.promise(() => resolveNetworkOptions(args))
|
const opts = yield* resolveNetworkOptions(args)
|
||||||
const server = yield* Effect.promise(() => Server.listen(opts))
|
const server = yield* Effect.promise(() => Server.listen(opts))
|
||||||
console.log(`opencode server listening on http://${server.hostname}:${server.port}`)
|
console.log(`opencode server listening on http://${server.hostname}:${server.port}`)
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ export const WebCommand = effectCmd({
|
|||||||
if (!Flag.OPENCODE_SERVER_PASSWORD) {
|
if (!Flag.OPENCODE_SERVER_PASSWORD) {
|
||||||
UI.println(UI.Style.TEXT_WARNING_BOLD + "! OPENCODE_SERVER_PASSWORD is not set; server is unsecured.")
|
UI.println(UI.Style.TEXT_WARNING_BOLD + "! OPENCODE_SERVER_PASSWORD is not set; server is unsecured.")
|
||||||
}
|
}
|
||||||
const opts = yield* Effect.promise(() => resolveNetworkOptions(args))
|
const opts = yield* resolveNetworkOptions(args)
|
||||||
const server = yield* Effect.promise(() => Server.listen(opts))
|
const server = yield* Effect.promise(() => Server.listen(opts))
|
||||||
UI.empty()
|
UI.empty()
|
||||||
UI.println(UI.logo(" "))
|
UI.println(UI.logo(" "))
|
||||||
@@ -72,7 +72,7 @@ export const WebCommand = effectCmd({
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Open localhost in browser
|
// Open localhost in browser
|
||||||
open(localhostUrl.toString()).catch(() => {})
|
open(localhostUrl).catch(() => {})
|
||||||
} else {
|
} else {
|
||||||
const displayUrl = server.url.toString()
|
const displayUrl = server.url.toString()
|
||||||
UI.println(UI.Style.TEXT_INFO_BOLD + " Web interface: ", UI.Style.TEXT_NORMAL, displayUrl)
|
UI.println(UI.Style.TEXT_INFO_BOLD + " Web interface: ", UI.Style.TEXT_NORMAL, displayUrl)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import type { Argv, InferredOptionTypes } from "yargs"
|
import type { Argv, InferredOptionTypes } from "yargs"
|
||||||
import { Config } from "@/config/config"
|
import { Config } from "@/config/config"
|
||||||
import { AppRuntime } from "@/effect/app-runtime"
|
import { Effect } from "effect"
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
port: {
|
port: {
|
||||||
@@ -36,10 +36,10 @@ export type NetworkOptions = InferredOptionTypes<typeof options>
|
|||||||
export function withNetworkOptions<T>(yargs: Argv<T>) {
|
export function withNetworkOptions<T>(yargs: Argv<T>) {
|
||||||
return yargs.options(options)
|
return yargs.options(options)
|
||||||
}
|
}
|
||||||
export async function resolveNetworkOptions(args: NetworkOptions) {
|
export const resolveNetworkOptions = Effect.fn("Cli.resolveNetworkOptions")(function* (args: NetworkOptions) {
|
||||||
const config = await AppRuntime.runPromise(Config.Service.use((cfg) => cfg.getGlobal()))
|
const config = yield* Config.Service.use((cfg) => cfg.getGlobal())
|
||||||
return resolveNetworkOptionsNoConfig(args, config)
|
return resolveNetworkOptionsNoConfig(args, config)
|
||||||
}
|
})
|
||||||
|
|
||||||
export function resolveNetworkOptionsNoConfig(args: NetworkOptions, config?: Config.Info) {
|
export function resolveNetworkOptionsNoConfig(args: NetworkOptions, config?: Config.Info) {
|
||||||
const portExplicitlySet = process.argv.includes("--port")
|
const portExplicitlySet = process.argv.includes("--port")
|
||||||
|
|||||||
Reference in New Issue
Block a user