Skip to content

Commit 12b2c09

Browse files
committed
fix(cli): 修复 Windows Shell 配置时的命令行参数处理顺序
- 将 Windows Shell 配置逻辑调整到 --version 和 --help 参数处理之后 - 避免在 Windows 无 Git Bash 环境下配置 Shell 时提前退出进程 - 确保命令行参数如 --version 和 --help 正常工作 - 添加 configureWindowsShell 函数注释说明其调用时机和作用 - 清理 cli.tsx 中的导入和调用顺序,提高代码可读性
1 parent 24a2ad9 commit 12b2c09

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

packages/cli/src/cli.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { writeStderrLine, writeStdoutLine } from "./utils/stdioHelpers";
1111
import { getPackageJson } from "./utils/package";
1212
import { CLI_VERSION } from "./generated/git-commit";
1313

14-
configureWindowsShell();
1514
void main();
1615

1716
async function main(): Promise<void> {
@@ -24,6 +23,11 @@ async function main(): Promise<void> {
2423
process.exit(0);
2524
}
2625

26+
// Configure Windows shell AFTER --version/--help handling.
27+
// On Windows without Git Bash, setShellIfWindows() throws and calls process.exit(1).
28+
// If called before argument parsing, --help and --version would fail on those machines.
29+
configureWindowsShell();
30+
2731
let initialPrompt = parsed.prompt;
2832
let resumeSessionId = parsed.resume;
2933
const projectRoot = process.cwd();
@@ -95,6 +99,12 @@ async function main(): Promise<void> {
9599
startApp();
96100
}
97101

102+
/**
103+
* Configure shell environment for Windows.
104+
* Sets NoDefaultCurrentDirectoryInExePath and resolves Git Bash path.
105+
* Must be called after --version/--help handling to avoid blocking those
106+
* commands on Windows machines without Git Bash installed.
107+
*/
98108
function configureWindowsShell(): void {
99109
process.env.NoDefaultCurrentDirectoryInExePath = "1";
100110
try {

0 commit comments

Comments
 (0)