Skip to content

Commit c4311dd

Browse files
authored
feat(cli): allow effectCmd instance to be a function of args (#25517)
1 parent ad05a46 commit c4311dd

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

packages/opencode/src/cli/effect-cmd.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,14 @@ interface EffectCmdOpts<Args, A> {
3737
* directly under AppRuntime — it can yield any `AppServices` but must not
3838
* yield `InstanceRef` (it'd be undefined, causing a defect).
3939
*
40+
* Function form: `(args) => boolean` decides per-invocation. Useful for
41+
* commands like `run --attach <url>` where one flag flips between local
42+
* (needs instance) and remote (doesn't).
43+
*
4044
* Use `false` for commands that don't read project state (e.g. `models`,
4145
* `serve`, `web`, `account`, `db`, `upgrade`).
4246
*/
43-
instance?: boolean
47+
instance?: boolean | ((args: Args) => boolean)
4448
/** Defaults to process.cwd(). Override for commands that take a directory positional. */
4549
directory?: (args: Args) => string
4650
handler: (args: Args) => Effect.Effect<A, CliError, AppServices | InstanceStore.Service>
@@ -72,7 +76,8 @@ export const effectCmd = <Args, A>(opts: EffectCmdOpts<Args, A>) =>
7276
async handler(rawArgs) {
7377
// yargs typing wraps Args in ArgumentsCamelCase<WithDoubleDash<...>>; cast at the boundary.
7478
const args = rawArgs as unknown as Args
75-
if (opts.instance === false) {
79+
const useInstance = typeof opts.instance === "function" ? opts.instance(args) : opts.instance !== false
80+
if (!useInstance) {
7681
await AppRuntime.runPromise(opts.handler(args))
7782
return
7883
}

0 commit comments

Comments
 (0)