docs: 补充 Windows PowerShell 命令约束 (#28)

This commit is contained in:
ila
2026-09-02 15:21:04 +08:00
parent 90938be380
commit 40b99387ad
5 changed files with 67 additions and 5 deletions
+3 -3
View File
@@ -2,8 +2,8 @@
generated: true (请先修改 Gitea Wiki,禁止直接编辑本文件)
wiki_page: Project-Profile
wiki_url: https://git.ilapage.cn/OPC/dev_harness/wiki/Project-Profile.-
wiki_revision: 5323a382fc19433c19441587120d5a0ee6447a24
synchronized_at: 2026-09-02T02:08:46Z
wiki_revision: 54598b0fed91a852385386bd6fd920245f5dc1dd
synchronized_at: 2026-09-02T07:17:36Z
<!-- gitea-wiki-mirror:end -->
# 项目档案
@@ -65,7 +65,7 @@ synchronized_at: 2026-09-02T02:08:46Z
|---|---|---|
| Harness 规则和模板 | Markdown、Gitea 1.25 | `AGENTS.md` |
| Wiki 镜像与结构检查 | Python 3 标准库 | `AGENTS.md` |
| 主要开发环境 | Windows、PowerShell、Git | `AGENTS.md` |
| 主要开发环境 | Windows 10、PowerShell 7 `pwsh`(当前验证 7.3.12)、Git | `AGENTS.md` |
本项目不需要安装第三方 Python 包。复制到业务项目后,必须把真实语言、框架、版本和支持平台写入本节。
+37 -2
View File
@@ -2,8 +2,8 @@
generated: true (请先修改 Gitea Wiki,禁止直接编辑本文件)
wiki_page: Local-Development-and-Verification
wiki_url: https://git.ilapage.cn/OPC/dev_harness/wiki/Local-Development-and-Verification.-
wiki_revision: a7f6ef9e0788065e5a81cfef5753a12b0f0bebc8
synchronized_at: 2026-08-27T07:00:30Z
wiki_revision: a94b4eaa509f351b77274f007ae882e9e696fc8b
synchronized_at: 2026-09-02T07:20:33Z
<!-- gitea-wiki-mirror:end -->
# 本地开发与验证
@@ -32,6 +32,41 @@ synchronized_at: 2026-08-27T07:00:30Z
- 不得仅为设置编码重复启动一层 PowerShell;嵌套进程会增加启动时间、转义复杂度和错误定位成本。
- 代码搜索仍优先使用代码图工具;非代码文本或图工具不足时优先使用 `rg`,不因本节改用 `Select-String`。
### PowerShell 语法与外部命令
- Windows 环境默认使用当前 PowerShell 语法,不套用 Bash 的 heredoc、变量、路径、引号或反斜杠转义规则。只有明确调用 Bash、WSL 或 Git Bash,并确认路径与编码边界时,才使用 Bash 专用语法。
- 不需要变量展开的正则和字符串优先用单引号;单引号字符串内部的单引号写成两个单引号。需要变量展开时才使用双引号。
- 正则同时包含单双引号或转义复杂时,优先赋值给变量、使用 `rg -e`,或拆成语义等价的简单查询;不得为了避开转义改变 AND/OR 条件或重复执行无关搜索。
```powershell
rg -n 'error|warning' docs
$pattern = 'can''t match "value"'
rg -n -e $pattern docs
```
PowerShell 不支持 Bash heredoc。需要把多行 Python 送入标准输入时,使用单引号 here-string,避免 PowerShell 展开 Python 中的 dollar sign(`$`)等内容。起始标记后必须立即换行,结束标记必须单独占一行:
```powershell
@'
print("hello")
'@ | python -
```
`foreach`、`if` 等语句块不能裸放在管道左侧;需要管道输出时使用 `$()`、`@()` 或先赋值。普通命令输出无需包装:
```powershell
@(foreach ($number in 1..3) { $number }) |
Measure-Object
```
不要把含 `*` 的搜索路径直接作为 `rg` 路径参数。优先传入真实目录,并用 `-g/--glob` 让 ripgrep 筛选路径:
```powershell
rg -n -g '*.md' 'PowerShell' docs
```
只有确实需要把实体路径列表交给其他命令时,才使用 `Get-ChildItem` 展开并传递 `.FullName`;不要把 `Get-ChildItem -Filter` 设为所有 `rg` 搜索的固定前置。
### 文件编码
文件解码与控制台输出编码是不同问题。读取 UTF-8 文本时,在命令支持的情况下显式指定编码和字面路径: