fix(cli): improve project metadata loading and normalize CLI error handling
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import * as plugins from '../../plugins.js';
|
||||
import * as paths from '../../../paths.js';
|
||||
import { tspmIpcClient } from '../../../client/tspm.ipcclient.js';
|
||||
import { Logger } from '../../../shared/common/utils.errorhandler.js';
|
||||
import { handleError, Logger } from '../../../shared/common/utils.errorhandler.js';
|
||||
import type { CliArguments } from '../../types.js';
|
||||
import { formatMemory } from '../../helpers/memory.js';
|
||||
|
||||
@@ -76,7 +76,7 @@ export function registerDaemonCommand(smartcli: plugins.smartcli.Smartcli) {
|
||||
// Disconnect from the daemon after starting
|
||||
await tspmIpcClient.disconnect();
|
||||
} catch (error) {
|
||||
console.error('Error starting daemon:', error.message);
|
||||
console.error('Error starting daemon:', handleError(error).message);
|
||||
process.exit(1);
|
||||
}
|
||||
break;
|
||||
@@ -139,7 +139,7 @@ export function registerDaemonCommand(smartcli: plugins.smartcli.Smartcli) {
|
||||
// Disconnect from the daemon after stopping
|
||||
await tspmIpcClient.disconnect();
|
||||
} catch (error) {
|
||||
console.error('Error stopping daemon:', error.message);
|
||||
console.error('Error stopping daemon:', handleError(error).message);
|
||||
process.exit(1);
|
||||
}
|
||||
break;
|
||||
@@ -169,7 +169,7 @@ export function registerDaemonCommand(smartcli: plugins.smartcli.Smartcli) {
|
||||
// Disconnect from daemon after getting status
|
||||
await tspmIpcClient.disconnect();
|
||||
} catch (error) {
|
||||
console.error('Error getting daemon status:', error.message);
|
||||
console.error('Error getting daemon status:', handleError(error).message);
|
||||
process.exit(1);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -8,10 +8,10 @@ import { formatMemory } from '../helpers/memory.js';
|
||||
|
||||
export function registerDefaultCommand(smartcli: plugins.smartcli.Smartcli) {
|
||||
const cliLogger = new Logger('CLI');
|
||||
const tspmProjectinfo = new plugins.projectinfo.ProjectInfo(paths.packageDir);
|
||||
|
||||
smartcli.standardCommand().subscribe({
|
||||
next: async (argvArg: CliArguments) => {
|
||||
const tspmProjectinfo = await plugins.projectinfo.ProjectInfo.create(paths.packageDir);
|
||||
console.log(
|
||||
`TSPM - TypeScript Process Manager v${tspmProjectinfo.npm.version}`,
|
||||
);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as plugins from '../../plugins.js';
|
||||
import { TspmServiceManager } from '../../../client/tspm.servicemanager.js';
|
||||
import { Logger } from '../../../shared/common/utils.errorhandler.js';
|
||||
import { handleError, Logger } from '../../../shared/common/utils.errorhandler.js';
|
||||
import type { CliArguments } from '../../types.js';
|
||||
|
||||
export function registerDisableCommand(smartcli: plugins.smartcli.Smartcli) {
|
||||
@@ -18,10 +18,11 @@ export function registerDisableCommand(smartcli: plugins.smartcli.Smartcli) {
|
||||
console.log(' The daemon will no longer start on system boot');
|
||||
console.log(' Use "tspm enable" to re-enable the service');
|
||||
} catch (error) {
|
||||
console.error('Error disabling service:', error.message);
|
||||
const errorMessage = handleError(error).message;
|
||||
console.error('Error disabling service:', errorMessage);
|
||||
if (
|
||||
error.message.includes('permission') ||
|
||||
error.message.includes('denied')
|
||||
errorMessage.includes('permission') ||
|
||||
errorMessage.includes('denied')
|
||||
) {
|
||||
console.log('\nNote: You may need to run this command with sudo');
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as plugins from '../../plugins.js';
|
||||
import { TspmServiceManager } from '../../../client/tspm.servicemanager.js';
|
||||
import { Logger } from '../../../shared/common/utils.errorhandler.js';
|
||||
import { handleError, Logger } from '../../../shared/common/utils.errorhandler.js';
|
||||
import type { CliArguments } from '../../types.js';
|
||||
|
||||
export function registerEnableCommand(smartcli: plugins.smartcli.Smartcli) {
|
||||
@@ -18,10 +18,11 @@ export function registerEnableCommand(smartcli: plugins.smartcli.Smartcli) {
|
||||
console.log(' The daemon will now start automatically on system boot');
|
||||
console.log(' Use "tspm disable" to remove the service');
|
||||
} catch (error) {
|
||||
console.error('Error enabling service:', error.message);
|
||||
const errorMessage = handleError(error).message;
|
||||
console.error('Error enabling service:', errorMessage);
|
||||
if (
|
||||
error.message.includes('permission') ||
|
||||
error.message.includes('denied')
|
||||
errorMessage.includes('permission') ||
|
||||
errorMessage.includes('denied')
|
||||
) {
|
||||
console.log('\nNote: You may need to run this command with sudo');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user