mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-03-31 14:22:27 +00:00
feat(core): optional mdns service (#6192)
Co-authored-by: Github Action <action@github.com>
This commit is contained in:
42
packages/opencode/src/cli/network.ts
Normal file
42
packages/opencode/src/cli/network.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import type { Argv, InferredOptionTypes } from "yargs"
|
||||
import type { Config } from "../config/config"
|
||||
|
||||
const options = {
|
||||
port: {
|
||||
type: "number" as const,
|
||||
describe: "port to listen on",
|
||||
default: 0,
|
||||
},
|
||||
hostname: {
|
||||
type: "string" as const,
|
||||
describe: "hostname to listen on",
|
||||
default: "127.0.0.1",
|
||||
},
|
||||
mdns: {
|
||||
type: "boolean" as const,
|
||||
describe: "enable mDNS service discovery (defaults hostname to 0.0.0.0)",
|
||||
default: false,
|
||||
},
|
||||
}
|
||||
|
||||
export type NetworkOptions = InferredOptionTypes<typeof options>
|
||||
|
||||
export function withNetworkOptions<T>(yargs: Argv<T>) {
|
||||
return yargs.options(options)
|
||||
}
|
||||
|
||||
export function resolveNetworkOptions(args: NetworkOptions, config?: Config.Info) {
|
||||
const portExplicitlySet = process.argv.includes("--port")
|
||||
const hostnameExplicitlySet = process.argv.includes("--hostname")
|
||||
const mdnsExplicitlySet = process.argv.includes("--mdns")
|
||||
|
||||
const mdns = mdnsExplicitlySet ? args.mdns : (config?.server?.mdns ?? args.mdns)
|
||||
const port = portExplicitlySet ? args.port : (config?.server?.port ?? args.port)
|
||||
const hostname = hostnameExplicitlySet
|
||||
? args.hostname
|
||||
: mdns && !config?.server?.hostname
|
||||
? "0.0.0.0"
|
||||
: (config?.server?.hostname ?? args.hostname)
|
||||
|
||||
return { hostname, port, mdns }
|
||||
}
|
||||
Reference in New Issue
Block a user