fix(cli): honor json output for config get

Ensure `rig config get <key> --json` emits the documented value/source/default payload even when Commander records the option on the parent `config` command.

Verification:
- npm --workspace packages/cli test -- config.test.ts -t "rig config get <key> --json"
- npm --workspace packages/cli run build

Full `config.test.ts` still has the pre-existing driver-declared failure in `DaemonClient config integration > ConfigStore resolves non-default host/port from config file`.
This commit is contained in:
mvschwarz committed 2026-05-11 19:55:46 -07:00
1 parent b252137a2e
commit 8f521d071f
2 files changed
+23 -1

No files matched your search

+1 -1
View File
@@ -84,7 +84,7 @@ Precedence: CLI flag > environment variable > config file > default`)
.description("Read a single config value")
.action((key: string, opts: { json?: boolean; showSource?: boolean }) => {
try {
if (opts.json) {
if (opts.json || cmd.opts<{ json?: boolean }>().json) {
console.log(JSON.stringify(store.resolveWithSource(key), null, 2));
return;
}
+22
View File
@@ -266,6 +266,28 @@ describe("Config CLI", () => {
expect(logs.join("\n")).toContain("transcripts");
});
it("rig config get <key> --json prints value with source metadata", async () => {
const savedHost = process.env["OPENRIG_HOST"];
delete process.env["OPENRIG_HOST"];
const cmd = configCommand(join(tmpDir, "config.json"));
const prog = new Command();
prog.exitOverride();
prog.addCommand(cmd);
try {
const { logs } = await captureLogs(async () => {
await prog.parseAsync(["node", "rig", "config", "get", "daemon.host", "--json"]);
});
const parsed = JSON.parse(logs.join("\n"));
expect(parsed.value).toBe("127.0.0.1");
expect(parsed.source).toBe("default");
expect(parsed.defaultValue).toBe("127.0.0.1");
} finally {
if (savedHost === undefined) delete process.env["OPENRIG_HOST"];
else process.env["OPENRIG_HOST"] = savedHost;
}
});
// Test 10
it("rig config --help includes subcommands and examples", () => {
const cmd = configCommand(join(tmpDir, "config.json"));