diff --git a/README.md b/README.md index c921ca0..a0d6605 100644 --- a/README.md +++ b/README.md @@ -69,8 +69,8 @@ scripts\sync_templates.bat C:\path\to\project - **新项目**:创建完整的 `AGENTS.md`、`AGENT_RULES.md`、`memory-bank/`、`docs/prompts/`、`TODO.md`、`CONFIRM.md` - **已有 AGENTS.md**:追加路由链接(使用 `` 标记) -- **--full 参数**:追加完整框架(规则优先级 + 新会话开始时)到已有 AGENTS.md -- **其他文件**:如果已存在则跳过(使用 `--force` 覆盖) +- **-full 参数**:追加完整框架(规则优先级 + 新会话开始时)到已有 AGENTS.md +- **其他文件**:如果已存在则跳过(使用 `-force` 覆盖) 详见:`templates/README.md` @@ -374,7 +374,7 @@ sh docs/standards/playbook/scripts/sync_standards.sh tsl cpp - Windows bat: ```bat - \\scripts\\vendor_playbook.bat --langs tsl,cpp + \\scripts\\vendor_playbook.bat -langs tsl,cpp ``` **脚本会**: diff --git a/SKILLS.md b/SKILLS.md index 2b3e83b..10ded3f 100644 --- a/SKILLS.md +++ b/SKILLS.md @@ -67,7 +67,7 @@ sh scripts/install_codex_skills.sh style-cleanup code-review-workflow ```bash # 安装到当前目录的 .codex/skills/ -sh scripts/install_codex_skills.sh --local +sh scripts/install_codex_skills.sh -local # 或手动指定 CODEX_HOME CODEX_HOME="$(pwd)/.codex" sh scripts/install_codex_skills.sh @@ -80,7 +80,7 @@ powershell -File scripts/install_codex_skills.ps1 -Local ``` ```bat -scripts\install_codex_skills.bat --local +scripts\install_codex_skills.bat -local ``` > 注意:Codex 只会从 `CODEX_HOME` 加载 skills;使用本地安装时,启动 Codex 需设置同样的 `CODEX_HOME`。 diff --git a/scripts/install_codex_skills.bat b/scripts/install_codex_skills.bat index 5ad78ed..2a51c4b 100644 --- a/scripts/install_codex_skills.bat +++ b/scripts/install_codex_skills.bat @@ -8,7 +8,7 @@ rem rem Usage: rem install_codex_skills.bat rem install_codex_skills.bat style-cleanup code-review-workflow -rem install_codex_skills.bat --local +rem install_codex_skills.bat -local rem rem Notes: rem - Codex loads skills at startup; restart `codex` after installation. @@ -19,10 +19,23 @@ for %%I in ("%SCRIPT_DIR%..") do set "SRC=%%~fI" set "SKILLS_SRC_ROOT=%SRC%\\codex\\skills" set "LOCAL_MODE=0" -if /I "%~1"=="--local" set "LOCAL_MODE=1" -if /I "%~1"=="-l" set "LOCAL_MODE=1" -if "%LOCAL_MODE%"=="1" shift +:parse_opts +if "%~1"=="" goto opts_done +if /I "%~1"=="-help" goto show_help +if /I "%~1"=="-h" goto show_help +if /I "%~1"=="-local" ( + set "LOCAL_MODE=1" + shift + goto parse_opts +) +if /I "%~1"=="-l" ( + set "LOCAL_MODE=1" + shift + goto parse_opts +) +goto opts_done +:opts_done set "CODEX_HOME=%CODEX_HOME%" if "%LOCAL_MODE%"=="1" if "%CODEX_HOME%"=="" set "CODEX_HOME=%CD%\\.codex" if "%CODEX_HOME%"=="" set "CODEX_HOME=%USERPROFILE%\\.codex" @@ -53,6 +66,18 @@ echo Done. Skills installed to: "%SKILLS_DST_ROOT%" endlocal exit /b 0 +:show_help +echo Usage: +echo install_codex_skills.bat [options] [skill ...] +echo. +echo Options: +echo -local, -l Install to .\\.codex ^(or CODEX_HOME if set^) +echo -help, -h Show this help +echo. +echo Env: +echo CODEX_HOME Target Codex home ^(default: %%USERPROFILE%%\\.codex^) +exit /b 0 + :InstallOne set "NAME=%~1" set "SRC_DIR=%SKILLS_SRC_ROOT%\\%NAME%" diff --git a/scripts/install_codex_skills.ps1 b/scripts/install_codex_skills.ps1 index f0b8958..8c85bbc 100644 --- a/scripts/install_codex_skills.ps1 +++ b/scripts/install_codex_skills.ps1 @@ -13,12 +13,28 @@ [CmdletBinding()] param( + [Alias('h', 'help', '?')] + [switch]$Help, + [switch]$Local, [Parameter(Mandatory = $false, ValueFromRemainingArguments = $true)] [string[]]$Skills ) $ErrorActionPreference = "Stop" + +if ($Help) { + Write-Host "Usage:" + Write-Host " powershell -File scripts/install_codex_skills.ps1 [options] [skill ...]" + Write-Host "" + Write-Host "Options:" + Write-Host " -Local Install to ./.codex (or CODEX_HOME if set)." + Write-Host " -Help Show this help." + Write-Host "" + Write-Host "Env:" + Write-Host " CODEX_HOME Target Codex home (default: ~/.codex)." + exit 0 +} $ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path $Src = (Resolve-Path (Join-Path $ScriptDir "..")).Path $SkillsSrcRoot = Join-Path $Src "codex/skills" diff --git a/scripts/install_codex_skills.sh b/scripts/install_codex_skills.sh index b0e0bda..95decdf 100644 --- a/scripts/install_codex_skills.sh +++ b/scripts/install_codex_skills.sh @@ -8,7 +8,7 @@ set -eu # Usage: # sh scripts/install_codex_skills.sh # install all skills # sh scripts/install_codex_skills.sh style-cleanup code-review-workflow -# sh scripts/install_codex_skills.sh --local # install to /.codex +# sh scripts/install_codex_skills.sh -local # install to /.codex # # Notes: # - Codex loads skills at startup; restart `codex` after installation. @@ -18,11 +18,41 @@ SCRIPT_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd -P)" SRC="$(CDPATH= cd -- "$SCRIPT_DIR/.." && pwd -P)" SKILLS_SRC_ROOT="$SRC/codex/skills" +usage() { + cat <<'EOF' >&2 +Usage: + sh scripts/install_codex_skills.sh [options] [skill ...] + +Options: + -local, -l Install to ./.codex (or CODEX_HOME if set). + -h, -help Show this help. + +Env: + CODEX_HOME Target Codex home (default: ~/.codex). +EOF +} + LOCAL_MODE=0 -if [ "${1:-}" = "--local" ] || [ "${1:-}" = "-l" ]; then - LOCAL_MODE=1 - shift -fi +while [ $# -gt 0 ]; do + case "$1" in + -local|-l) + LOCAL_MODE=1 + shift + ;; + -h|-help) + usage + exit 0 + ;; + -*) + echo "ERROR: Unknown option: $1" >&2 + usage + exit 1 + ;; + *) + break + ;; + esac +done if [ "$LOCAL_MODE" -eq 1 ]; then LOCAL_CODEX_HOME="$(pwd -P)/.codex" diff --git a/scripts/sync_standards.bat b/scripts/sync_standards.bat index 936b5ab..02afcbe 100644 --- a/scripts/sync_standards.bat +++ b/scripts/sync_standards.bat @@ -11,6 +11,9 @@ rem sync_standards.bat tsl cpp rem Notes: rem - When syncing multiple rulesets, .gitattributes is synced only once (first ruleset). +if /I "%~1"=="-h" goto show_help +if /I "%~1"=="-help" goto show_help + set "SCRIPT_DIR=%~dp0" set "ROOT=%SYNC_ROOT%" if "%ROOT%"=="" for /f "delims=" %%R in ('git -C "%SCRIPT_DIR%" rev-parse --show-toplevel 2^>nul') do set "ROOT=%%R" @@ -32,6 +35,23 @@ set "GITATTR_DST=%ROOT%\.gitattributes" set "SYNC_GITATTR_MODE=%SYNC_GITATTR_MODE%" if "%SYNC_GITATTR_MODE%"=="" set "SYNC_GITATTR_MODE=append" +goto after_help + +:show_help +echo Usage: +echo sync_standards.bat +echo sync_standards.bat tsl cpp +echo. +echo Options: +echo -h, -help Show this help. +echo. +echo Env: +echo SYNC_ROOT Target project root ^(default: git root^). +echo AGENTS_NS Single ruleset name ^(default: tsl^). +echo SYNC_GITATTR_MODE append^|overwrite^|block^|skip ^(default: append^). +exit /b 0 + +:after_help rem Multi rulesets: only on outer invocation. if "%SYNC_STANDARDS_INNER%"=="" ( set "LANG_LIST=" diff --git a/scripts/sync_standards.ps1 b/scripts/sync_standards.ps1 index debc4d4..7a2aa55 100644 --- a/scripts/sync_standards.ps1 +++ b/scripts/sync_standards.ps1 @@ -4,6 +4,10 @@ # Existing targets are backed up before overwrite. [CmdletBinding()] param( + [Parameter(Mandatory = $false)] + [Alias('h', 'help', '?')] + [switch]$Help, + # Sync multiple rulesets in one run: # -Langs tsl,cpp # -Langs @("tsl","cpp") @@ -12,6 +16,22 @@ param( ) $ErrorActionPreference = "Stop" + +if ($Help) { + Write-Host "Usage:" + Write-Host " powershell -File scripts/sync_standards.ps1" + Write-Host " powershell -File scripts/sync_standards.ps1 -Langs tsl,cpp" + Write-Host "" + Write-Host "Options:" + Write-Host " -Langs Comma/space-separated list or array." + Write-Host " -Help Show this help." + Write-Host "" + Write-Host "Env:" + Write-Host " SYNC_ROOT Target project root (default: git root)." + Write-Host " AGENTS_NS Single ruleset name (default: tsl)." + Write-Host " SYNC_GITATTR_MODE append|overwrite|block|skip (default: append)." + exit 0 +} $ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path $Src = (Resolve-Path (Join-Path $ScriptDir "..")).Path diff --git a/scripts/sync_standards.sh b/scripts/sync_standards.sh index 39a6e35..c726d7f 100644 --- a/scripts/sync_standards.sh +++ b/scripts/sync_standards.sh @@ -8,7 +8,7 @@ set -eu # # Multi rulesets: # sh .../sync_standards.sh tsl cpp -# sh .../sync_standards.sh --langs tsl,cpp +# sh .../sync_standards.sh -langs tsl,cpp # Notes: # - When syncing multiple rulesets, .gitattributes is synced only once (first ruleset). @@ -21,6 +21,29 @@ else fi ROOT="$(CDPATH= cd -- "$ROOT" && pwd -P)" +usage() { + cat <<'EOF' >&2 +Usage: + sh scripts/sync_standards.sh + sh scripts/sync_standards.sh tsl cpp + sh scripts/sync_standards.sh -langs tsl,cpp + +Options: + -langs L1,L2 Comma/space-separated list of languages. + -h, -help Show this help. + +Env: + SYNC_ROOT Target project root (default: git root). + AGENTS_NS Single ruleset name (default: tsl). + SYNC_GITATTR_MODE append|overwrite|block|skip (default: append). +EOF +} + +if [ "${1:-}" = "-h" ] || [ "${1:-}" = "-help" ]; then + usage + exit 0 +fi + AGENTS_SRC_ROOT="$SRC/rulesets" GITATTR_SRC="$SRC/.gitattributes" @@ -41,7 +64,7 @@ fi # Parse multi rulesets only on the outer invocation. if [ "${SYNC_STANDARDS_INNER:-}" != "1" ]; then langs="" - if [ "${1:-}" = "--langs" ]; then + if [ "${1:-}" = "-langs" ]; then langs="${2:-}" shift 2 fi diff --git a/scripts/sync_templates.bat b/scripts/sync_templates.bat index 516334e..9b92127 100644 --- a/scripts/sync_templates.bat +++ b/scripts/sync_templates.bat @@ -11,8 +11,8 @@ rem rem Usage: rem sync_templates.bat # sync to current git root rem sync_templates.bat # sync to specified project -rem sync_templates.bat --force # overwrite existing files -rem sync_templates.bat --full # append full framework to existing AGENTS.md +rem sync_templates.bat -force # overwrite existing files +rem sync_templates.bat -full # append full framework to existing AGENTS.md set "SCRIPT_DIR=%~dp0" for %%I in ("%SCRIPT_DIR%..") do set "SRC=%%~fI" @@ -23,18 +23,18 @@ set "PROJECT_ROOT=" :parse_args if "%~1"=="" goto args_done -if /I "%~1"=="--force" ( +if /I "%~1"=="-force" ( set "FORCE=1" shift goto parse_args ) -if /I "%~1"=="--full" ( +if /I "%~1"=="-full" ( set "FULL=1" shift goto parse_args ) if /I "%~1"=="-h" goto show_help -if /I "%~1"=="--help" goto show_help +if /I "%~1"=="-help" goto show_help set "PROJECT_ROOT=%~1" shift goto parse_args @@ -44,9 +44,9 @@ echo Usage: echo sync_templates.bat [options] [project-root] echo. echo Options: -echo --force Overwrite existing files -echo --full Append full framework (规则优先级 + 新会话开始时) to existing AGENTS.md -echo -h, --help Show this help +echo -force Overwrite existing files +echo -full Append full framework (规则优先级 + 新会话开始时) to existing AGENTS.md +echo -h, -help Show this help exit /b 0 :args_done @@ -89,7 +89,7 @@ set "MEMORY_BANK_DST=%PROJECT_ROOT%\memory-bank" if exist "%MEMORY_BANK_SRC%" ( if exist "%MEMORY_BANK_DST%" ( if "%FORCE%"=="0" ( - echo memory-bank/ already exists. Skip. Use --force to overwrite. + echo memory-bank/ already exists. Skip. Use -force to overwrite. goto sync_prompts ) ) @@ -118,7 +118,7 @@ set "PROMPTS_DST=%PROJECT_ROOT%\docs\prompts" if exist "%PROMPTS_SRC%" ( if exist "%PROMPTS_DST%" ( if "%FORCE%"=="0" ( - echo docs/prompts/ already exists. Skip. Use --force to overwrite. + echo docs/prompts/ already exists. Skip. Use -force to overwrite. goto sync_agents ) ) @@ -146,7 +146,7 @@ if exist "%PROMPTS_SRC%" ( rem 3. Sync AGENTS.md set "AGENTS_DST=%PROJECT_ROOT%\AGENTS.md" -rem Choose markers based on --full flag +rem Choose markers based on -full flag if "%FULL%"=="1" ( set "MARKER_START=" set "MARKER_END=" @@ -199,7 +199,7 @@ set "AGENT_RULES_DST=%PROJECT_ROOT%\AGENT_RULES.md" if exist "%AGENT_RULES_SRC%" ( if exist "%AGENT_RULES_DST%" ( if "%FORCE%"=="0" ( - echo AGENT_RULES.md already exists. Skip. Use --force to overwrite. + echo AGENT_RULES.md already exists. Skip. Use -force to overwrite. goto sync_todo ) ) diff --git a/scripts/sync_templates.ps1 b/scripts/sync_templates.ps1 index ac74e36..644cd47 100644 --- a/scripts/sync_templates.ps1 +++ b/scripts/sync_templates.ps1 @@ -6,6 +6,10 @@ # Existing targets are backed up before overwrite. [CmdletBinding()] param( + [Parameter(Mandatory = $false)] + [Alias('h', 'help', '?')] + [switch]$Help, + [Parameter(Mandatory = $false, Position = 0)] [string]$ProjectRoot, @@ -26,6 +30,20 @@ param( ) $ErrorActionPreference = "Stop" + +if ($Help) { + Write-Host "Usage:" + Write-Host " powershell -File scripts/sync_templates.ps1 [options] [project-root]" + Write-Host "" + Write-Host "Options:" + Write-Host " -ProjectName NAME Replace {{PROJECT_NAME}} placeholder." + Write-Host " -Date DATE Replace {{DATE}} placeholder (default: today)." + Write-Host " -NoBackup Skip backup of existing files." + Write-Host " -Force Overwrite without prompting." + Write-Host " -Full Append full framework section to AGENTS.md." + Write-Host " -Help Show this help." + exit 0 +} $ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path $Src = (Resolve-Path (Join-Path $ScriptDir "..")).Path diff --git a/scripts/sync_templates.sh b/scripts/sync_templates.sh index f34e57d..dd3c90b 100644 --- a/scripts/sync_templates.sh +++ b/scripts/sync_templates.sh @@ -11,13 +11,14 @@ set -eu # Usage: # sh scripts/sync_templates.sh # sync to current git root # sh scripts/sync_templates.sh # sync to specified project -# sh scripts/sync_templates.sh --project-name "MyProject" --date "2026-01-20" +# sh scripts/sync_templates.sh -project-name "MyProject" -date "2026-01-20" # # Options: -# --project-name NAME Replace {{PROJECT_NAME}} placeholder -# --date DATE Replace {{DATE}} placeholder (default: today) -# --no-backup Skip backup of existing files -# --force Overwrite without prompting +# -project-name NAME Replace {{PROJECT_NAME}} placeholder +# -date DATE Replace {{DATE}} placeholder (default: today) +# -no-backup Skip backup of existing files +# -force Overwrite without prompting +# -full Append full framework (规则优先级 + 新会话开始时) to existing AGENTS.md SCRIPT_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd -P)" SRC="$(CDPATH= cd -- "$SCRIPT_DIR/.." && pwd -P)" @@ -33,43 +34,43 @@ PROJECT_ROOT="" # Parse arguments while [ $# -gt 0 ]; do case "$1" in - --project-name) + -project-name) PROJECT_NAME="$2" shift 2 ;; - --date) + -date) SYNC_DATE="$2" shift 2 ;; - --no-backup) + -no-backup) NO_BACKUP=1 shift ;; - --force) + -force) FORCE=1 shift ;; - --full) + -full) FULL=1 shift ;; - -h|--help) + -h|-help) cat <<'EOF' Usage: sh scripts/sync_templates.sh [options] [project-root] Options: - --project-name NAME Replace {{PROJECT_NAME}} placeholder - --date DATE Replace {{DATE}} placeholder (default: today) - --no-backup Skip backup of existing files - --force Overwrite without prompting - --full Append full framework (规则优先级 + 新会话开始时) to existing AGENTS.md - -h, --help Show this help + -project-name NAME Replace {{PROJECT_NAME}} placeholder + -date DATE Replace {{DATE}} placeholder (default: today) + -no-backup Skip backup of existing files + -force Overwrite without prompting + -full Append full framework (规则优先级 + 新会话开始时) to existing AGENTS.md + -h, -help Show this help Examples: sh scripts/sync_templates.sh sh scripts/sync_templates.sh /path/to/project - sh scripts/sync_templates.sh --full /path/to/project + sh scripts/sync_templates.sh -full /path/to/project EOF exit 0 ;; @@ -160,7 +161,7 @@ if [ -d "$MEMORY_BANK_SRC" ]; then MEMORY_BANK_DST="$PROJECT_ROOT/memory-bank" if [ -e "$MEMORY_BANK_DST" ] && [ "$FORCE" -eq 0 ]; then - echo "memory-bank/ already exists. Use --force to overwrite." + echo "memory-bank/ already exists. Use -force to overwrite." else backup_if_exists "$MEMORY_BANK_DST" mkdir -p "$MEMORY_BANK_DST" @@ -185,7 +186,7 @@ if [ -d "$PROMPTS_SRC" ]; then PROMPTS_DST="$PROJECT_ROOT/docs/prompts" if [ -e "$PROMPTS_DST" ] && [ "$FORCE" -eq 0 ]; then - echo "docs/prompts/ already exists. Use --force to overwrite." + echo "docs/prompts/ already exists. Use -force to overwrite." else backup_if_exists "$PROMPTS_DST" mkdir -p "$PROJECT_ROOT/docs" @@ -206,7 +207,7 @@ else fi # 3. Sync AGENTS.md -# Choose markers based on --full flag +# Choose markers based on -full flag if [ "$FULL" -eq 1 ]; then MARKER_START="" MARKER_END="" @@ -283,7 +284,7 @@ if [ -f "$AGENT_RULES_SRC" ]; then AGENT_RULES_DST="$PROJECT_ROOT/AGENT_RULES.md" if [ -e "$AGENT_RULES_DST" ] && [ "$FORCE" -eq 0 ]; then - echo "AGENT_RULES.md already exists. Use --force to overwrite." + echo "AGENT_RULES.md already exists. Use -force to overwrite." else backup_if_exists "$AGENT_RULES_DST" cp "$AGENT_RULES_SRC" "$AGENT_RULES_DST" diff --git a/scripts/vendor_playbook.bat b/scripts/vendor_playbook.bat index 881347f..d56a2e3 100644 --- a/scripts/vendor_playbook.bat +++ b/scripts/vendor_playbook.bat @@ -8,23 +8,23 @@ rem rem Usage: rem scripts\vendor_playbook.bat (default: tsl) rem scripts\vendor_playbook.bat tsl cpp -rem scripts\vendor_playbook.bat --langs tsl,cpp -rem scripts\vendor_playbook.bat tsl cpp --apply-templates +rem scripts\vendor_playbook.bat -langs tsl,cpp +rem scripts\vendor_playbook.bat tsl cpp -apply-templates rem rem Options: -rem --apply-templates Apply CI/lang templates to project root (skip if exists) +rem -apply-templates Apply CI/lang templates to project root (skip if exists) rem rem Notes: rem - Snapshot is written to: \docs\standards\playbook\ rem - Existing snapshot is backed up before overwrite. -rem - With --apply-templates, CI and lang templates are copied to project root. +rem - With -apply-templates, CI and lang templates are copied to project root. set "SCRIPT_DIR=%~dp0" for %%I in ("%SCRIPT_DIR%..") do set "SRC=%%~fI" if "%~1"=="" goto Usage if "%~1"=="-h" goto Usage -if "%~1"=="--help" goto Usage +if "%~1"=="-help" goto Usage set "DEST_ROOT=%~1" shift /1 @@ -35,13 +35,13 @@ set "APPLY_TEMPLATES=0" rem Parse arguments :parse_args if "%~1"=="" goto args_done -if "%~1"=="--langs" ( +if "%~1"=="-langs" ( set "LANGS=%~2" shift /1 shift /1 goto parse_args ) -if "%~1"=="--apply-templates" ( +if "%~1"=="-apply-templates" ( set "APPLY_TEMPLATES=1" shift /1 goto parse_args @@ -358,9 +358,9 @@ exit /b 0 echo Usage: echo scripts\vendor_playbook.bat ^ ^(default: tsl^) echo scripts\vendor_playbook.bat ^ tsl cpp -echo scripts\vendor_playbook.bat ^ --langs tsl,cpp -echo scripts\vendor_playbook.bat ^ tsl cpp --apply-templates +echo scripts\vendor_playbook.bat ^ -langs tsl,cpp +echo scripts\vendor_playbook.bat ^ tsl cpp -apply-templates echo. echo Options: -echo --apply-templates Apply CI/lang templates to project root ^(skip if exists^) +echo -apply-templates Apply CI/lang templates to project root ^(skip if exists^) exit /b 1 diff --git a/scripts/vendor_playbook.ps1 b/scripts/vendor_playbook.ps1 index a85cf40..84bff4f 100644 --- a/scripts/vendor_playbook.ps1 +++ b/scripts/vendor_playbook.ps1 @@ -17,7 +17,11 @@ [CmdletBinding()] param( - [Parameter(Mandatory = $true)] + [Parameter(Mandatory = $false)] + [Alias('h', 'help', '?')] + [switch]$Help, + + [Parameter(Mandatory = $false)] [string]$DestRoot, [Parameter(Mandatory = $false)] @@ -29,6 +33,24 @@ param( $ErrorActionPreference = "Stop" +if ($Help) { + Write-Host "Usage:" + Write-Host " powershell -File scripts/vendor_playbook.ps1 -DestRoot " + Write-Host " powershell -File scripts/vendor_playbook.ps1 -DestRoot -Langs tsl,cpp" + Write-Host " powershell -File scripts/vendor_playbook.ps1 -DestRoot -Langs @('tsl','cpp') -ApplyTemplates" + Write-Host "" + Write-Host "Options:" + Write-Host " -DestRoot Target project root." + Write-Host " -Langs Comma/space-separated list or array (default: tsl)." + Write-Host " -ApplyTemplates Apply CI/lang templates to project root." + Write-Host " -Help Show this help." + exit 0 +} + +if (-not $DestRoot) { + throw "DestRoot is required. Use -Help for usage." +} + function Normalize-Langs([string[]]$InputLangs) { if (-not $InputLangs -or $InputLangs.Count -eq 0) { return @("tsl") } diff --git a/scripts/vendor_playbook.sh b/scripts/vendor_playbook.sh index f79ba5a..518a695 100644 --- a/scripts/vendor_playbook.sh +++ b/scripts/vendor_playbook.sh @@ -8,17 +8,17 @@ set -eu # Usage: # sh scripts/vendor_playbook.sh # default: tsl # sh scripts/vendor_playbook.sh tsl cpp -# sh scripts/vendor_playbook.sh --langs tsl,cpp -# sh scripts/vendor_playbook.sh tsl cpp --apply-templates +# sh scripts/vendor_playbook.sh -langs tsl,cpp +# sh scripts/vendor_playbook.sh tsl cpp -apply-templates # # Options: -# --apply-templates Apply CI/lang templates to project root (skip if exists) +# -apply-templates Apply CI/lang templates to project root (skip if exists) # # Notes: # - Snapshot is written to: /docs/standards/playbook/ # - Existing snapshot is backed up before overwrite. # - Ruleset templates from rulesets/ will be copied to snapshot for sync_standards use. -# - With --apply-templates, CI and lang templates are copied to project root. +# - With -apply-templates, CI and lang templates are copied to project root. SCRIPT_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd -P)" SRC="$(CDPATH= cd -- "$SCRIPT_DIR/.." && pwd -P)" @@ -28,12 +28,12 @@ usage() { Usage: sh scripts/vendor_playbook.sh # default: tsl sh scripts/vendor_playbook.sh tsl cpp - sh scripts/vendor_playbook.sh --langs tsl,cpp - sh scripts/vendor_playbook.sh tsl cpp --apply-templates + sh scripts/vendor_playbook.sh -langs tsl,cpp + sh scripts/vendor_playbook.sh tsl cpp -apply-templates Options: - --apply-templates Apply CI/lang templates to project root (skip if exists) - -h, --help Show this help + -apply-templates Apply CI/lang templates to project root (skip if exists) + -h, -help Show this help EOF } @@ -42,7 +42,7 @@ if [ "$#" -lt 1 ]; then exit 1 fi -if [ "${1:-}" = "-h" ] || [ "${1:-}" = "--help" ]; then +if [ "${1:-}" = "-h" ] || [ "${1:-}" = "-help" ]; then usage exit 0 fi @@ -56,11 +56,11 @@ APPLY_TEMPLATES=0 # Parse arguments while [ $# -gt 0 ]; do case "$1" in - --langs) + -langs) langs="${2:-}" shift 2 || true ;; - --apply-templates) + -apply-templates) APPLY_TEMPLATES=1 shift ;; diff --git a/templates/README.md b/templates/README.md index ecfefd7..97979d1 100644 --- a/templates/README.md +++ b/templates/README.md @@ -47,7 +47,7 @@ templates/ sh scripts/sync_templates.sh /path/to/project # 追加完整框架到已有 AGENTS.md -sh scripts/sync_templates.sh --full /path/to/project +sh scripts/sync_templates.sh -full /path/to/project ``` **Windows PowerShell**: @@ -64,7 +64,7 @@ sh scripts/sync_templates.sh --full /path/to/project ```cmd scripts\sync_templates.bat C:\path\to\project -scripts\sync_templates.bat --full C:\path\to\project +scripts\sync_templates.bat -full C:\path\to\project ``` ### 部署行为 @@ -72,8 +72,8 @@ scripts\sync_templates.bat --full C:\path\to\project - **新项目**:创建完整的 AGENTS.md、AGENT_RULES.md、memory-bank/、docs/prompts/ - **已有 AGENTS.md**: - 默认:追加路由链接(``) - - `--full`:追加完整框架(规则优先级 + 路由 + 新会话开始时) -- **其他文件**:如果已存在则跳过(使用 `--force` 覆盖) + - `-full`:追加完整框架(规则优先级 + 路由 + 新会话开始时) +- **其他文件**:如果已存在则跳过(使用 `-force` 覆盖) - **自动创建**:TODO.md 和 CONFIRM.md(如果不存在) - **占位符替换**:自动替换 `{{DATE}}` 为当前日期 @@ -157,11 +157,11 @@ project/ | --------------------------------------- | ----------------------- | -------------- | | `` | 语言规则链接 | sync_standards | | `` | 路由链接(默认追加) | sync_templates | -| `` | 完整框架(--full 追加) | sync_templates | +| `` | 完整框架(-full 追加) | sync_templates | ### ci/、cpp/、python/ -语言和 CI 配置模板。通过 `vendor_playbook --apply-templates` 部署: +语言和 CI 配置模板。通过 `vendor_playbook -apply-templates` 部署: | 目录 | 内容 | 部署位置 | | ----------- | ----------------------------------------- | ---------- | @@ -173,7 +173,7 @@ project/ ```bash # vendor_playbook 时一并部署 -sh scripts/vendor_playbook.sh /path/to/project tsl cpp --apply-templates +sh scripts/vendor_playbook.sh /path/to/project tsl cpp -apply-templates ``` ## 与 playbook 其他部分的关系 diff --git a/tests/README.md b/tests/README.md index 2284263..913b50f 100644 --- a/tests/README.md +++ b/tests/README.md @@ -102,10 +102,10 @@ sh check_doc_links.sh - **占位符替换**: - `{{PROJECT_NAME}}` 与 `{{DATE}}` - **目录覆盖策略**: - - 无 `--force` 时不覆盖已有目录 - - `--force` 时覆盖并备份 + - 无 `-force` 时不覆盖已有目录 + - `-force` 时覆盖并备份 - **AGENTS.md 更新**: - - `--full` 更新 framework 区块 + - `-full` 更新 framework 区块 #### test_vendor_playbook.bats diff --git a/tests/scripts/test_sync_templates.bats b/tests/scripts/test_sync_templates.bats index a50b47d..41189d7 100644 --- a/tests/scripts/test_sync_templates.bats +++ b/tests/scripts/test_sync_templates.bats @@ -23,7 +23,7 @@ teardown() { } @test "sync_templates.sh - 基础同步与占位符替换" { - sh "$SCRIPT_PATH" --project-name "DemoProject" --date "2026-02-03" "$TARGET_DIR" + sh "$SCRIPT_PATH" -project-name "DemoProject" -date "2026-02-03" "$TARGET_DIR" [ -d "$TARGET_DIR/memory-bank" ] [ -f "$TARGET_DIR/memory-bank/project-brief.md" ] @@ -39,7 +39,7 @@ teardown() { [ -z "$(find "$TARGET_DIR" -name '*.template.md' -print -quit)" ] } -@test "sync_templates.sh - 已存在目录不覆盖 (无 --force)" { +@test "sync_templates.sh - 已存在目录不覆盖 (无 -force)" { mkdir -p "$TARGET_DIR/memory-bank" mkdir -p "$TARGET_DIR/docs/prompts" echo "keep" > "$TARGET_DIR/memory-bank/keep.md" @@ -53,11 +53,11 @@ teardown() { [ ! -f "$TARGET_DIR/docs/prompts/README.md" ] } -@test "sync_templates.sh - --force 覆盖并备份" { +@test "sync_templates.sh - -force 覆盖并备份" { mkdir -p "$TARGET_DIR/memory-bank" echo "marker" > "$TARGET_DIR/memory-bank/marker.txt" - sh "$SCRIPT_PATH" --force "$TARGET_DIR" + sh "$SCRIPT_PATH" -force "$TARGET_DIR" [ -f "$TARGET_DIR/memory-bank/project-brief.md" ] [ ! -f "$TARGET_DIR/memory-bank/marker.txt" ] @@ -67,7 +67,7 @@ teardown() { [ -f "$backup_dir/marker.txt" ] } -@test "sync_templates.sh - --full 更新 framework 区块" { +@test "sync_templates.sh - -full 更新 framework 区块" { cat > "$TARGET_DIR/AGENTS.md" << 'EOF' # Agent Instructions @@ -78,7 +78,7 @@ OLD_FRAMEWORK Footer EOF - sh "$SCRIPT_PATH" --full "$TARGET_DIR" + sh "$SCRIPT_PATH" -full "$TARGET_DIR" ! grep -q "OLD_FRAMEWORK" "$TARGET_DIR/AGENTS.md" grep -q "" "$TARGET_DIR/AGENTS.md" diff --git a/tests/scripts/test_vendor_playbook.bats b/tests/scripts/test_vendor_playbook.bats index 3d34c45..eb3d459 100644 --- a/tests/scripts/test_vendor_playbook.bats +++ b/tests/scripts/test_vendor_playbook.bats @@ -176,10 +176,10 @@ teardown() { [ -d "docs/standards/playbook/templates/ci" ] } -@test "vendor_playbook.sh - --apply-templates 应用模板到项目根目录" { +@test "vendor_playbook.sh - -apply-templates 应用模板到项目根目录" { cd "$TARGET_DIR" - sh "$SCRIPT_PATH" "$TARGET_DIR" cpp --apply-templates + sh "$SCRIPT_PATH" "$TARGET_DIR" cpp -apply-templates if [ -f "$PLAYBOOK_ROOT/templates/cpp/.clang-format" ]; then [ -f ".clang-format" ]