@aopslabs/aops 0.2.1 → 0.3.1

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.
@@ -1,109 +0,0 @@
1
- import { Command } from 'commander';
2
- import { logInfo } from '@aopslabs/xf-cli-ui';
3
- import { promptSelect } from '../utils/prompts.js';
4
- import { runCommercialLicenseStatus } from './commercial-license.js';
5
- import { runCommunityDoctor } from './community-doctor.js';
6
- import { runCommunityCockpit, runCommunityCockpitHealth, runCommunityCockpitLogs, runCommunityCockpitRestart, runCommunityCockpitStart, runCommunityCockpitStatus, runCommunityCockpitStop, } from './community-cockpit.js';
7
- import { runCommunityServerHealth, runCommunityServerLogs, runCommunityServerRestart, runCommunityServerStart, runCommunityServerStatus, runCommunityServerStop, } from './community-server.js';
8
- export const COMMUNITY_CONSOLE_CHOICES = Object.freeze([
9
- { name: 'Open Cockpit — starts stopped services if needed', value: 'cockpit' },
10
- { name: 'Show both service statuses', value: 'status' },
11
- { name: 'Start AOPS Server — 5900', value: 'server-start' },
12
- { name: 'Start AOPS Server in this terminal — live logs, Ctrl+C to stop', value: 'server-start-foreground' },
13
- { name: 'Stop AOPS Server — 5900', value: 'server-stop' },
14
- { name: 'Restart AOPS Server — 5900', value: 'server-restart' },
15
- { name: 'Check AOPS Server health', value: 'server-health' },
16
- { name: 'Show AOPS Server logs', value: 'server-logs' },
17
- { name: 'Start Cockpit — 5922', value: 'cockpit-start' },
18
- { name: 'Stop Cockpit — 5922', value: 'cockpit-stop' },
19
- { name: 'Restart Cockpit — 5922', value: 'cockpit-restart' },
20
- { name: 'Check Cockpit health', value: 'cockpit-health' },
21
- { name: 'Show Cockpit logs', value: 'cockpit-logs' },
22
- { name: 'Show commercial license and domain-admission status', value: 'license-status' },
23
- { name: 'Run Doctor (read-only)', value: 'doctor' },
24
- { name: 'Back', value: 'back' },
25
- ]);
26
- export async function runCommunityConsoleAction(action, options, dependencies = {}) {
27
- if (action === 'cockpit')
28
- return (dependencies.runCockpit ?? runCommunityCockpit)(options);
29
- if (action === 'status') {
30
- await (dependencies.runServerStatus ?? runCommunityServerStatus)(options);
31
- await (dependencies.runCockpitStatus ?? runCommunityCockpitStatus)(options);
32
- return;
33
- }
34
- if (action === 'server-health')
35
- return (dependencies.runServerHealth ?? runCommunityServerHealth)(options);
36
- if (action === 'server-start')
37
- return (dependencies.runServerStart ?? runCommunityServerStart)(options);
38
- if (action === 'server-start-foreground')
39
- return (dependencies.runServerStart ?? runCommunityServerStart)({
40
- ...options,
41
- foreground: true,
42
- });
43
- if (action === 'server-restart')
44
- return (dependencies.runServerRestart ?? runCommunityServerRestart)(options);
45
- if (action === 'server-stop')
46
- return (dependencies.runServerStop ?? runCommunityServerStop)(options);
47
- if (action === 'server-logs')
48
- return (dependencies.runServerLogs ?? runCommunityServerLogs)(options);
49
- if (action === 'cockpit-health')
50
- return (dependencies.runCockpitHealth ?? runCommunityCockpitHealth)(options);
51
- if (action === 'cockpit-start')
52
- return (dependencies.runCockpitStart ?? runCommunityCockpitStart)(options);
53
- if (action === 'cockpit-restart')
54
- return (dependencies.runCockpitRestart ?? runCommunityCockpitRestart)(options);
55
- if (action === 'cockpit-stop')
56
- return (dependencies.runCockpitStop ?? runCommunityCockpitStop)(options);
57
- if (action === 'cockpit-logs')
58
- return (dependencies.runCockpitLogs ?? runCommunityCockpitLogs)(options);
59
- if (action === 'license-status') {
60
- return (dependencies.runLicenseStatus ?? runCommercialLicenseStatus)({ json: options.json });
61
- }
62
- return (dependencies.runDoctor ?? runCommunityDoctor)(options);
63
- }
64
- export async function runCommunityConsole(options = {}, dependencies = {}) {
65
- const interactive = dependencies.isInteractive?.() ??
66
- (process.stdin.isTTY === true && process.stdout.isTTY === true);
67
- if (!interactive || options.json === true) {
68
- console.log(JSON.stringify({
69
- status: 'needs-input',
70
- mutationPerformed: false,
71
- reason: 'community_console_tty_required',
72
- next: [
73
- 'aops server status --json',
74
- 'aops server start --json',
75
- 'aops server stop --json',
76
- 'aops cockpit status --json',
77
- 'aops cockpit start --json',
78
- 'aops cockpit stop --json',
79
- 'aops license status --json',
80
- ],
81
- }, null, 2));
82
- process.exitCode = 2;
83
- return;
84
- }
85
- const select = dependencies.select ?? promptSelect;
86
- const info = dependencies.info ?? logInfo;
87
- info('AOPS Server and Cockpit use separate processes and ports: 5900 and 5922.');
88
- await (dependencies.runServerStatus ?? runCommunityServerStatus)(options);
89
- await (dependencies.runCockpitStatus ?? runCommunityCockpitStatus)(options);
90
- while (true) {
91
- const action = await select({
92
- message: 'Server and Cockpit:',
93
- type: process.env.AOPS_CLI_MENU_STYLE?.toLowerCase() === 'rawlist' ? 'rawlist' : 'select',
94
- pageSize: COMMUNITY_CONSOLE_CHOICES.length,
95
- choices: [...COMMUNITY_CONSOLE_CHOICES],
96
- });
97
- if (action === 'back')
98
- return;
99
- await runCommunityConsoleAction(action, options, dependencies);
100
- }
101
- }
102
- export function makeCommunityConsoleCommand() {
103
- return new Command('console')
104
- .description('Guided server and Cockpit controls; non-TTY returns needs-input without mutation')
105
- .option('--instance <name>', 'Installation instance name', 'default')
106
- .option('--data-root <path>', 'Absolute Community data root override')
107
- .option('--json', 'Return the non-interactive needs-input contract')
108
- .action((options) => runCommunityConsole(options));
109
- }
@@ -1,70 +0,0 @@
1
- import inquirer from 'inquirer';
2
- const DONE_PREFIX = '\u2714 ';
3
- const PROMPT_THEME = { prefix: { idle: '?', done: DONE_PREFIX } };
4
- const normalizePromptMessage = (message) => message.trimStart();
5
- export async function promptInput(opts) {
6
- const { value } = await inquirer.prompt([
7
- {
8
- type: 'input',
9
- name: 'value',
10
- message: normalizePromptMessage(opts.message),
11
- default: opts.default,
12
- validate: opts.validate,
13
- theme: PROMPT_THEME,
14
- },
15
- ]);
16
- return String(value ?? '');
17
- }
18
- export async function promptPassword(opts) {
19
- const { value } = await inquirer.prompt([
20
- {
21
- type: 'password',
22
- name: 'value',
23
- message: normalizePromptMessage(opts.message),
24
- default: opts.default,
25
- mask: '*',
26
- validate: opts.validate,
27
- theme: PROMPT_THEME,
28
- },
29
- ]);
30
- return String(value ?? '');
31
- }
32
- export async function promptConfirm(opts) {
33
- const { confirm } = await inquirer.prompt([
34
- {
35
- type: 'confirm',
36
- name: 'confirm',
37
- message: normalizePromptMessage(opts.message),
38
- default: opts.default ?? true,
39
- theme: PROMPT_THEME,
40
- },
41
- ]);
42
- return Boolean(confirm);
43
- }
44
- export async function promptSelect(opts) {
45
- const resolvedType = opts.type === 'list' || !opts.type ? 'select' : opts.type;
46
- const { value } = await inquirer.prompt([
47
- {
48
- type: resolvedType,
49
- name: 'value',
50
- message: normalizePromptMessage(opts.message),
51
- choices: opts.choices,
52
- default: opts.default,
53
- pageSize: opts.pageSize,
54
- theme: PROMPT_THEME,
55
- },
56
- ]);
57
- return String(value);
58
- }
59
- export async function promptMultiSelect(opts) {
60
- const { values } = await inquirer.prompt([
61
- {
62
- type: 'checkbox',
63
- name: 'values',
64
- message: normalizePromptMessage(opts.message),
65
- choices: opts.choices,
66
- theme: PROMPT_THEME,
67
- },
68
- ]);
69
- return Array.isArray(values) ? values.map((v) => String(v)) : [];
70
- }