style: configure deno fmt to use single quotes
All checks were successful
CI / Build All Platforms (Tag/Main only) (push) Has been skipped
CI / Type Check & Lint (push) Successful in 6s
CI / Build Test (Current Platform) (push) Successful in 6s

- Add singleQuote: true to deno.json fmt configuration
- Reformat all files with single quotes using deno fmt
This commit is contained in:
2025-10-19 13:14:18 +00:00
parent b935087d50
commit 071ded9c41
24 changed files with 1094 additions and 672 deletions

View File

@@ -6,7 +6,7 @@ import { logger } from './logger.ts';
import { UpsHandler } from './cli/ups-handler.ts';
import { GroupHandler } from './cli/group-handler.ts';
import { ServiceHandler } from './cli/service-handler.ts';
import * as https from "node:https";
import * as https from 'node:https';
/**
* Main Nupst class that coordinates all components
@@ -31,7 +31,7 @@ export class Nupst {
this.snmp.setNupst(this); // Set up bidirectional reference
this.daemon = new NupstDaemon(this.snmp);
this.systemd = new NupstSystemd(this.daemon);
// Initialize handlers
this.upsHandler = new UpsHandler(this);
this.groupHandler = new GroupHandler(this);
@@ -58,28 +58,28 @@ export class Nupst {
public getSystemd(): NupstSystemd {
return this.systemd;
}
/**
* Get the UPS handler for UPS management
*/
public getUpsHandler(): UpsHandler {
return this.upsHandler;
}
/**
* Get the Group handler for group management
*/
public getGroupHandler(): GroupHandler {
return this.groupHandler;
}
/**
* Get the Service handler for service management
*/
public getServiceHandler(): ServiceHandler {
return this.serviceHandler;
}
/**
* Get the current version of NUPST
* @returns The current version string
@@ -87,7 +87,7 @@ export class Nupst {
public getVersion(): string {
return commitinfo.version;
}
/**
* Check if an update is available
* @returns Promise resolving to true if an update is available
@@ -96,34 +96,36 @@ export class Nupst {
try {
const latestVersion = await this.getLatestVersion();
const currentVersion = this.getVersion();
// Compare versions
this.updateAvailable = this.compareVersions(latestVersion, currentVersion) > 0;
this.latestVersion = latestVersion;
return this.updateAvailable;
} catch (error) {
logger.error(`Error checking for updates: ${error instanceof Error ? error.message : String(error)}`);
logger.error(
`Error checking for updates: ${error instanceof Error ? error.message : String(error)}`,
);
return false;
}
}
/**
* Get update status information
* @returns Object with update status information
*/
public getUpdateStatus(): {
currentVersion: string,
latestVersion: string,
updateAvailable: boolean
public getUpdateStatus(): {
currentVersion: string;
latestVersion: string;
updateAvailable: boolean;
} {
return {
currentVersion: this.getVersion(),
latestVersion: this.latestVersion || this.getVersion(),
updateAvailable: this.updateAvailable
updateAvailable: this.updateAvailable,
};
}
/**
* Get the latest version from npm registry
* @returns Promise resolving to the latest version string
@@ -136,17 +138,17 @@ export class Nupst {
method: 'GET',
headers: {
'Accept': 'application/json',
'User-Agent': `nupst/${this.getVersion()}`
}
'User-Agent': `nupst/${this.getVersion()}`,
},
};
const req = https.request(options, (res) => {
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
try {
const response = JSON.parse(data);
@@ -160,15 +162,15 @@ export class Nupst {
}
});
});
req.on('error', (error) => {
reject(error);
});
req.end();
});
}
/**
* Compare two semantic version strings
* @param versionA First version
@@ -176,39 +178,39 @@ export class Nupst {
* @returns -1 if versionA < versionB, 0 if equal, 1 if versionA > versionB
*/
private compareVersions(versionA: string, versionB: string): number {
const partsA = versionA.split('.').map(part => parseInt(part, 10));
const partsB = versionB.split('.').map(part => parseInt(part, 10));
const partsA = versionA.split('.').map((part) => parseInt(part, 10));
const partsB = versionB.split('.').map((part) => parseInt(part, 10));
for (let i = 0; i < Math.max(partsA.length, partsB.length); i++) {
const partA = i < partsA.length ? partsA[i] : 0;
const partB = i < partsB.length ? partsB[i] : 0;
if (partA > partB) return 1;
if (partA < partB) return -1;
}
return 0; // Versions are equal
}
/**
* Log the current version and update status
*/
public logVersionInfo(checkForUpdates: boolean = true): void {
const version = this.getVersion();
const boxWidth = 45;
logger.logBoxTitle('NUPST Version', boxWidth);
logger.logBoxLine(`Current Version: ${version}`);
if (this.updateAvailable && this.latestVersion) {
logger.logBoxLine(`Update Available: ${this.latestVersion}`);
logger.logBoxLine('Run "sudo nupst update" to update');
logger.logBoxEnd();
} else if (checkForUpdates) {
logger.logBoxLine('Checking for updates...');
// We can't end the box yet since we're in an async operation
this.checkForUpdates().then(updateAvailable => {
this.checkForUpdates().then((updateAvailable) => {
if (updateAvailable) {
logger.logBoxLine(`Update Available: ${this.latestVersion}`);
logger.logBoxLine('Run "sudo nupst update" to update');
@@ -224,4 +226,4 @@ export class Nupst {
logger.logBoxEnd();
}
}
}
}