Skip to content

Commit 4cb77a2

Browse files
committed
cli list aggregators
1 parent d679566 commit 4cb77a2

3 files changed

Lines changed: 38 additions & 7 deletions

File tree

cli/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@ agg register-user # register and add aggregator to config
112112
agg register-user --set-active # also set it as the active aggregator
113113
```
114114

115+
#### `list`
116+
117+
List all registered aggregators.
118+
119+
```bash
120+
agg list
121+
```
122+
115123
#### `agg set-active <id>`
116124

117125
Set the active aggregator by its ID.

cli/src/cli.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ program
2121
await main({ setActive: opts.setActive });
2222
});
2323

24+
program
25+
.command("list")
26+
.description("List all available aggregators")
27+
.action(() => {
28+
console.log("List of available aggregators:");
29+
for (const agg of Object.keys(config.aggregators))
30+
console.log(`\t-> ${agg}`);
31+
});
32+
2433
program
2534
.command("set-active <id>")
2635
.description("Set the active aggregator")
@@ -113,7 +122,7 @@ program
113122
.command("reset")
114123
.description("Remove all aggregators and unset the active aggregator")
115124
.action(() => {
116-
updateConfig({ aggregators: {}, activeAggregator: null });
125+
updateConfig({ aggregators: {}, activeAggregator: null }, ["aggregators"]);
117126
console.log("✅ All aggregators removed and active aggregator unset.");
118127
});
119128

cli/src/config.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,38 @@ if (existsSync(CONFIG_PATH)) {
1111

1212
export const config: Config = deepMerge(defaults, userConfig) as Config;
1313

14-
function deepMerge(target: any, source: any): any {
14+
function deepMerge(target: any, source: any, replaceKeys: string[] = []) {
1515
const result = { ...target };
16+
1617
for (const key of Object.keys(source ?? {})) {
17-
if (source[key] && typeof source[key] === "object" && !Array.isArray(source[key])) {
18-
result[key] = deepMerge(target[key] ?? {}, source[key]);
19-
} else {
18+
if (replaceKeys.includes(key)) {
2019
result[key] = source[key];
20+
continue;
21+
}
22+
23+
const sourceVal = source[key];
24+
25+
if (
26+
sourceVal &&
27+
typeof sourceVal === "object" &&
28+
!Array.isArray(sourceVal)
29+
) {
30+
result[key] = deepMerge(target[key] ?? {}, sourceVal, replaceKeys);
31+
} else {
32+
result[key] = sourceVal;
2133
}
2234
}
35+
2336
return result;
2437
}
2538

26-
export function updateConfig(updates: any) {
39+
40+
export function updateConfig(updates: any, replaceKeys: string[] = []) {
2741
const current = existsSync(CONFIG_PATH)
2842
? JSON.parse(readFileSync(CONFIG_PATH, "utf-8"))
2943
: {};
3044

31-
const merged = deepMerge(current, updates);
45+
const merged = deepMerge(current, updates, replaceKeys);
3246

3347
writeFileSync(CONFIG_PATH, JSON.stringify(merged, null, 2));
3448
}

0 commit comments

Comments
 (0)