The CLI's profile flag stands before the command, so deploy's --config reaches deploy
Misha Kaletsky, 2026-11-25 20:24 UTC · 126eb7a3c6263e4d4a955e576f608fb09eb14bf5 · parent 33638e3
3 files changed
M core/lib/src/cli/README.md
@@ -636,6 +636,9 @@ profile, then `default`. `iterate login <address>` points the selected profile at the mind. `--mind <address>` names another mind for one command, with that mind's own sign-in. +`--config <profile>` stands before the command. After the command the flag is the command's own: +`iterate deploy --config <address>` names the repo that a new mind's config starts as. + ```sh iterate login example.com # the profile `default` iterate config set --name lab # a second profile
M core/lib/src/cli/cli.test.ts
@@ -3,7 +3,19 @@ import { fileURLToPath } from "node:url"; import { expect, test } from "vitest"; import { z } from "zod"; -import { packageVersionOf } from "./cli.ts"; +import { packageVersionOf, profileFlagIn } from "./cli.ts"; + +test("--config before the command picks a profile; after the command it is the command's own flag", () => { + expect(profileFlagIn(["--config", "lab", "whoami"])).toEqual({ + profile: "lab", + rest: ["whoami"], + }); + + const birth = ["deploy", "--config", "https://git.mindlew.com/repos/config-template"]; + expect(profileFlagIn(birth)).toEqual({ profile: undefined, rest: birth }); + + expect(() => profileFlagIn(["--config"])).toThrow("--config requires a value"); +}); test("iterate --version and -v print the package version and exit 0", () => { const pkg = z
M core/lib/src/cli/cli.ts
@@ -1,8 +1,8 @@ // cli.ts — THE `iterate` CLI: sign in to a mind by its address, run scripts in it, and lend it // what runs on this machine (a file's functions, a local port, this computer). A profile -// (./config.ts) names one mind; `--config <name>`, a folder mapped to a profile, the default -// profile, or the only one picks it, and `--mind <address>` overrides it for one command. Every -// connection is the Node client's (../node.ts `connectMind`). +// (./config.ts) names one mind; `--config <name>` before the command, a folder mapped to a +// profile, the default profile, or the only one picks it, and `--mind <address>` overrides it for +// one command. Every connection is the Node client's (../node.ts `connectMind`). import { spawnSync } from "node:child_process"; import { existsSync, readFileSync, rmSync } from "node:fs"; import { readFile } from "node:fs/promises"; @@ -54,16 +54,18 @@ const isAgent = isCodingAgent(process.env); let configFlagOverride: string | undefined; -const consumeCliStringFlag = (flagName: string): string | undefined => { - const args = process.argv.slice(2); - const flagIndex = args.indexOf(flagName); - if (flagIndex === -1) return undefined; - const value = args[flagIndex + 1]; - if (!value || value.startsWith("-")) throw new Error(`${flagName} requires a value`); - process.argv.splice(flagIndex + 2, 2); - return value; -}; +/** THE CLI'S OWN FLAG `--config <profile>` STANDS BEFORE THE COMMAND: `iterate --config lab + * whoami`. A `--config` after the command is that command's own flag and is left where it is: + * `iterate deploy --config <address>` names the repo that a new mind's config starts as. Answers + * the profile, and the arguments without the flag. */ +export function profileFlagIn(args: string[]) { + if (args[0] !== "--config") return { profile: undefined, rest: args }; + const profile = args[1]; + if (!profile || profile.startsWith("-")) throw new Error("--config requires a value"); + return { profile, rest: args.slice(2) }; +} + /** * Which profile to use. Priority: --config flag > workspace match (walk up from cwd) > default > * the only profile > `default`. @@ -904,7 +906,9 @@ process.exitCode = await runFs(process.argv.slice(3), process); return; } - configFlagOverride = consumeCliStringFlag("--config"); + const { profile, rest } = profileFlagIn(process.argv.slice(2)); + configFlagOverride = profile; + process.argv.splice(2, process.argv.length, ...rest); if (process.argv.length === 2) process.argv.push("--help"); if (process.argv.length === 3 && process.argv[2] === "-v") process.argv[2] = "--version"; const cli = createCli({