🔧 chore(scripts): require flag-driven args

This commit is contained in:
csh
2026-01-21 15:19:53 +08:00
parent e4e1d14182
commit c44b9aa4bb
20 changed files with 412 additions and 280 deletions
+41 -13
View File
@@ -6,9 +6,9 @@ rem - Source: <snapshot>\codex\skills\<skill-name>\
rem - Dest: %CODEX_HOME%\skills\<skill-name>\ (default CODEX_HOME=%USERPROFILE%\.codex)
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 -all
rem install_codex_skills.bat -skills style-cleanup,code-review-workflow
rem install_codex_skills.bat -local -all
rem
rem Notes:
rem - Codex loads skills at startup; restart `codex` after installation.
@@ -19,6 +19,8 @@ for %%I in ("%SCRIPT_DIR%..") do set "SRC=%%~fI"
set "SKILLS_SRC_ROOT=%SRC%\\codex\\skills"
set "LOCAL_MODE=0"
set "INSTALL_ALL=0"
set "SKILLS="
:parse_opts
if "%~1"=="" goto opts_done
if /I "%~1"=="-help" goto show_help
@@ -33,6 +35,23 @@ if /I "%~1"=="-l" (
shift
goto parse_opts
)
if /I "%~1"=="-all" (
set "INSTALL_ALL=1"
shift
goto parse_opts
)
if /I "%~1"=="-skills" (
if "%~2"=="" (
echo ERROR: -skills requires a value.
exit /b 1
)
set "SKILLS=%~2"
shift
shift
goto parse_opts
)
echo ERROR: Unknown option: %~1
exit /b 1
goto opts_done
:opts_done
@@ -48,17 +67,23 @@ if not exist "%SKILLS_SRC_ROOT%" (
if not exist "%SKILLS_DST_ROOT%" mkdir "%SKILLS_DST_ROOT%"
set "HAS_ARGS=0"
if not "%~1"=="" set "HAS_ARGS=1"
if "%HAS_ARGS%"=="1" (
for %%S in (%*) do call :InstallOne "%%~S"
goto Done
if "%INSTALL_ALL%"=="1" if not "%SKILLS%"=="" (
echo ERROR: use either -all or -skills, not both.
exit /b 1
)
if "%INSTALL_ALL%"=="0" if "%SKILLS%"=="" (
echo ERROR: -all or -skills is required.
exit /b 1
)
for /d %%D in ("%SKILLS_SRC_ROOT%\\*") do (
set "NAME=%%~nD"
if not "!NAME!"=="" if not "!NAME:~0,1!"=="." call :InstallOne "!NAME!"
if "%INSTALL_ALL%"=="1" (
for /d %%D in ("%SKILLS_SRC_ROOT%\\*") do (
set "NAME=%%~nD"
if not "!NAME!"=="" if not "!NAME:~0,1!"=="." call :InstallOne "!NAME!"
)
) else (
set "SKILLS=%SKILLS:,= %"
for %%S in (%SKILLS%) do call :InstallOne "%%~S"
)
:Done
@@ -68,10 +93,13 @@ exit /b 0
:show_help
echo Usage:
echo install_codex_skills.bat [options] [skill ...]
echo install_codex_skills.bat -all
echo install_codex_skills.bat -skills style-cleanup,code-review-workflow
echo.
echo Options:
echo -local, -l Install to .\\.codex ^(or CODEX_HOME if set^)
echo -skills LIST Comma/space-separated skill names
echo -all Install all skills
echo -help, -h Show this help
echo.
echo Env:
+22 -8
View File
@@ -17,7 +17,8 @@ param(
[switch]$Help,
[switch]$Local,
[Parameter(Mandatory = $false, ValueFromRemainingArguments = $true)]
[switch]$All,
[Parameter(Mandatory = $false)]
[string[]]$Skills
)
@@ -25,16 +26,26 @@ $ErrorActionPreference = "Stop"
if ($Help) {
Write-Host "Usage:"
Write-Host " powershell -File scripts/install_codex_skills.ps1 [options] [skill ...]"
Write-Host " powershell -File scripts/install_codex_skills.ps1 -All"
Write-Host " powershell -File scripts/install_codex_skills.ps1 -Skills style-cleanup,code-review-workflow"
Write-Host ""
Write-Host "Options:"
Write-Host " -Local Install to ./.codex (or CODEX_HOME if set)."
Write-Host " -Skills Comma/space-separated skill names."
Write-Host " -All Install all skills."
Write-Host " -Help Show this help."
Write-Host ""
Write-Host "Env:"
Write-Host " CODEX_HOME Target Codex home (default: ~/.codex)."
exit 0
}
if ($All -and $Skills -and $Skills.Count -gt 0) {
throw "Use either -All or -Skills, not both."
}
if (-not $All -and (-not $Skills -or $Skills.Count -eq 0)) {
throw "Missing -All or -Skills. Use -Help for usage."
}
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$Src = (Resolve-Path (Join-Path $ScriptDir "..")).Path
$SkillsSrcRoot = Join-Path $Src "codex/skills"
@@ -76,16 +87,19 @@ function Install-One([string]$Name) {
Write-Host "Installed: $Name"
}
if ($Skills -and $Skills.Count -gt 0) {
foreach ($name in $Skills) {
if (-not $name) { continue }
Install-One $name
}
} else {
if ($All) {
foreach ($dir in (Get-ChildItem -Path $SkillsSrcRoot -Directory)) {
if ($dir.Name.StartsWith(".")) { continue }
Install-One $dir.Name
}
} else {
foreach ($item in $Skills) {
if (-not $item) { continue }
foreach ($part in $item.Split(@(',', ' '), [System.StringSplitOptions]::RemoveEmptyEntries)) {
if (-not $part) { continue }
Install-One $part
}
}
}
Write-Host "Done. Skills installed to: $SkillsDstRoot"
+47 -10
View File
@@ -6,9 +6,9 @@ set -eu
# - Dest: $CODEX_HOME/skills/<skill-name>/ (default CODEX_HOME=~/.codex)
#
# 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 <cwd>/.codex
# sh scripts/install_codex_skills.sh -all
# sh scripts/install_codex_skills.sh -skills style-cleanup,code-review-workflow
# sh scripts/install_codex_skills.sh -local -all # install to <cwd>/.codex
#
# Notes:
# - Codex loads skills at startup; restart `codex` after installation.
@@ -21,10 +21,14 @@ SKILLS_SRC_ROOT="$SRC/codex/skills"
usage() {
cat <<'EOF' >&2
Usage:
sh scripts/install_codex_skills.sh [options] [skill ...]
sh scripts/install_codex_skills.sh [options]
sh scripts/install_codex_skills.sh -skills style-cleanup,code-review-workflow
sh scripts/install_codex_skills.sh -all
Options:
-local, -l Install to ./.codex (or CODEX_HOME if set).
-skills LIST Comma/space-separated skill names.
-all Install all skills.
-h, -help Show this help.
Env:
@@ -33,12 +37,27 @@ EOF
}
LOCAL_MODE=0
INSTALL_ALL=0
SKILLS=""
while [ $# -gt 0 ]; do
case "$1" in
-local|-l)
LOCAL_MODE=1
shift
;;
-skills)
if [ $# -lt 2 ] || [ -z "${2:-}" ]; then
echo "ERROR: -skills requires a value." >&2
usage
exit 1
fi
SKILLS="$2"
shift 2
;;
-all)
INSTALL_ALL=1
shift
;;
-h|-help)
usage
exit 0
@@ -49,11 +68,24 @@ while [ $# -gt 0 ]; do
exit 1
;;
*)
break
echo "ERROR: positional args are not supported; use -skills/-all." >&2
usage
exit 1
;;
esac
done
if [ "$INSTALL_ALL" -eq 1 ] && [ -n "$SKILLS" ]; then
echo "ERROR: use either -all or -skills, not both." >&2
usage
exit 1
fi
if [ "$INSTALL_ALL" -eq 0 ] && [ -z "$SKILLS" ]; then
echo "ERROR: -all or -skills is required." >&2
usage
exit 1
fi
if [ "$LOCAL_MODE" -eq 1 ]; then
LOCAL_CODEX_HOME="$(pwd -P)/.codex"
CODEX_HOME="${CODEX_HOME:-$LOCAL_CODEX_HOME}"
@@ -87,11 +119,7 @@ install_one() {
echo "Installed: $name"
}
if [ "$#" -gt 0 ]; then
for name in "$@"; do
install_one "$name"
done
else
if [ "$INSTALL_ALL" -eq 1 ]; then
for dir in "$SKILLS_SRC_ROOT"/*; do
[ -d "$dir" ] || continue
name="$(basename -- "$dir")"
@@ -100,6 +128,15 @@ else
esac
install_one "$name"
done
else
old_ifs="${IFS}"
IFS=', '
set -- $SKILLS
IFS="${old_ifs}"
for name in "$@"; do
[ -n "$name" ] || continue
install_one "$name"
done
fi
echo "Done. Skills installed to: $SKILLS_DST_ROOT"
+29 -17
View File
@@ -7,7 +7,7 @@ rem - Updates <project-root>\.gitattributes (append missing rules by default)
rem Existing targets are backed up before overwrite.
rem
rem Multi rulesets:
rem sync_standards.bat tsl cpp
rem sync_standards.bat -langs tsl,cpp
rem Notes:
rem - When syncing multiple rulesets, .gitattributes is synced only once (first ruleset).
@@ -35,14 +35,13 @@ 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 sync_standards.bat -langs tsl,cpp
echo.
echo Options:
echo -langs Comma/space-separated list of languages ^(required^).
echo -h, -help Show this help.
echo.
echo Env:
@@ -51,21 +50,34 @@ echo AGENTS_NS Single ruleset name ^(default: tsl^).
echo SYNC_GITATTR_MODE append^|overwrite^|block^|skip ^(default: append^).
exit /b 0
:after_help
set "LANG_LIST="
:parse_args
if "%~1"=="" goto args_done
if /I "%~1"=="-h" goto show_help
if /I "%~1"=="-help" goto show_help
if /I "%~1"=="-langs" (
if "%~2"=="" goto missing_langs
set "LANG_LIST=%~2"
shift /1
shift /1
goto parse_args
)
echo ERROR: Unknown option: %~1
exit /b 1
:missing_langs
echo ERROR: -langs requires a value.
exit /b 1
:args_done
if not "%LANG_LIST%"=="" set "LANG_LIST=%LANG_LIST:,= %"
rem Multi rulesets: only on outer invocation.
if "%SYNC_STANDARDS_INNER%"=="" (
set "LANG_LIST="
if not "%~1"=="" set "LANG_LIST=%*"
if "%LANG_LIST%"=="" (
if "%AGENTS_NS%"=="" (
if exist "%ROOT%\.agents" (
for /d %%D in ("%ROOT%\.agents\*") do (
set "CAND=%%~nxD"
if exist "%AGENTS_SRC_ROOT%\!CAND!\" (
if defined LANG_LIST (set "LANG_LIST=!LANG_LIST! !CAND!") else set "LANG_LIST=!CAND!"
)
)
)
echo ERROR: -langs is required.
exit /b 1
)
)
if not "%LANG_LIST%"=="" (
@@ -77,12 +89,12 @@ if "%SYNC_STANDARDS_INNER%"=="" (
set "SYNC_STANDARDS_INNER=1"
set "AGENTS_NS=%%~L"
set "SYNC_GITATTR_MODE=!SYNC_FIRST!"
call "%~f0"
call "%~f0" -langs %%~L
) else (
set "SYNC_STANDARDS_INNER=1"
set "AGENTS_NS=%%~L"
set "SYNC_GITATTR_MODE=skip"
call "%~f0"
call "%~f0" -langs %%~L
)
)
exit /b 0
+3 -10
View File
@@ -19,11 +19,10 @@ $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 <list> Comma/space-separated list or array."
Write-Host " -Langs <list> Comma/space-separated list or array (required)."
Write-Host " -Help Show this help."
Write-Host ""
Write-Host "Env:"
@@ -51,15 +50,9 @@ if (-not (Test-Path $AgentsSrcRoot)) {
$timestamp = Get-Date -Format "yyyyMMddHHmmss"
# Auto-detect languages from existing .agents when no args are provided.
# Require explicit -Langs on outer invocation unless AGENTS_NS is provided.
if (-not $env:SYNC_STANDARDS_INNER -and (-not $Langs -or $Langs.Count -eq 0) -and -not $env:AGENTS_NS) {
$agentsRoot = Join-Path $Root ".agents"
if (Test-Path $agentsRoot) {
$autoLangs = @(Get-ChildItem -Path $agentsRoot -Directory | ForEach-Object { $_.Name } | Where-Object { Test-Path (Join-Path $AgentsSrcRoot $_) })
if ($autoLangs.Count -gt 0) {
$Langs = $autoLangs
}
}
throw "Missing -Langs. Use -Help for usage."
}
# Multi rulesets: only on the outer invocation.
+33 -28
View File
@@ -7,7 +7,6 @@ set -eu
# Existing targets are backed up before overwrite.
#
# Multi rulesets:
# sh .../sync_standards.sh tsl cpp
# sh .../sync_standards.sh -langs tsl,cpp
# Notes:
# - When syncing multiple rulesets, .gitattributes is synced only once (first ruleset).
@@ -24,12 +23,11 @@ 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
sh scripts/sync_standards.sh -langs tsl,cpp
Options:
-langs L1,L2 Comma/space-separated list of languages.
-langs L1,L2 Comma/space-separated list of languages (required).
-h, -help Show this help.
Env:
@@ -44,6 +42,31 @@ if [ "${1:-}" = "-h" ] || [ "${1:-}" = "-help" ]; then
exit 0
fi
langs=""
while [ $# -gt 0 ]; do
case "$1" in
-langs)
if [ $# -lt 2 ] || [ -z "${2:-}" ]; then
echo "ERROR: -langs requires a value." >&2
usage
exit 1
fi
langs="$2"
shift 2
;;
-*)
echo "ERROR: Unknown option: $1" >&2
usage
exit 1
;;
*)
echo "ERROR: positional args are not supported; use -langs." >&2
usage
exit 1
;;
esac
done
AGENTS_SRC_ROOT="$SRC/rulesets"
GITATTR_SRC="$SRC/.gitattributes"
@@ -63,28 +86,10 @@ fi
# Parse multi rulesets only on the outer invocation.
if [ "${SYNC_STANDARDS_INNER:-}" != "1" ]; then
langs=""
if [ "${1:-}" = "-langs" ]; then
langs="${2:-}"
shift 2
fi
if [ -z "${langs:-}" ] && [ "$#" -gt 0 ]; then
langs="$*"
fi
if [ -z "${langs:-}" ] && [ "$#" -eq 0 ] && [ -z "${AGENTS_NS:-}" ]; then
auto_langs=""
if [ -d "$ROOT/.agents" ]; then
for dir in "$ROOT/.agents"/*; do
[ -d "$dir" ] || continue
ns="$(basename "$dir")"
if [ -d "$AGENTS_SRC_ROOT/$ns" ]; then
auto_langs="${auto_langs:+$auto_langs }$ns"
fi
done
fi
if [ -n "$auto_langs" ]; then
langs="$auto_langs"
fi
if [ -z "${langs:-}" ] && [ -z "${AGENTS_NS:-}" ]; then
echo "ERROR: -langs is required." >&2
usage
exit 1
fi
if [ -n "${langs:-}" ]; then
sync_mode_first="${SYNC_GITATTR_MODE:-append}"
@@ -99,9 +104,9 @@ if [ "${SYNC_STANDARDS_INNER:-}" != "1" ]; then
[ -n "$ns" ] || continue
if [ "$first" -eq 1 ]; then
first=0
SYNC_STANDARDS_INNER=1 AGENTS_NS="$ns" SYNC_GITATTR_MODE="$sync_mode_first" sh "$0"
SYNC_STANDARDS_INNER=1 AGENTS_NS="$ns" SYNC_GITATTR_MODE="$sync_mode_first" sh "$0" -langs "$ns"
else
SYNC_STANDARDS_INNER=1 AGENTS_NS="$ns" SYNC_GITATTR_MODE=skip sh "$0"
SYNC_STANDARDS_INNER=1 AGENTS_NS="$ns" SYNC_GITATTR_MODE=skip sh "$0" -langs "$ns"
fi
done
exit 0
+18 -7
View File
@@ -10,9 +10,9 @@ rem Existing targets are NOT overwritten (skip if exists).
rem
rem Usage:
rem sync_templates.bat # sync to current git root
rem sync_templates.bat <project-root> # 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 -project-root <path> # sync to specified project
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"
@@ -33,17 +33,28 @@ if /I "%~1"=="-full" (
shift
goto parse_args
)
if /I "%~1"=="-project-root" (
if "%~2"=="" (
echo ERROR: -project-root requires a path.
exit /b 1
)
set "PROJECT_ROOT=%~2"
shift
shift
goto parse_args
)
if /I "%~1"=="-h" goto show_help
if /I "%~1"=="-help" goto show_help
set "PROJECT_ROOT=%~1"
shift
goto parse_args
echo ERROR: positional args are not supported. Use -project-root.
exit /b 1
:show_help
echo Usage:
echo sync_templates.bat [options] [project-root]
echo sync_templates.bat [options]
echo sync_templates.bat -project-root ^<path^>
echo.
echo Options:
echo -project-root PATH Target project root ^(default: git root^)
echo -force Overwrite existing files
echo -full Append full framework (规则优先级 + 新会话开始时) to existing AGENTS.md
echo -h, -help Show this help
+4 -2
View File
@@ -10,7 +10,7 @@ param(
[Alias('h', 'help', '?')]
[switch]$Help,
[Parameter(Mandatory = $false, Position = 0)]
[Parameter(Mandatory = $false)]
[string]$ProjectRoot,
[Parameter(Mandatory = $false)]
@@ -33,9 +33,11 @@ $ErrorActionPreference = "Stop"
if ($Help) {
Write-Host "Usage:"
Write-Host " powershell -File scripts/sync_templates.ps1 [options] [project-root]"
Write-Host " powershell -File scripts/sync_templates.ps1 [options]"
Write-Host " powershell -File scripts/sync_templates.ps1 -ProjectRoot C:\\path\\to\\project"
Write-Host ""
Write-Host "Options:"
Write-Host " -ProjectRoot PATH Target project root (default: git root)."
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."
+27 -8
View File
@@ -10,10 +10,11 @@ set -eu
#
# Usage:
# sh scripts/sync_templates.sh # sync to current git root
# sh scripts/sync_templates.sh <project-root> # sync to specified project
# sh scripts/sync_templates.sh -project-name "MyProject" -date "2026-01-20"
# sh scripts/sync_templates.sh -project-root /path/to/project
# sh scripts/sync_templates.sh -project-root /path/to/project -project-name "MyProject" -date "2026-01-20"
#
# Options:
# -project-root PATH Target project root (default: git root)
# -project-name NAME Replace {{PROJECT_NAME}} placeholder
# -date DATE Replace {{DATE}} placeholder (default: today)
# -no-backup Skip backup of existing files
@@ -34,11 +35,27 @@ PROJECT_ROOT=""
# Parse arguments
while [ $# -gt 0 ]; do
case "$1" in
-project-root)
if [ $# -lt 2 ] || [ -z "${2:-}" ]; then
echo "ERROR: -project-root requires a path." >&2
exit 1
fi
PROJECT_ROOT="$2"
shift 2
;;
-project-name)
if [ $# -lt 2 ] || [ -z "${2:-}" ]; then
echo "ERROR: -project-name requires a value." >&2
exit 1
fi
PROJECT_NAME="$2"
shift 2
;;
-date)
if [ $# -lt 2 ] || [ -z "${2:-}" ]; then
echo "ERROR: -date requires a value." >&2
exit 1
fi
SYNC_DATE="$2"
shift 2
;;
@@ -57,9 +74,11 @@ while [ $# -gt 0 ]; do
-h|-help)
cat <<'EOF'
Usage:
sh scripts/sync_templates.sh [options] [project-root]
sh scripts/sync_templates.sh [options]
sh scripts/sync_templates.sh -project-root /path/to/project
Options:
-project-root PATH Target project root (default: git root)
-project-name NAME Replace {{PROJECT_NAME}} placeholder
-date DATE Replace {{DATE}} placeholder (default: today)
-no-backup Skip backup of existing files
@@ -69,8 +88,8 @@ Options:
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 -project-root /path/to/project
sh scripts/sync_templates.sh -project-root /path/to/project -full
EOF
exit 0
;;
@@ -79,8 +98,8 @@ EOF
exit 1
;;
*)
PROJECT_ROOT="$1"
shift
echo "ERROR: positional args are not supported; use -project-root." >&2
exit 1
;;
esac
done
@@ -347,4 +366,4 @@ echo ""
echo "Next steps:"
echo " 1. Edit memory-bank/*.md to fill in project-specific content"
echo " 2. Replace remaining {{PLACEHOLDER}} values"
echo " 3. Run sync_standards.sh to sync .agents/ rules"
echo " 3. Run sync_standards.sh -langs <lang> to sync .agents/ rules"
+34 -21
View File
@@ -6,12 +6,12 @@ rem then run sync_standards to materialize .agents\<lang>\ and .gitattributes in
rem the target project root.
rem
rem Usage:
rem scripts\vendor_playbook.bat <project-root> (default: tsl)
rem scripts\vendor_playbook.bat <project-root> tsl cpp
rem scripts\vendor_playbook.bat <project-root> -langs tsl,cpp
rem scripts\vendor_playbook.bat <project-root> tsl cpp -apply-templates
rem scripts\vendor_playbook.bat -project-root <path> (default: tsl)
rem scripts\vendor_playbook.bat -project-root <path> -langs tsl,cpp
rem scripts\vendor_playbook.bat -project-root <path> -langs tsl,cpp -apply-templates
rem
rem Options:
rem -project-root Target project root (required)
rem -apply-templates Apply CI/lang templates to project root (skip if exists)
rem
rem Notes:
@@ -26,16 +26,28 @@ if "%~1"=="" goto Usage
if "%~1"=="-h" goto Usage
if "%~1"=="-help" goto Usage
set "DEST_ROOT=%~1"
shift /1
set "DEST_ROOT="
set "LANGS="
set "APPLY_TEMPLATES=0"
rem Parse arguments
:parse_args
if "%~1"=="" goto args_done
if "%~1"=="-project-root" (
if "%~2"=="" (
echo ERROR: -project-root requires a path.
exit /b 1
)
set "DEST_ROOT=%~2"
shift /1
shift /1
goto parse_args
)
if "%~1"=="-langs" (
if "%~2"=="" (
echo ERROR: -langs requires a value.
exit /b 1
)
set "LANGS=%~2"
shift /1
shift /1
@@ -46,15 +58,15 @@ if "%~1"=="-apply-templates" (
shift /1
goto parse_args
)
if "%LANGS%"=="" (
set "LANGS=%~1"
) else (
set "LANGS=%LANGS% %~1"
)
shift /1
goto parse_args
echo ERROR: positional args are not supported. Use -project-root/-langs.
exit /b 1
:args_done
if "%DEST_ROOT%"=="" (
echo ERROR: -project-root is required.
exit /b 1
)
if "%LANGS%"=="" set "LANGS=tsl"
set "LANGS=%LANGS:,= %"
@@ -182,7 +194,7 @@ set "README=%DEST_PREFIX%\\README.md"
>> "%README%" echo 在目标项目根目录执行(多语言一次同步):
>> "%README%" echo.
>> "%README%" echo ```sh
>> "%README%" echo sh docs/standards/playbook/scripts/sync_standards.sh %LANGS_CSV%
>> "%README%" echo sh docs/standards/playbook/scripts/sync_standards.sh -langs %LANGS_CSV%
>> "%README%" echo ```
>> "%README%" echo.
>> "%README%" echo 查看规范入口:
@@ -195,7 +207,7 @@ set "README=%DEST_PREFIX%\\README.md"
>> "%README%" echo 安装到本机(需要先在 `~/.codex/config.toml` 启用 skills;见 `docs/standards/playbook/SKILLS.md`):
>> "%README%" echo.
>> "%README%" echo ```sh
>> "%README%" echo sh docs/standards/playbook/scripts/install_codex_skills.sh
>> "%README%" echo sh docs/standards/playbook/scripts/install_codex_skills.sh -all
>> "%README%" echo ```
>> "%README%" echo.
>> "%README%" echo ## CI templates(可选)
@@ -240,7 +252,7 @@ if not exist "%PROJECT_AGENTS_INDEX%" (
set "OLD_SYNC_ROOT=%SYNC_ROOT%"
set "SYNC_ROOT=%DEST_ROOT_ABS%"
pushd "%DEST_ROOT_ABS%"
call "%DEST_PREFIX%\\scripts\\sync_standards.bat" %LANGS%
call "%DEST_PREFIX%\\scripts\\sync_standards.bat" -langs %LANGS_CSV%
popd
set "SYNC_ROOT=%OLD_SYNC_ROOT%"
@@ -356,11 +368,12 @@ exit /b 0
:Usage
echo Usage:
echo scripts\vendor_playbook.bat ^<project-root^> ^(default: tsl^)
echo scripts\vendor_playbook.bat ^<project-root^> tsl cpp
echo scripts\vendor_playbook.bat ^<project-root^> -langs tsl,cpp
echo scripts\vendor_playbook.bat ^<project-root^> tsl cpp -apply-templates
echo scripts\vendor_playbook.bat -project-root ^<path^> ^(default: tsl^)
echo scripts\vendor_playbook.bat -project-root ^<path^> -langs tsl,cpp
echo scripts\vendor_playbook.bat -project-root ^<path^> -langs tsl,cpp -apply-templates
echo.
echo Options:
echo -project-root Target project root ^(required^)
echo -langs Comma/space-separated list of languages ^(default: tsl^)
echo -apply-templates Apply CI/lang templates to project root ^(skip if exists^)
exit /b 1
+14 -14
View File
@@ -3,9 +3,9 @@
# the target project root.
#
# Usage:
# powershell -File scripts/vendor_playbook.ps1 -DestRoot <project-root>
# powershell -File scripts/vendor_playbook.ps1 -DestRoot <project-root> -Langs tsl,cpp
# powershell -File scripts/vendor_playbook.ps1 -DestRoot <project-root> -Langs @("tsl","cpp") -ApplyTemplates
# powershell -File scripts/vendor_playbook.ps1 -ProjectRoot <path>
# powershell -File scripts/vendor_playbook.ps1 -ProjectRoot <path> -Langs tsl,cpp
# powershell -File scripts/vendor_playbook.ps1 -ProjectRoot <path> -Langs @("tsl","cpp") -ApplyTemplates
#
# Options:
# -ApplyTemplates Apply CI/lang templates to project root (skip if exists)
@@ -22,7 +22,7 @@ param(
[switch]$Help,
[Parameter(Mandatory = $false)]
[string]$DestRoot,
[string]$ProjectRoot,
[Parameter(Mandatory = $false)]
[string[]]$Langs,
@@ -35,20 +35,20 @@ $ErrorActionPreference = "Stop"
if ($Help) {
Write-Host "Usage:"
Write-Host " powershell -File scripts/vendor_playbook.ps1 -DestRoot <project-root>"
Write-Host " powershell -File scripts/vendor_playbook.ps1 -DestRoot <project-root> -Langs tsl,cpp"
Write-Host " powershell -File scripts/vendor_playbook.ps1 -DestRoot <project-root> -Langs @('tsl','cpp') -ApplyTemplates"
Write-Host " powershell -File scripts/vendor_playbook.ps1 -ProjectRoot <path>"
Write-Host " powershell -File scripts/vendor_playbook.ps1 -ProjectRoot <path> -Langs tsl,cpp"
Write-Host " powershell -File scripts/vendor_playbook.ps1 -ProjectRoot <path> -Langs @('tsl','cpp') -ApplyTemplates"
Write-Host ""
Write-Host "Options:"
Write-Host " -DestRoot Target project root."
Write-Host " -ProjectRoot Target project root (required)."
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."
if (-not $ProjectRoot) {
throw "ProjectRoot is required. Use -Help for usage."
}
function Normalize-Langs([string[]]$InputLangs) {
@@ -77,8 +77,8 @@ foreach ($lang in $Langs) {
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$Src = (Resolve-Path (Join-Path $ScriptDir "..")).Path
New-Item -ItemType Directory -Path $DestRoot -Force | Out-Null
$DestRootAbs = (Resolve-Path $DestRoot).Path
New-Item -ItemType Directory -Path $ProjectRoot -Force | Out-Null
$DestRootAbs = (Resolve-Path $ProjectRoot).Path
$StandardsDir = Join-Path $DestRootAbs "docs/standards"
$DestPrefix = Join-Path $StandardsDir "playbook"
@@ -207,7 +207,7 @@ if (-not $commit) { $commit = "N/A" }
```sh
sh docs/standards/playbook/scripts/sync_standards.sh $langsCsv
sh docs/standards/playbook/scripts/sync_standards.sh -langs $langsCsv
```
@@ -220,7 +220,7 @@ sh docs/standards/playbook/scripts/sync_standards.sh $langsCsv
`~/.codex/config.toml` skills `docs/standards/playbook/SKILLS.md`
```sh
sh docs/standards/playbook/scripts/install_codex_skills.sh
sh docs/standards/playbook/scripts/install_codex_skills.sh -all
```
## CI templates
+38 -27
View File
@@ -6,12 +6,13 @@ set -eu
# the target project root.
#
# Usage:
# sh scripts/vendor_playbook.sh <project-root> # default: tsl
# sh scripts/vendor_playbook.sh <project-root> tsl cpp
# sh scripts/vendor_playbook.sh <project-root> -langs tsl,cpp
# sh scripts/vendor_playbook.sh <project-root> tsl cpp -apply-templates
# sh scripts/vendor_playbook.sh -project-root <path> # default: tsl
# sh scripts/vendor_playbook.sh -project-root <path> -langs tsl,cpp
# sh scripts/vendor_playbook.sh -project-root <path> -langs tsl,cpp -apply-templates
#
# Options:
# -project-root PATH Target project root (required)
# -langs L1,L2 Comma/space-separated list of languages (default: tsl)
# -apply-templates Apply CI/lang templates to project root (skip if exists)
#
# Notes:
@@ -26,39 +27,47 @@ SRC="$(CDPATH= cd -- "$SCRIPT_DIR/.." && pwd -P)"
usage() {
cat <<'EOF' >&2
Usage:
sh scripts/vendor_playbook.sh <project-root> # default: tsl
sh scripts/vendor_playbook.sh <project-root> tsl cpp
sh scripts/vendor_playbook.sh <project-root> -langs tsl,cpp
sh scripts/vendor_playbook.sh <project-root> tsl cpp -apply-templates
sh scripts/vendor_playbook.sh -project-root <path> # default: tsl
sh scripts/vendor_playbook.sh -project-root <path> -langs tsl,cpp
sh scripts/vendor_playbook.sh -project-root <path> -langs tsl,cpp -apply-templates
Options:
-project-root PATH Target project root (required)
-langs L1,L2 Comma/space-separated list of languages (default: tsl)
-apply-templates Apply CI/lang templates to project root (skip if exists)
-h, -help Show this help
EOF
}
if [ "$#" -lt 1 ]; then
usage
exit 1
fi
if [ "${1:-}" = "-h" ] || [ "${1:-}" = "-help" ]; then
usage
exit 0
fi
PROJECT_ROOT="$1"
shift
PROJECT_ROOT=""
langs=""
APPLY_TEMPLATES=0
# Parse arguments
while [ $# -gt 0 ]; do
case "$1" in
-project-root)
if [ $# -lt 2 ] || [ -z "${2:-}" ]; then
echo "ERROR: -project-root requires a path." >&2
usage
exit 1
fi
PROJECT_ROOT="$2"
shift 2
;;
-langs)
langs="${2:-}"
shift 2 || true
if [ $# -lt 2 ] || [ -z "${2:-}" ]; then
echo "ERROR: -langs requires a value." >&2
usage
exit 1
fi
langs="$2"
shift 2
;;
-apply-templates)
APPLY_TEMPLATES=1
@@ -69,16 +78,18 @@ while [ $# -gt 0 ]; do
exit 1
;;
*)
if [ -z "$langs" ]; then
langs="$1"
else
langs="$langs $1"
fi
shift
echo "ERROR: positional args are not supported; use -project-root/-langs." >&2
exit 1
;;
esac
done
if [ -z "$PROJECT_ROOT" ]; then
echo "ERROR: -project-root is required." >&2
usage
exit 1
fi
if [ -z "${langs:-}" ]; then
langs="tsl"
fi
@@ -236,7 +247,7 @@ cat >"$DEST_PREFIX/README.md" <<EOF
在目标项目根目录执行(多语言一次同步):
\`\`\`sh
sh docs/standards/playbook/scripts/sync_standards.sh ${langs_csv}
sh docs/standards/playbook/scripts/sync_standards.sh -langs ${langs_csv}
\`\`\`
查看规范入口:
@@ -249,7 +260,7 @@ sh docs/standards/playbook/scripts/sync_standards.sh ${langs_csv}
安装到本机(需要先在 \`~/.codex/config.toml\` 启用 skills;见 \`docs/standards/playbook/SKILLS.md\`):
\`\`\`sh
sh docs/standards/playbook/scripts/install_codex_skills.sh
sh docs/standards/playbook/scripts/install_codex_skills.sh -all
\`\`\`
## CI templates(可选)
@@ -307,7 +318,7 @@ EOF
EOF
fi
SYNC_ROOT="$PROJECT_ROOT_ABS" sh "$DEST_PREFIX/scripts/sync_standards.sh" "$@"
SYNC_ROOT="$PROJECT_ROOT_ABS" sh "$DEST_PREFIX/scripts/sync_standards.sh" -langs "$langs_csv"
# Apply templates to project root if requested
if [ "$APPLY_TEMPLATES" -eq 1 ]; then