Compare commits

...

2 Commits

4 changed files with 10 additions and 34 deletions

View File

@ -1,5 +1,12 @@
# Changelog
## 2025-03-28 - 3.0.1 - fix(cli)
Simplify UPS ID generation by removing the redundant promptForUniqueUpsId function in the CLI module and replacing it with the shortId helper.
- Deleted the unused promptForUniqueUpsId method from ts/cli.ts.
- Updated UPS configuration to generate a unique ID directly using helpers.shortId().
- Improved code clarity by removing unnecessary interactive prompts for UPS IDs.
## 2025-03-28 - 3.0.0 - BREAKING CHANGE(core)
Add multi-UPS support and group management; update CLI, configuration and documentation to support multiple UPS devices with group modes

View File

@ -1,6 +1,6 @@
{
"name": "@serve.zone/nupst",
"version": "3.0.0",
"version": "3.0.1",
"description": "Node.js UPS Shutdown Tool for SNMP-enabled UPS devices",
"main": "dist/index.js",
"bin": {

View File

@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@serve.zone/nupst',
version: '3.0.0',
version: '3.0.1',
description: 'Node.js UPS Shutdown Tool for SNMP-enabled UPS devices'
}

View File

@ -595,7 +595,7 @@ export class NupstCli {
}
// Get UPS ID and name
const upsId = await this.promptForUniqueUpsId(prompt, config.upsDevices);
const upsId = helpers.shortId();
const name = await prompt('UPS Name: ');
// Create a new UPS configuration object with defaults
@ -1651,37 +1651,6 @@ Options:
logger.error(`Failed to display configuration: ${error.message}`);
}
}
/**
* Generate a unique UPS ID
* @param prompt Function to prompt for user input
* @param existingUpsDevices Array of existing UPS devices
* @returns Unique UPS ID
*/
private async promptForUniqueUpsId(
prompt: (question: string) => Promise<string>,
existingUpsDevices: any[]
): Promise<string> {
const existingIds = existingUpsDevices.map(ups => ups.id);
// First ask for a custom ID
const customId = await prompt('UPS ID (leave empty for auto-generated): ');
if (customId.trim()) {
// Check if ID is already in use
if (existingIds.includes(customId.trim())) {
logger.error(`UPS ID "${customId.trim()}" is already in use.`);
// Recursively call this function to try again
return this.promptForUniqueUpsId(prompt, existingUpsDevices);
}
return customId.trim();
}
// Generate a unique ID with timestamp
const timestamp = new Date().getTime().toString(36);
const randomPart = Math.floor(Math.random() * 1000).toString(36);
return `ups-${timestamp}-${randomPart}`;
}
/**
* Generate a unique group ID