Skip to content

Commit c67103e

Browse files
ruibabyCopilot
andcommitted
Prompt to enable plugin after installation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 90d54f5 commit c67103e

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

src/commands/plugin/index.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
type Plugin,
44
type PluginV1alpha1ConsoleApiListPluginsRequest,
55
} from "@halo-dev/api-client";
6-
import { checkbox } from "@inquirer/prompts";
6+
import { checkbox, confirm } from "@inquirer/prompts";
77
import cac, { type CAC } from "cac";
88
import ora, { type Ora } from "ora";
99

@@ -754,6 +754,30 @@ function buildPluginCli(runtime: RuntimeContext): CAC {
754754

755755
if (options.json) {
756756
printJson(response.data);
757+
return;
758+
}
759+
760+
const pluginName = response.data.metadata.name;
761+
if (!response.data.spec.enabled) {
762+
let shouldEnable = options.yes ?? false;
763+
if (!shouldEnable && process.stdin.isTTY && process.stdout.isTTY) {
764+
shouldEnable = await confirm({
765+
message: `Enable plugin ${pluginName} now?`,
766+
default: true,
767+
});
768+
}
769+
770+
if (shouldEnable) {
771+
await clients.console.plugin.plugin.changePluginRunningState({
772+
name: pluginName,
773+
pluginRunningStateRequest: { enable: true },
774+
});
775+
process.stdout.write(`Enabled plugin ${pluginName}.\n`);
776+
} else {
777+
process.stdout.write(
778+
`Plugin ${pluginName} installed but not enabled. Run \`halo plugin enable ${pluginName}\` to enable it.\n`,
779+
);
780+
}
757781
}
758782
});
759783

0 commit comments

Comments
 (0)