feat(cli): Improve CLI output and logging with colored header, grouped script listings, and ANSI-styled logger

This commit is contained in:
2025-10-28 19:03:13 +00:00
parent d832343b38
commit 45ac9af405
4 changed files with 58 additions and 15 deletions

View File

@@ -1,5 +1,14 @@
# Changelog
## 2025-10-28 - 1.4.0 - feat(cli)
Improve CLI output and logging with colored header, grouped script listings, and ANSI-styled logger
- Set smartcli instance version from deno.json to surface the package version in the CLI
- Revamp standard command output with a colored ASCII header, clearer commands list, and improved usage line
- Group script index output by type including Proxmox VE host (pve), Containers (ct), Virtual Machines (vm), and Other
- Enhance scripts listing formatting (slug padding and bullet points) for readability
- Replace timestamped logger messages with ANSI-colored output and icons for error/warn/success/info
## 2025-10-28 - 1.3.6 - fix(deps)
Bump smartcli dependency and add local settings file

View File

@@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@serve.zone/moxytool',
version: '1.3.6',
version: '1.4.0',
description: 'Proxmox administration tool for vGPU setup, VM management, and cluster configuration'
}

View File

@@ -3,6 +3,7 @@ import * as paths from './moxytool.paths.ts';
import { logger } from './moxytool.logging.ts';
import { ScriptIndex } from './moxytool.classes.scriptindex.ts';
import { ScriptRunner } from './moxytool.classes.scriptrunner.ts';
import denoConfig from '../deno.json' with { type: 'json' };
export const runCli = async () => {
const smartshellInstance = new plugins.smartshell.Smartshell({
@@ -10,6 +11,7 @@ export const runCli = async () => {
});
const smartcliInstance = new plugins.smartcli.Smartcli();
smartcliInstance.version = denoConfig.version;
// Initialize script index and check if refresh is needed
const scriptIndex = new ScriptIndex();
@@ -31,14 +33,16 @@ export const runCli = async () => {
// Standard command (no arguments)
smartcliInstance.standardCommand().subscribe(async () => {
logger.log('info', 'MOXYTOOL - Proxmox Administration Tool');
logger.log('info', '');
logger.log('info', 'Available commands:');
logger.log('info', '* vgpu-setup - Install and configure Proxmox vGPU support');
logger.log('info', '* scripts - Manage Proxmox community scripts');
logger.log('info', '* update - Update MOXYTOOL to the latest version');
logger.log('info', '');
logger.log('info', 'Usage: moxytool <command> [options]');
console.log('\x1b[1m\x1b[36m╔════════════════════════════════════════════╗\x1b[0m');
console.log('\x1b[1m\x1b[36m║\x1b[0m \x1b[1mMOXYTOOL\x1b[0m - Proxmox Administration \x1b[1m\x1b[36m║\x1b[0m');
console.log('\x1b[1m\x1b[36m╚════════════════════════════════════════════╝\x1b[0m');
console.log('');
console.log('\x1b[1mCommands:\x1b[0m');
console.log(' \x1b[36m►\x1b[0m vgpu-setup Install and configure Proxmox vGPU support');
console.log(' \x1b[36m►\x1b[0m scripts Manage Proxmox community scripts (400+)');
console.log(' \x1b[36m►\x1b[0m update Update MOXYTOOL to the latest version');
console.log('');
console.log('\x1b[2mUsage: moxytool <command> [options]\x1b[0m');
});
// vGPU setup command
@@ -237,8 +241,18 @@ export const runCli = async () => {
logger.log('info', '');
// Group by type
const pveScripts = scripts.filter(s => s.type === 'pve');
const containers = scripts.filter(s => s.type === 'ct');
const vms = scripts.filter(s => s.type === 'vm');
const otherScripts = scripts.filter(s => s.type !== 'pve' && s.type !== 'ct' && s.type !== 'vm');
if (pveScripts.length > 0) {
logger.log('info', 'Proxmox VE Host Scripts:');
pveScripts.forEach(script => {
logger.log('info', `${script.slug.padEnd(25)} - ${script.name}`);
});
logger.log('info', '');
}
if (containers.length > 0) {
logger.log('info', 'Containers (LXC):');
@@ -253,6 +267,14 @@ export const runCli = async () => {
vms.forEach(script => {
logger.log('info', `${script.slug.padEnd(25)} - ${script.name}`);
});
logger.log('info', '');
}
if (otherScripts.length > 0) {
logger.log('info', 'Other:');
otherScripts.forEach(script => {
logger.log('info', `${script.slug.padEnd(25)} - ${script.name} (${script.type})`);
});
}
logger.log('info', '');

View File

@@ -1,5 +1,19 @@
import * as plugins from './moxytool.plugins.ts';
// ANSI color codes
const colors = {
reset: '\x1b[0m',
bright: '\x1b[1m',
dim: '\x1b[2m',
red: '\x1b[31m',
green: '\x1b[32m',
yellow: '\x1b[33m',
blue: '\x1b[34m',
magenta: '\x1b[35m',
cyan: '\x1b[36m',
white: '\x1b[37m',
};
/**
* A simple logger class for MOXYTOOL
*/
@@ -14,22 +28,20 @@ class Logger {
}
public log(level: string, message: string): void {
const timestamp = new Date().toISOString();
switch (level) {
case 'error':
console.error(`[${timestamp}] [ERROR] ${message}`);
console.error(`${colors.red}${message}${colors.reset}`);
break;
case 'warn':
console.warn(`[${timestamp}] [WARN] ${message}`);
console.warn(`${colors.yellow}${message}${colors.reset}`);
break;
case 'ok':
case 'success':
console.log(`[${timestamp}] [OK] ${message}`);
console.log(`${colors.green}${message}${colors.reset}`);
break;
case 'info':
default:
console.log(`[${timestamp}] [INFO] ${message}`);
console.log(message);
break;
}
}