Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
c8e5960abd | |||
7304a62357 | |||
a5a88e53ba | |||
73bc271c59 | |||
1e98181e71 | |||
eb5a8185ae | |||
ef3d3f3fa3 | |||
34e6e850ad |
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@serve.zone/nupst",
|
||||
"version": "4.3.2",
|
||||
"version": "5.0.1",
|
||||
"exports": "./mod.ts",
|
||||
"tasks": {
|
||||
"dev": "deno run --allow-all mod.ts",
|
||||
|
82
ts/cli.ts
82
ts/cli.ts
@@ -127,8 +127,7 @@ export class NupstCli {
|
||||
break;
|
||||
}
|
||||
case 'remove':
|
||||
case 'rm': // Alias
|
||||
case 'delete': { // Backward compatibility
|
||||
case 'rm': {
|
||||
const upsIdToRemove = subcommandArgs[0];
|
||||
if (!upsIdToRemove) {
|
||||
logger.error('UPS ID is required for remove command');
|
||||
@@ -172,8 +171,7 @@ export class NupstCli {
|
||||
break;
|
||||
}
|
||||
case 'remove':
|
||||
case 'rm': // Alias
|
||||
case 'delete': { // Backward compatibility
|
||||
case 'rm': {
|
||||
const groupIdToRemove = subcommandArgs[0];
|
||||
if (!groupIdToRemove) {
|
||||
logger.error('Group ID is required for remove command');
|
||||
@@ -206,8 +204,7 @@ export class NupstCli {
|
||||
break;
|
||||
}
|
||||
case 'remove':
|
||||
case 'rm': // Alias
|
||||
case 'delete': { // Backward compatibility
|
||||
case 'rm': {
|
||||
const upsId = subcommandArgs[0];
|
||||
const actionIndex = subcommandArgs[1];
|
||||
await actionHandler.remove(upsId, actionIndex);
|
||||
@@ -242,72 +239,8 @@ export class NupstCli {
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle top-level commands and backward compatibility
|
||||
// Handle top-level commands
|
||||
switch (command) {
|
||||
// Backward compatibility - old UPS commands
|
||||
case 'add':
|
||||
logger.log("Note: 'nupst add' is deprecated. Use 'nupst ups add' instead.");
|
||||
await upsHandler.add();
|
||||
break;
|
||||
case 'edit':
|
||||
logger.log("Note: 'nupst edit' is deprecated. Use 'nupst ups edit' instead.");
|
||||
await upsHandler.edit(commandArgs[0]);
|
||||
break;
|
||||
case 'delete':
|
||||
logger.log("Note: 'nupst delete' is deprecated. Use 'nupst ups remove' instead.");
|
||||
if (!commandArgs[0]) {
|
||||
logger.error('UPS ID is required for delete command');
|
||||
this.showHelp();
|
||||
return;
|
||||
}
|
||||
await upsHandler.remove(commandArgs[0]);
|
||||
break;
|
||||
case 'list':
|
||||
logger.log("Note: 'nupst list' is deprecated. Use 'nupst ups list' instead.");
|
||||
await upsHandler.list();
|
||||
break;
|
||||
case 'test':
|
||||
logger.log("Note: 'nupst test' is deprecated. Use 'nupst ups test' instead.");
|
||||
await upsHandler.test(debugMode);
|
||||
break;
|
||||
case 'setup':
|
||||
logger.log("Note: 'nupst setup' is deprecated. Use 'nupst ups edit' instead.");
|
||||
await upsHandler.edit(undefined);
|
||||
break;
|
||||
|
||||
// Backward compatibility - old service commands
|
||||
case 'enable':
|
||||
logger.log("Note: 'nupst enable' is deprecated. Use 'nupst service enable' instead.");
|
||||
await serviceHandler.enable();
|
||||
break;
|
||||
case 'disable':
|
||||
logger.log("Note: 'nupst disable' is deprecated. Use 'nupst service disable' instead.");
|
||||
await serviceHandler.disable();
|
||||
break;
|
||||
case 'start':
|
||||
logger.log("Note: 'nupst start' is deprecated. Use 'nupst service start' instead.");
|
||||
await serviceHandler.start();
|
||||
break;
|
||||
case 'stop':
|
||||
logger.log("Note: 'nupst stop' is deprecated. Use 'nupst service stop' instead.");
|
||||
await serviceHandler.stop();
|
||||
break;
|
||||
case 'status':
|
||||
logger.log("Note: 'nupst status' is deprecated. Use 'nupst service status' instead.");
|
||||
await serviceHandler.status();
|
||||
break;
|
||||
case 'logs':
|
||||
logger.log("Note: 'nupst logs' is deprecated. Use 'nupst service logs' instead.");
|
||||
await serviceHandler.logs();
|
||||
break;
|
||||
case 'daemon-start':
|
||||
logger.log(
|
||||
"Note: 'nupst daemon-start' is deprecated. Use 'nupst service start-daemon' instead.",
|
||||
);
|
||||
await serviceHandler.daemonStart(debugMode);
|
||||
break;
|
||||
|
||||
// Top-level commands (no changes)
|
||||
case 'update':
|
||||
await serviceHandler.update();
|
||||
break;
|
||||
@@ -589,11 +522,6 @@ export class NupstCli {
|
||||
logger.dim(' nupst group list # Show all configured groups');
|
||||
logger.dim(' nupst config # Display current configuration');
|
||||
console.log('');
|
||||
|
||||
// Note about deprecated commands
|
||||
logger.warn('Note: Old command format (e.g., \'nupst add\') still works but is deprecated.');
|
||||
logger.dim(' Use the new format (e.g., \'nupst ups add\') going forward.');
|
||||
console.log('');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -692,7 +620,7 @@ Usage:
|
||||
|
||||
Subcommands:
|
||||
add <ups-id|group-id> - Add a new action to a UPS or group interactively
|
||||
remove <ups-id|group-id> <index> - Remove an action by index (alias: rm, delete)
|
||||
remove <ups-id|group-id> <index> - Remove an action by index (alias: rm)
|
||||
list [ups-id|group-id] - List all actions (optionally for specific target) (alias: ls)
|
||||
|
||||
Options:
|
||||
|
@@ -277,6 +277,9 @@ WantedBy=multi-user.target
|
||||
for (const ups of config.upsDevices) {
|
||||
await this.displaySingleUpsStatus(ups, snmp);
|
||||
}
|
||||
|
||||
// Display groups after UPS devices
|
||||
this.displayGroupsStatus();
|
||||
} else if (config.snmp) {
|
||||
// Legacy single UPS configuration (v1/v2 format)
|
||||
logger.info('UPS Devices (1):');
|
||||
@@ -365,6 +368,27 @@ WantedBy=multi-user.target
|
||||
logger.log(` ${theme.dim(`Groups: ${groupNames.join(', ')}`)}`);
|
||||
}
|
||||
|
||||
// Display actions if any
|
||||
if (ups.actions && ups.actions.length > 0) {
|
||||
for (const action of ups.actions) {
|
||||
let actionDesc = `${action.type}`;
|
||||
if (action.thresholds) {
|
||||
actionDesc += ` (${action.triggerMode || 'onlyThresholds'}: battery<${action.thresholds.battery}%, runtime<${action.thresholds.runtime}min`;
|
||||
if (action.shutdownDelay) {
|
||||
actionDesc += `, delay=${action.shutdownDelay}s`;
|
||||
}
|
||||
actionDesc += ')';
|
||||
} else {
|
||||
actionDesc += ` (${action.triggerMode || 'onlyPowerChanges'}`;
|
||||
if (action.shutdownDelay) {
|
||||
actionDesc += `, delay=${action.shutdownDelay}s`;
|
||||
}
|
||||
actionDesc += ')';
|
||||
}
|
||||
logger.log(` ${theme.dim('Action:')} ${theme.info(actionDesc)}`);
|
||||
}
|
||||
}
|
||||
|
||||
logger.log('');
|
||||
|
||||
} catch (error) {
|
||||
@@ -376,6 +400,69 @@ WantedBy=multi-user.target
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display status of all groups
|
||||
* @private
|
||||
*/
|
||||
private displayGroupsStatus(): void {
|
||||
const config = this.daemon.getConfig();
|
||||
|
||||
if (!config.groups || config.groups.length === 0) {
|
||||
return; // No groups to display
|
||||
}
|
||||
|
||||
logger.log('');
|
||||
logger.info(`Groups (${config.groups.length}):`);
|
||||
|
||||
for (const group of config.groups) {
|
||||
// Display group name and mode
|
||||
const modeColor = group.mode === 'redundant' ? theme.success : theme.warning;
|
||||
logger.log(
|
||||
` ${symbols.info} ${theme.highlight(group.name)} ${theme.dim(`(${modeColor(group.mode)})`)}`,
|
||||
);
|
||||
|
||||
// Display description if present
|
||||
if (group.description) {
|
||||
logger.log(` ${theme.dim(group.description)}`);
|
||||
}
|
||||
|
||||
// Display UPS devices in this group
|
||||
const upsInGroup = config.upsDevices.filter((ups) =>
|
||||
ups.groups && ups.groups.includes(group.id)
|
||||
);
|
||||
|
||||
if (upsInGroup.length > 0) {
|
||||
const upsNames = upsInGroup.map((ups) => ups.name).join(', ');
|
||||
logger.log(` ${theme.dim(`UPS Devices (${upsInGroup.length}):`)} ${upsNames}`);
|
||||
} else {
|
||||
logger.log(` ${theme.dim('UPS Devices: None')}`);
|
||||
}
|
||||
|
||||
// Display actions if any
|
||||
if (group.actions && group.actions.length > 0) {
|
||||
for (const action of group.actions) {
|
||||
let actionDesc = `${action.type}`;
|
||||
if (action.thresholds) {
|
||||
actionDesc += ` (${action.triggerMode || 'onlyThresholds'}: battery<${action.thresholds.battery}%, runtime<${action.thresholds.runtime}min`;
|
||||
if (action.shutdownDelay) {
|
||||
actionDesc += `, delay=${action.shutdownDelay}s`;
|
||||
}
|
||||
actionDesc += ')';
|
||||
} else {
|
||||
actionDesc += ` (${action.triggerMode || 'onlyPowerChanges'}`;
|
||||
if (action.shutdownDelay) {
|
||||
actionDesc += `, delay=${action.shutdownDelay}s`;
|
||||
}
|
||||
actionDesc += ')';
|
||||
}
|
||||
logger.log(` ${theme.dim('Action:')} ${theme.info(actionDesc)}`);
|
||||
}
|
||||
}
|
||||
|
||||
logger.log('');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable and uninstall the systemd service
|
||||
* @throws Error if disabling fails
|
||||
|
Reference in New Issue
Block a user