pi-profiles-manager 1.1.1 → 1.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/commands.test.ts +29 -13
- package/src/commands.ts +53 -57
package/package.json
CHANGED
package/src/commands.test.ts
CHANGED
|
@@ -70,16 +70,27 @@ describe("registerCommands", () => {
|
|
|
70
70
|
);
|
|
71
71
|
});
|
|
72
72
|
|
|
73
|
-
it("registers
|
|
73
|
+
it("registers slash-command aliases for every profile action", () => {
|
|
74
74
|
const pi = mockPi();
|
|
75
75
|
const mgr = new ProfileManager(pi, mockCtx());
|
|
76
76
|
mgr.setConfig(configWithProfiles([]));
|
|
77
77
|
|
|
78
78
|
registerCommands(pi, mgr, vi.fn() as any, vi.fn() as any);
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
79
|
+
|
|
80
|
+
for (const action of [
|
|
81
|
+
"list",
|
|
82
|
+
"status",
|
|
83
|
+
"sync",
|
|
84
|
+
"use",
|
|
85
|
+
"save",
|
|
86
|
+
"next",
|
|
87
|
+
"off",
|
|
88
|
+
]) {
|
|
89
|
+
expect(pi.registerCommand).toHaveBeenCalledWith(
|
|
90
|
+
`profiles:${action}`,
|
|
91
|
+
expect.any(Object),
|
|
92
|
+
);
|
|
93
|
+
}
|
|
83
94
|
});
|
|
84
95
|
|
|
85
96
|
it("completes actions first and profile names after use or save", () => {
|
|
@@ -267,23 +278,28 @@ describe("registerCommands", () => {
|
|
|
267
278
|
expect(openTui).not.toHaveBeenCalled();
|
|
268
279
|
});
|
|
269
280
|
|
|
270
|
-
it("profiles
|
|
281
|
+
it("profiles action aliases delegate through the existing action handling", async () => {
|
|
271
282
|
const pi = mockPi();
|
|
272
283
|
const ctx = mockCtx();
|
|
273
284
|
const mgr = new ProfileManager(pi, ctx);
|
|
285
|
+
const save = vi.fn(async () => {});
|
|
274
286
|
const sync = vi.fn(async () => {});
|
|
275
287
|
const openTui = vi.fn(async () => {});
|
|
276
|
-
mgr.setConfig(configWithProfiles([]));
|
|
288
|
+
mgr.setConfig(configWithProfiles(["alpha"]));
|
|
277
289
|
|
|
278
|
-
registerCommands(pi, mgr,
|
|
290
|
+
registerCommands(pi, mgr, save as any, vi.fn() as any, openTui, sync);
|
|
279
291
|
|
|
280
|
-
const
|
|
281
|
-
(
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
await
|
|
292
|
+
const handlerFor = (command: string) =>
|
|
293
|
+
(pi.registerCommand as any).mock.calls.find(
|
|
294
|
+
(c: any[]) => c[0] === command,
|
|
295
|
+
)[1].handler;
|
|
296
|
+
await handlerFor("profiles:save")("snapshot", ctx);
|
|
297
|
+
await handlerFor("profiles:sync")("", ctx);
|
|
298
|
+
await handlerFor("profiles:list")("", ctx);
|
|
285
299
|
|
|
300
|
+
expect(save).toHaveBeenCalledWith(ctx, "snapshot");
|
|
286
301
|
expect(sync).toHaveBeenCalledWith(ctx);
|
|
302
|
+
expect(ctx.ui.notify).toHaveBeenCalledWith("alpha");
|
|
287
303
|
expect(openTui).not.toHaveBeenCalled();
|
|
288
304
|
});
|
|
289
305
|
});
|
package/src/commands.ts
CHANGED
|
@@ -30,19 +30,52 @@ export function registerCommands(
|
|
|
30
30
|
openTui: OpenTuiFn = async () => {},
|
|
31
31
|
sync: SyncFn = async () => {},
|
|
32
32
|
) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
const handleAction = async (args: string, ctx: ExtensionCommandContext) => {
|
|
34
|
+
manager.setContext(ctx);
|
|
35
|
+
const { verb, name } = parseCommand(args);
|
|
36
|
+
|
|
37
|
+
try {
|
|
38
|
+
if (verb === "list") {
|
|
39
|
+
return ctx.ui.notify(manager.names().join("\n") || "No profiles");
|
|
40
|
+
}
|
|
41
|
+
if (verb === "status") {
|
|
42
|
+
const active = manager.state.get(ctx.sessionManager.getSessionId());
|
|
43
|
+
return ctx.ui.notify(active?.profile ?? "none");
|
|
44
|
+
}
|
|
45
|
+
if (verb === "sync") {
|
|
37
46
|
await sync(ctx);
|
|
38
|
-
|
|
39
|
-
ctx.ui.notify(
|
|
40
|
-
error instanceof Error ? error.message : String(error),
|
|
41
|
-
"error",
|
|
42
|
-
);
|
|
47
|
+
return;
|
|
43
48
|
}
|
|
44
|
-
|
|
45
|
-
|
|
49
|
+
if (verb === "use") {
|
|
50
|
+
if (!name) {
|
|
51
|
+
return ctx.ui.notify("Usage: /profiles use <name>", "error");
|
|
52
|
+
}
|
|
53
|
+
await manager.use(name);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (verb === "save") {
|
|
57
|
+
if (!name) {
|
|
58
|
+
return ctx.ui.notify("Usage: /profiles save <name>", "error");
|
|
59
|
+
}
|
|
60
|
+
await _save(ctx, name);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (verb === "next") {
|
|
64
|
+
await manager.next();
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (verb === "off") {
|
|
68
|
+
await manager.off();
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
return openTui(ctx as ContextLike);
|
|
72
|
+
} catch (error: unknown) {
|
|
73
|
+
ctx.ui.notify(
|
|
74
|
+
error instanceof Error ? error.message : String(error),
|
|
75
|
+
"error",
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
46
79
|
|
|
47
80
|
pi.registerCommand("profiles", {
|
|
48
81
|
description: "Manage SDD model profiles",
|
|
@@ -65,51 +98,14 @@ export function registerCommands(
|
|
|
65
98
|
.filter((name) => name.startsWith(namePrefix))
|
|
66
99
|
.map((value) => ({ value, label: value }));
|
|
67
100
|
},
|
|
68
|
-
|
|
69
|
-
manager.setContext(ctx);
|
|
70
|
-
const { verb, name } = parseCommand(args);
|
|
71
|
-
|
|
72
|
-
try {
|
|
73
|
-
if (verb === "list") {
|
|
74
|
-
return ctx.ui.notify(manager.names().join("\n") || "No profiles");
|
|
75
|
-
}
|
|
76
|
-
if (verb === "status") {
|
|
77
|
-
const active = manager.state.get(ctx.sessionManager.getSessionId());
|
|
78
|
-
return ctx.ui.notify(active?.profile ?? "none");
|
|
79
|
-
}
|
|
80
|
-
if (verb === "sync") {
|
|
81
|
-
await sync(ctx);
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
if (verb === "use") {
|
|
85
|
-
if (!name) {
|
|
86
|
-
return ctx.ui.notify("Usage: /profiles use <name>", "error");
|
|
87
|
-
}
|
|
88
|
-
await manager.use(name);
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
if (verb === "save") {
|
|
92
|
-
if (!name) {
|
|
93
|
-
return ctx.ui.notify("Usage: /profiles save <name>", "error");
|
|
94
|
-
}
|
|
95
|
-
await _save(ctx, name);
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
if (verb === "next") {
|
|
99
|
-
await manager.next();
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
if (verb === "off") {
|
|
103
|
-
await manager.off();
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
return openTui(ctx as ContextLike);
|
|
107
|
-
} catch (error: unknown) {
|
|
108
|
-
ctx.ui.notify(
|
|
109
|
-
error instanceof Error ? error.message : String(error),
|
|
110
|
-
"error",
|
|
111
|
-
);
|
|
112
|
-
}
|
|
113
|
-
},
|
|
101
|
+
handler: handleAction,
|
|
114
102
|
});
|
|
103
|
+
|
|
104
|
+
for (const action of COMMAND_ACTIONS) {
|
|
105
|
+
pi.registerCommand(`profiles:${action}`, {
|
|
106
|
+
description: `PiProfiles: ${action}`,
|
|
107
|
+
handler: (args: string, ctx: ExtensionCommandContext) =>
|
|
108
|
+
handleAction(`${action} ${args}`.trim(), ctx),
|
|
109
|
+
});
|
|
110
|
+
}
|
|
115
111
|
}
|