feat(cli): add --debug/-d flag for CLI debugging

- Add -d/--debug option to ccw cli command
- Enable debug logging at runtime when flag is set
- Change DEBUG check from const to function for runtime evaluation
- Support debug mode for both exec and status subcommands
- Update help text to include --debug option

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
catlog22
2025-12-29 23:26:48 +08:00
parent 6efc499c77
commit f566b8aabc
5 changed files with 27 additions and 10 deletions

View File

@@ -10,11 +10,13 @@ import { spawn, ChildProcess } from 'child_process';
import { existsSync, mkdirSync, readFileSync, writeFileSync, unlinkSync, readdirSync, statSync } from 'fs';
import { join, relative } from 'path';
// Debug logging utility
const DEBUG = process.env.DEBUG === 'true' || process.env.DEBUG === '1' || process.env.CCW_DEBUG === 'true';
// Debug logging utility - check env at runtime for --debug flag support
function isDebugEnabled(): boolean {
return process.env.DEBUG === 'true' || process.env.DEBUG === '1' || process.env.CCW_DEBUG === 'true';
}
function debugLog(category: string, message: string, data?: Record<string, unknown>): void {
if (!DEBUG) return;
if (!isDebugEnabled()) return;
const timestamp = new Date().toISOString();
const prefix = `[${timestamp}] [CLI-DEBUG] [${category}]`;
if (data) {
@@ -30,7 +32,7 @@ function errorLog(category: string, message: string, error?: Error | unknown, co
console.error(`${prefix} ${message}`);
if (error instanceof Error) {
console.error(`${prefix} Error: ${error.message}`);
if (DEBUG && error.stack) {
if (isDebugEnabled() && error.stack) {
console.error(`${prefix} Stack: ${error.stack}`);
}
} else if (error) {