From 22c2d17954b4a23bd8f180baafd9aa9c1b193598 Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Thu, 18 Jun 2026 14:32:55 +0800 Subject: [PATCH] =?UTF-8?q?feat(cli):=20=E6=B7=BB=E5=8A=A0=20no-color=20?= =?UTF-8?q?=E5=91=BD=E4=BB=A4=E8=A1=8C=E9=80=89=E9=A1=B9=E5=B9=B6=E6=B8=85?= =?UTF-8?q?=E7=90=86=E5=B8=AE=E5=8A=A9=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加 no-color 参数用于禁用 ANSI 颜色输出 - 移除帮助文档中过多的命令行示例 - 简化 CLI 帮助界面以提高可读性 --- src/Php/Constants.php | 6 ++++++ src/Php/Translator.php | 39 +++++++++++++++++---------------------- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/Php/Constants.php b/src/Php/Constants.php index 69b9c790..937d50cd 100644 --- a/src/Php/Constants.php +++ b/src/Php/Constants.php @@ -169,6 +169,12 @@ class Constants 'required' => false, 'defaultValue' => '', ], + 'no-color' => [ + 'longPrefix' => 'no-color', + 'description' => 'Disable ANSI color output', + 'required' => false, + 'noValue' => true, + ], 'build-dir' => [ 'longPrefix' => 'build-dir', 'description' => 'Specify the build directory for generated C++ code', diff --git a/src/Php/Translator.php b/src/Php/Translator.php index 4dfa9b6f..b1c9c3c4 100644 --- a/src/Php/Translator.php +++ b/src/Php/Translator.php @@ -137,6 +137,11 @@ class Translator extends Preprocessor exit(0); } + // 提前处理 --no-color,确保后续所有输出均为无颜色模式 + if ($this->climate->arguments->defined('no-color')) { + $this->climate->forceAnsiOff(); + } + // 检测操作系统、编译器以及 Windows 平台的 PHP lib 文件 $this->detectPlatform(); @@ -206,11 +211,18 @@ class Translator extends Preprocessor $climate->tab()->out(' Input PHP file/directory/project.yml to compile'); $climate->br(); + $climate->bold('EXAMPLES:'); + $climate->tab()->out($cmd . ' hello.php'); + $climate->tab()->out($cmd . ' bench.php -O2'); + $climate->tab()->out($cmd . ' project/config.yml -O2'); + $climate->tab()->out($cmd . ' my-ext/ -O2 -o myapp -m ext'); + $climate->tab()->out($cmd . ' app.php -r -O2 -- --flag1 value1'); + $climate->br(); + $climate->bold('OPTIONS:'); $climate->tab()->out('-O Optimization level (0-3, default: 0)'); $climate->tab()->out('--profile Enable performance profiling (adds -lprofiler, forces recompile)'); $climate->tab()->out('-d, --debug Enable debug mode (auto-disable optimizations, add debug symbols)'); - $climate->tab()->out('--cxx-std C++ standard version (c++17, c++20, etc.)'); $climate->tab()->out('-o, --output Output binary name (default: input basename)'); $climate->tab()->out('-v, --version Show version'); $climate->tab()->out('-h, --help Show this help message'); @@ -218,38 +230,21 @@ class Translator extends Preprocessor $climate->tab()->out('-m, --mode Compilation mode, -m bin(binary) or -m ext(extension), default: bin'); $climate->tab()->out('-r, --run Run the compiled binary after build'); $climate->tab()->out('-j, --job Number of parallel compilation jobs (default: 4)'); + $climate->tab()->out('--cxx-std C++ standard version (c++17, c++20, etc., default: c++17)'); + $climate->tab()->out('--march Target CPU instruction set (e.g. native, x86-64-v3, armv8-a)'); + $climate->tab()->out('--lto Enable Link Time Optimization (-flto)'); $climate->tab()->out('--no-literal-strings Disable literal strings optimization'); $climate->tab()->out('--no-console Hide console window (Windows only, GUI application)'); + $climate->tab()->out('--no-color Disable ANSI color output'); $climate->tab()->out('--sanitize Enable sanitizers (address, undefined, etc.)'); $climate->tab()->out('--build-dir Specify build directory for generated C++ code (default: /build)'); $climate->tab()->out('--dry Dry run: only generate C++ code, skip compilation and linking'); $climate->tab()->out('-I, --include-path Add an additional C++ include directory (repeatable)'); $climate->tab()->out('-D, --define Define a preprocessor macro (repeatable, e.g. -D FOO=bar)'); - $climate->tab()->out('--lto Enable Link Time Optimization (-flto)'); $climate->tab()->out('--format Enable clang-format code formatting (disabled by default)'); - $climate->tab()->out('--cxx-std C++ standard version (c++17, c++20, etc., default: c++17)'); - $climate->tab()->out('--march Target CPU instruction set (e.g. native, x86-64-v3, armv8-a)'); $climate->tab()->out('-l, --link-lib Link against a library (repeatable, e.g. -lcurl)'); $climate->tab()->out('-L, --link-path Add a library search path (repeatable, e.g. -L/usr/local/lib)'); $climate->br(); - - $climate->bold('EXAMPLES:'); - $climate->tab()->out($cmd . ' hello.php'); - $climate->tab()->out($cmd . ' bench.php -O2'); - $climate->tab()->out($cmd . ' project/config.yml -O2'); - $climate->tab()->out($cmd . ' my-ext/ -O2 -o myapp -m ext'); - $climate->tab()->out($cmd . ' app.php -O3 -o myapp -v'); - $climate->tab()->out($cmd . ' gui-app.php --no-console (Windows GUI app, no console)'); - $climate->tab()->out($cmd . ' app.php --sanitize=address (Enable AddressSanitizer)'); - $climate->tab()->out($cmd . ' app.php --cxx-std=c++17 (Use C++17 standard)'); - $climate->tab()->out($cmd . ' app.php --march=native -O2 (Optimize for host CPU)'); - $climate->tab()->out($cmd . ' app.php --march=x86-64-v3 -O2 (Target x86-64-v3 instructions)'); - $climate->tab()->out($cmd . ' app.php --no-literal-strings (Disable string optimization)'); - $climate->tab()->out($cmd . ' app.php -r -O2 -- --flag1 value1'); - $climate->tab()->out($cmd . ' hello.php --dry (only generate C++ code, skip compilation)'); - $climate->tab()->out($cmd . ' app.php --build-dir /tmp/mybuild -O2 (specify build directory)'); - $climate->tab()->out($cmd . ' app.php -I /opt/mylib/include -D MY_DEBUG=1 -O2 (custom includes and defines)'); - $climate->br(); } /**