CLI: add config path subcommand to print active config file path (#26256)
Merged via squash. Prepared head SHA: b11c593a34c5730f4244c054e1d1ab536953b0ef Co-authored-by: cyb1278588254 <48212932+cyb1278588254@users.noreply.github.com> Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com> Reviewed-by: @gumadeiras
This commit is contained in:
@@ -288,4 +288,27 @@ describe("config cli", () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("config file", () => {
|
||||
it("prints the active config file path", async () => {
|
||||
const resolved: OpenClawConfig = { gateway: { port: 18789 } };
|
||||
setSnapshot(resolved, resolved);
|
||||
|
||||
await runConfigCommand(["config", "file"]);
|
||||
|
||||
expect(mockLog).toHaveBeenCalledWith("/tmp/openclaw.json");
|
||||
expect(mockWriteConfigFile).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("handles config file path with home directory", async () => {
|
||||
const resolved: OpenClawConfig = { gateway: { port: 18789 } };
|
||||
const snapshot = buildSnapshot({ resolved, config: resolved });
|
||||
snapshot.path = "/home/user/.openclaw/openclaw.json";
|
||||
mockReadConfigFileSnapshot.mockResolvedValueOnce(snapshot);
|
||||
|
||||
await runConfigCommand(["config", "file"]);
|
||||
|
||||
expect(mockLog).toHaveBeenCalledWith("/home/user/.openclaw/openclaw.json");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -324,11 +324,22 @@ export async function runConfigUnset(opts: { path: string; runtime?: RuntimeEnv
|
||||
}
|
||||
}
|
||||
|
||||
export async function runConfigFile(opts: { runtime?: RuntimeEnv }) {
|
||||
const runtime = opts.runtime ?? defaultRuntime;
|
||||
try {
|
||||
const snapshot = await readConfigFileSnapshot();
|
||||
runtime.log(shortenHomePath(snapshot.path));
|
||||
} catch (err) {
|
||||
runtime.error(danger(String(err)));
|
||||
runtime.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
export function registerConfigCli(program: Command) {
|
||||
const cmd = program
|
||||
.command("config")
|
||||
.description(
|
||||
"Non-interactive config helpers (get/set/unset). Run without subcommand for the setup wizard.",
|
||||
"Non-interactive config helpers (get/set/unset/file). Run without subcommand for the setup wizard.",
|
||||
)
|
||||
.addHelpText(
|
||||
"after",
|
||||
@@ -390,4 +401,11 @@ export function registerConfigCli(program: Command) {
|
||||
.action(async (path: string) => {
|
||||
await runConfigUnset({ path });
|
||||
});
|
||||
|
||||
cmd
|
||||
.command("file")
|
||||
.description("Print the active config file path")
|
||||
.action(async () => {
|
||||
await runConfigFile({});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ const coreEntries: CoreCliEntry[] = [
|
||||
{
|
||||
name: "config",
|
||||
description:
|
||||
"Non-interactive config helpers (get/set/unset). Default: starts setup wizard.",
|
||||
"Non-interactive config helpers (get/set/unset/file). Default: starts setup wizard.",
|
||||
hasSubcommands: true,
|
||||
},
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user