diff --git a/changelog.md b/changelog.md index 09a7910..a8e33a3 100644 --- a/changelog.md +++ b/changelog.md @@ -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 diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index 0bcd63b..b973ba8 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -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' } diff --git a/ts/cli.ts b/ts/cli.ts index b960b7a..7ebc572 100644 --- a/ts/cli.ts +++ b/ts/cli.ts @@ -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, - existingUpsDevices: any[] - ): Promise { - 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