feat(tui): 配置编辑器循环 + 挂进 Edit-Config(第二轮第三块·完成)
装配:Get-BakNRetConfigSetting(读)→ 菜单选设置 → Read-BakNRetLine(输入新值)→ Set-BakNRetConfigSetting(只改那一行)→ Save-BakNRetConfigFile(校验通过才原子替换 + 时间戳备份)。 输入行**从空开始**、当前值只作提示:预填当前值看着贴心,实际等于逼用户先删一遍(对 'Backups' 这种带引号的原文尤其别扭)。 校验用 Import-PowerShellDataFile:这份配置里没有动态表达式,能被它读回来是个**强校验** —— 比"语法能不能过"更强,它还能抓出"值是合法语法、但结构不对"。它只接受文件路径,所以先把候选文本写到临时文件再读。 Edit-Config 的 -Target Settings 与菜单里的"设置"都挂上了同一个编辑器;-Target Catalog 仍明确报"还没做(第三轮)"。 判据 9 条:改一个值后只动一行、注释行数不变、新值落盘、留下时间戳备份且备份里是原文;取消时不写盘也不产生备份。 验收:test.ps1 9/9 全绿(5.1 与 7)。
This commit is contained in:
1 parent
92bbc995c4
commit
4aa44e8965
5 files changed
+143
-2
No files matched your search
+22
-2
@@ -56,8 +56,18 @@ if ($Target -eq 'List') {
|
||||
exit (Invoke-BakNRetListEditorEntry -Path $ListPath -Script $InputScript)
|
||||
}
|
||||
|
||||
if ($Target -eq 'Settings') {
|
||||
$configPath = Join-Path $PSScriptRoot 'BackupConfig.psd1'
|
||||
$driver = New-BakNRetInputDriver -Script $InputScript -NonInteractive:$([bool]$InputScript)
|
||||
$saved = Invoke-BakNRetConfigEditor -Path $configPath -Driver $driver
|
||||
if ($saved.Saved) { Write-Host ("已保存:{0}" -f $configPath) -ForegroundColor Green; Write-Host ("原文件备份:{0}" -f $saved.BackupPath) -ForegroundColor DarkGray; exit 0 }
|
||||
if ($saved.Error) { Write-Host $saved.Error -ForegroundColor Yellow; exit 1 }
|
||||
Write-Host '没有改动。' -ForegroundColor DarkGray
|
||||
exit 0
|
||||
}
|
||||
|
||||
if ($Target) {
|
||||
Write-Host ("{0} 的编辑器还没做:清单已完成;设置与名录分别是第二轮与第三轮的工作。" -f $Target) -ForegroundColor Yellow
|
||||
Write-Host ("{0} 的编辑器还没做:清单与设置已完成;名录是第三轮的工作。" -f $Target) -ForegroundColor Yellow
|
||||
exit 1
|
||||
}
|
||||
|
||||
@@ -82,5 +92,15 @@ if ($picked.Chosen.Key -eq 'List') {
|
||||
exit (Invoke-BakNRetListEditorEntry -Path $ListPath -Script $InputScript)
|
||||
}
|
||||
|
||||
Write-Host ("{0} 的编辑器还没做。" -f $picked.Chosen.Key) -ForegroundColor Yellow
|
||||
if ($picked.Chosen.Key -eq 'Settings') {
|
||||
$configPath = Join-Path $PSScriptRoot 'BackupConfig.psd1'
|
||||
$driver2 = New-BakNRetInputDriver -Script $InputScript -NonInteractive:$([bool]$InputScript)
|
||||
$saved2 = Invoke-BakNRetConfigEditor -Path $configPath -Driver $driver2
|
||||
if ($saved2.Saved) { Write-Host ("已保存:{0}" -f $configPath) -ForegroundColor Green; exit 0 }
|
||||
if ($saved2.Error) { Write-Host $saved2.Error -ForegroundColor Yellow; exit 1 }
|
||||
Write-Host '没有改动。' -ForegroundColor DarkGray
|
||||
exit 0
|
||||
}
|
||||
|
||||
Write-Host ("{0} 的编辑器还没做(名录是第三轮的工作)。" -f $picked.Chosen.Key) -ForegroundColor Yellow
|
||||
exit 1
|
||||
Reference in new issue
Block a user