pets_tools 0.2.0

MusKitty multi-repo source management CLI — one command to clone, build, test, push, and publish 9 independent crate repositories
# env.example.ps1 — 凭据注入脚本模板
# 复制为 env.ps1 后使用。env.ps1 已被 .gitignore 排除。
#
# 用法:dot-source 此脚本
#   . .\env.ps1
#   pets status MusKitty

# ── 1. CRATES_GIT_TOKEN(crate 仓库)──
# 优先从 gh CLI 拿,失败则检查环境变量(手动设置)
if (-not $env:CRATES_GIT_TOKEN) {
    $env:CRATES_GIT_TOKEN = try { gh auth token --hostname github.com 2>$null } catch { $null }
}

# ── 2. MAIN_GIT_TOKEN(主仓库 Ink-dark)──
# 如果你有两个不同的 GitHub 账号/令牌,在此处指定
if (-not $env:MAIN_GIT_TOKEN) {
    # 如果有 Ink-dark 专属 token,改这里:
    # $env:MAIN_GIT_TOKEN = "ghp_xxxxxxxxxxxx"
    # 否则 fallback 到和 crates 一样的 token
    $env:MAIN_GIT_TOKEN = $env:CRATES_GIT_TOKEN
}

# ── 3. CARGO_REGISTRY_TOKEN(crates.io 发布)──
# Cargo 登录后存在 ~/.cargo/credentials.toml
if (-not $env:CARGO_REGISTRY_TOKEN) {
    $creds = "$env:USERPROFILE\.cargo\credentials.toml"
    if (Test-Path $creds) {
        $m = [regex]::Match((Get-Content $creds -Raw), 'token\s*=\s*"([^"]+)"')
        if ($m.Success) { $env:CARGO_REGISTRY_TOKEN = $m.Groups[1].Value }
    }
}

# ── 汇总 ──
Write-Host "[pets] token status:" -ForegroundColor Cyan
@('CRATES_GIT_TOKEN','MAIN_GIT_TOKEN','CARGO_REGISTRY_TOKEN') | ForEach-Object {
    $v = (Get-Item "env:$_" -EA SilentlyContinue).Value
    if ($v) { Write-Host "  ✓ $_" -ForegroundColor Green }
    else    { Write-Host "  ✗ $_ — missing" -ForegroundColor Red }
}