BREAKING CHANGE(core): Add multi-UPS support and group management; update CLI, configuration and documentation to support multiple UPS devices with group modes

This commit is contained in:
2025-03-28 16:19:43 +00:00
parent bd3042de25
commit 0e55f22dad
10 changed files with 2381 additions and 780 deletions

View File

@@ -5,6 +5,9 @@
export class Logger {
private currentBoxWidth: number | null = null;
private static instance: Logger;
/** Default width to use when no width is specified */
private readonly DEFAULT_WIDTH = 60;
/**
* Creates a new Logger instance
@@ -59,17 +62,17 @@ export class Logger {
/**
* Log a logbox title and set the current box width
* @param title Title of the logbox
* @param width Width of the logbox (including borders)
* @param width Width of the logbox (including borders), defaults to DEFAULT_WIDTH
*/
public logBoxTitle(title: string, width: number): void {
this.currentBoxWidth = width;
public logBoxTitle(title: string, width?: number): void {
this.currentBoxWidth = width || this.DEFAULT_WIDTH;
// Create the title line with appropriate padding
const paddedTitle = ` ${title} `;
const remainingSpace = width - 3 - paddedTitle.length;
const remainingSpace = this.currentBoxWidth - 3 - paddedTitle.length;
// Title line: ┌─ Title ───┐
const titleLine = `┌─${paddedTitle}${'─'.repeat(remainingSpace)}`;
const titleLine = `┌─${paddedTitle}${'─'.repeat(Math.max(0, remainingSpace))}`;
console.log(titleLine);
}
@@ -77,15 +80,16 @@ export class Logger {
/**
* Log a logbox line
* @param content Content of the line
* @param width Optional width override. If not provided, uses the current box width.
* @param width Optional width override. If not provided, uses the current box width or DEFAULT_WIDTH.
*/
public logBoxLine(content: string, width?: number): void {
const boxWidth = width || this.currentBoxWidth;
if (!boxWidth) {
throw new Error('No box width specified and no previous box width to use');
if (!this.currentBoxWidth && !width) {
// No current width and no width provided, use default width
this.logBoxTitle('', this.DEFAULT_WIDTH);
}
const boxWidth = width || this.currentBoxWidth || this.DEFAULT_WIDTH;
// Calculate the available space for content
const availableSpace = boxWidth - 2; // Account for left and right borders
@@ -101,27 +105,26 @@ export class Logger {
/**
* Log a logbox end
* @param width Optional width override. If not provided, uses the current box width.
* @param width Optional width override. If not provided, uses the current box width or DEFAULT_WIDTH.
*/
public logBoxEnd(width?: number): void {
const boxWidth = width || this.currentBoxWidth;
if (!boxWidth) {
throw new Error('No box width specified and no previous box width to use');
}
const boxWidth = width || this.currentBoxWidth || this.DEFAULT_WIDTH;
// Create the bottom border: └────────┘
console.log(`${'─'.repeat(boxWidth - 2)}`);
// Reset the current box width
this.currentBoxWidth = null;
}
/**
* Log a complete logbox with title, content lines, and ending
* @param title Title of the logbox
* @param lines Array of content lines
* @param width Width of the logbox
* @param width Width of the logbox, defaults to DEFAULT_WIDTH
*/
public logBox(title: string, lines: string[], width: number): void {
this.logBoxTitle(title, width);
public logBox(title: string, lines: string[], width?: number): void {
this.logBoxTitle(title, width || this.DEFAULT_WIDTH);
for (const line of lines) {
this.logBoxLine(line);
@@ -132,11 +135,11 @@ export class Logger {
/**
* Log a divider line
* @param width Width of the divider
* @param width Width of the divider, defaults to DEFAULT_WIDTH
* @param character Character to use for the divider (default: ─)
*/
public logDivider(width: number, character: string = '─'): void {
console.log(character.repeat(width));
public logDivider(width?: number, character: string = '─'): void {
console.log(character.repeat(width || this.DEFAULT_WIDTH));
}
}