fix(cli): Improve console output formatting for status banners and logging messages
This commit is contained in:
parent
d01e878310
commit
1123a99aea
@ -1,5 +1,12 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 2025-03-26 - 2.6.9 - fix(cli)
|
||||||
|
Improve console output formatting for status banners and logging messages
|
||||||
|
|
||||||
|
- Standardize banner messages in daemon status updates
|
||||||
|
- Refine version information banner in nupst logging
|
||||||
|
- Update UPS connection and status banners in systemd
|
||||||
|
|
||||||
## 2025-03-26 - 2.6.8 - fix(cli)
|
## 2025-03-26 - 2.6.8 - fix(cli)
|
||||||
Improve CLI formatting, refine debug option filtering, and remove unused dgram import in SNMP manager
|
Improve CLI formatting, refine debug option filtering, and remove unused dgram import in SNMP manager
|
||||||
|
|
||||||
|
@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@serve.zone/nupst',
|
name: '@serve.zone/nupst',
|
||||||
version: '2.6.8',
|
version: '2.6.9',
|
||||||
description: 'Node.js UPS Shutdown Tool for SNMP-enabled UPS devices'
|
description: 'Node.js UPS Shutdown Tool for SNMP-enabled UPS devices'
|
||||||
}
|
}
|
||||||
|
12
ts/daemon.ts
12
ts/daemon.ts
@ -226,8 +226,8 @@ export class NupstDaemon {
|
|||||||
|
|
||||||
// Log status changes
|
// Log status changes
|
||||||
if (status.powerStatus !== lastStatus) {
|
if (status.powerStatus !== lastStatus) {
|
||||||
console.log('┌──────────────────────────────────────────┐');
|
console.log('┌─ Power Status Change ─────────────────────┐');
|
||||||
console.log(`│ Power status changed: ${lastStatus} → ${status.powerStatus}`);
|
console.log(`│ Status changed: ${lastStatus} → ${status.powerStatus}`);
|
||||||
console.log('└──────────────────────────────────────────┘');
|
console.log('└──────────────────────────────────────────┘');
|
||||||
lastStatus = status.powerStatus;
|
lastStatus = status.powerStatus;
|
||||||
lastLogTime = currentTime; // Reset log timer when status changes
|
lastLogTime = currentTime; // Reset log timer when status changes
|
||||||
@ -235,8 +235,8 @@ export class NupstDaemon {
|
|||||||
// Log status periodically (at least every 5 minutes)
|
// Log status periodically (at least every 5 minutes)
|
||||||
else if (shouldLogStatus) {
|
else if (shouldLogStatus) {
|
||||||
const timestamp = new Date().toISOString();
|
const timestamp = new Date().toISOString();
|
||||||
console.log('┌──────────────────────────────────────────┐');
|
console.log('┌─ Periodic Status Update ──────────────────┐');
|
||||||
console.log(`│ [${timestamp}] Periodic Status Update`);
|
console.log(`│ Timestamp: ${timestamp}`);
|
||||||
console.log(`│ Power Status: ${status.powerStatus}`);
|
console.log(`│ Power Status: ${status.powerStatus}`);
|
||||||
console.log(`│ Battery: ${status.batteryCapacity}% | Runtime: ${status.batteryRuntime} min`);
|
console.log(`│ Battery: ${status.batteryCapacity}% | Runtime: ${status.batteryRuntime} min`);
|
||||||
console.log('└──────────────────────────────────────────┘');
|
console.log('└──────────────────────────────────────────┘');
|
||||||
@ -267,8 +267,8 @@ export class NupstDaemon {
|
|||||||
batteryCapacity: number,
|
batteryCapacity: number,
|
||||||
batteryRuntime: number
|
batteryRuntime: number
|
||||||
}): Promise<void> {
|
}): Promise<void> {
|
||||||
console.log('┌─ UPS Status ───────────────────────────────┐');
|
console.log('┌─ UPS Status ────────────────────────────┐');
|
||||||
console.log(`│ Battery: ${status.batteryCapacity}% | Runtime: ${status.batteryRuntime} min │`);
|
console.log(`│ Battery: ${status.batteryCapacity}% | Runtime: ${status.batteryRuntime} min`);
|
||||||
console.log('└──────────────────────────────────────────┘');
|
console.log('└──────────────────────────────────────────┘');
|
||||||
|
|
||||||
// Check battery threshold
|
// Check battery threshold
|
||||||
|
@ -162,7 +162,7 @@ export class Nupst {
|
|||||||
*/
|
*/
|
||||||
public logVersionInfo(checkForUpdates: boolean = true): void {
|
public logVersionInfo(checkForUpdates: boolean = true): void {
|
||||||
const version = this.getVersion();
|
const version = this.getVersion();
|
||||||
console.log('┌─ NUPST Version ────────────────────────┐');
|
console.log('┌─ NUPST Version ────────────────────────────┐');
|
||||||
console.log(`│ Current Version: ${version}`);
|
console.log(`│ Current Version: ${version}`);
|
||||||
|
|
||||||
if (this.updateAvailable && this.latestVersion) {
|
if (this.updateAvailable && this.latestVersion) {
|
||||||
|
@ -190,20 +190,20 @@ WantedBy=multi-user.target
|
|||||||
timeout: Math.min(config.snmp.timeout, 10000) // Use at most 10 seconds for status check
|
timeout: Math.min(config.snmp.timeout, 10000) // Use at most 10 seconds for status check
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log('┌─ Connecting to UPS... ────────────────────┐');
|
console.log('┌─ Connecting to UPS... ─────────────────────┐');
|
||||||
console.log(`│ Host: ${config.snmp.host}:${config.snmp.port}`);
|
console.log(`│ Host: ${config.snmp.host}:${config.snmp.port}`);
|
||||||
console.log(`│ UPS Model: ${config.snmp.upsModel || 'cyberpower'}`);
|
console.log(`│ UPS Model: ${config.snmp.upsModel || 'cyberpower'}`);
|
||||||
console.log('└──────────────────────────────────────────┘');
|
console.log('└────────────────────────────────────────────┘');
|
||||||
|
|
||||||
const status = await snmp.getUpsStatus(snmpConfig);
|
const status = await snmp.getUpsStatus(snmpConfig);
|
||||||
|
|
||||||
console.log('┌─ UPS Status ───────────────────────────────┐');
|
console.log('┌─ UPS Status ─────────────────────────────┐');
|
||||||
console.log(`│ Power Status: ${status.powerStatus}`);
|
console.log(`│ Power Status: ${status.powerStatus}`);
|
||||||
console.log(`│ Battery Capacity: ${status.batteryCapacity}%`);
|
console.log(`│ Battery Capacity: ${status.batteryCapacity}%`);
|
||||||
console.log(`│ Runtime Remaining: ${status.batteryRuntime} minutes`);
|
console.log(`│ Runtime Remaining: ${status.batteryRuntime} minutes`);
|
||||||
console.log('└──────────────────────────────────────────┘');
|
console.log('└──────────────────────────────────────────┘');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('┌─ UPS Status ───────────────────────────────┐');
|
console.error('┌─ UPS Status ─────────────────────────────┐');
|
||||||
console.error(`│ Failed to retrieve UPS status: ${error.message}`);
|
console.error(`│ Failed to retrieve UPS status: ${error.message}`);
|
||||||
console.error('└──────────────────────────────────────────┘');
|
console.error('└──────────────────────────────────────────┘');
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user