mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-04 23:50:20 +00:00
CLI: add config path subcommand to print active config file path
This commit is contained in:
committed by
Gustavo Madeira Santana
parent
dc2290aeb1
commit
d724019705
@@ -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.
|
||||
|
||||
@@ -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`
|
||||
|
||||
|
||||
@@ -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");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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({});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user