feat(cli): Refactor CLI commands to use dedicated handlers for UPS, group, and service management
This commit is contained in:
38
ts/nupst.ts
38
ts/nupst.ts
@@ -2,9 +2,11 @@ import { NupstSnmp } from './snmp/manager.js';
|
||||
import { NupstDaemon } from './daemon.js';
|
||||
import { NupstSystemd } from './systemd.js';
|
||||
import { commitinfo } from './00_commitinfo_data.js';
|
||||
import { spawn } from 'child_process';
|
||||
import * as https from 'https';
|
||||
import { logger } from './logger.js';
|
||||
import { UpsHandler } from './cli/ups-handler.js';
|
||||
import { GroupHandler } from './cli/group-handler.js';
|
||||
import { ServiceHandler } from './cli/service-handler.js';
|
||||
import * as https from 'https';
|
||||
|
||||
/**
|
||||
* Main Nupst class that coordinates all components
|
||||
@@ -14,6 +16,9 @@ export class Nupst {
|
||||
private readonly snmp: NupstSnmp;
|
||||
private readonly daemon: NupstDaemon;
|
||||
private readonly systemd: NupstSystemd;
|
||||
private readonly upsHandler: UpsHandler;
|
||||
private readonly groupHandler: GroupHandler;
|
||||
private readonly serviceHandler: ServiceHandler;
|
||||
private updateAvailable: boolean = false;
|
||||
private latestVersion: string = '';
|
||||
|
||||
@@ -21,10 +26,16 @@ export class Nupst {
|
||||
* Create a new Nupst instance with all necessary components
|
||||
*/
|
||||
constructor() {
|
||||
// Initialize core components
|
||||
this.snmp = new NupstSnmp();
|
||||
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);
|
||||
this.serviceHandler = new ServiceHandler(this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -48,6 +59,27 @@ export class Nupst {
|
||||
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
|
||||
@@ -192,4 +224,4 @@ export class Nupst {
|
||||
logger.logBoxEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user