CLI: add config path subcommand to print active config file path

This commit is contained in:
陈运波0668001438
2026-02-25 15:16:04 +08:00
committed by Gustavo Madeira Santana
parent dc2290aeb1
commit d724019705
4 changed files with 47 additions and 0 deletions

View File

@@ -13,6 +13,7 @@ the configure wizard (same as `openclaw configure`).
## Examples
```bash
openclaw config path
openclaw config get browser.executablePath
openclaw config set browser.executablePath "/usr/bin/google-chrome"
openclaw config set agents.defaults.heartbeat.every "2h"
@@ -47,4 +48,8 @@ openclaw config set gateway.port 19001 --strict-json
openclaw config set channels.whatsapp.groups '["*"]' --strict-json
```
## Subcommands
- `config path`: Print the active config file path (resolved from `OPENCLAW_CONFIG_PATH` or default location).
Restart the gateway after edits.

View File

@@ -388,6 +388,7 @@ Subcommands:
- `config get <path>`: print a config value (dot/bracket path).
- `config set <path> <value>`: set a value (JSON5 or raw string).
- `config unset <path>`: remove a value.
- `config path`: print the active config file path.
### `doctor`

View File

@@ -288,4 +288,27 @@ describe("config cli", () => {
});
});
});
describe("config path", () => {
it("prints the active config file path", async () => {
const resolved: OpenClawConfig = { gateway: { port: 18789 } };
setSnapshot(resolved, resolved);
await runConfigCommand(["config", "path"]);
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", "path"]);
expect(mockLog).toHaveBeenCalledWith("/home/user/.openclaw/openclaw.json");
});
});
});

View File

@@ -324,6 +324,17 @@ export async function runConfigUnset(opts: { path: string; runtime?: RuntimeEnv
}
}
export async function runConfigPath(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")
@@ -390,4 +401,11 @@ export function registerConfigCli(program: Command) {
.action(async (path: string) => {
await runConfigUnset({ path });
});
cmd
.command("path")
.description("Print the active config file path")
.action(async () => {
await runConfigPath({});
});
}