浏览代码

fix dot.ps1 and park.ps1 - simulate and verbose tested only

Daniel Sheffield 4 周之前
父节点
当前提交
14a454b68c
共有 2 个文件被更改,包括 19 次插入15 次删除
  1. 10 0
      dot.ps1
  2. 9 15
      park.ps1

+ 10 - 0
dot.ps1

@@ -7,6 +7,16 @@ param (
 
 $ErrorActionPreference = "Stop"
 
+if ($env:DEBUG) {
+    $stow = "./park.ps1"
+    $stowArgs = @{
+        Simulate = $true
+        Verbose  = $true
+    }
+} else {
+    $stow = "./park.ps1"
+    $stowArgs = @{}
+}
 
 $stow = "Write-Output" # For debugging
 #$stow = "./park.ps1"

+ 9 - 15
park.ps1

@@ -13,27 +13,27 @@
 #      * --stow
 #      * --delete
 #      * --restow
-#      * --verbose
+#      * --verbose (bool not int!)
 #      * --simulate
 #   * No tree folding by default (regardless of --nofolding option)
 #
 
+[CmdletBinding()]
 param(
-    [Parameter(Mandatory = $true)][string]$Source,
-    [Parameter(Mandatory = $true)][string]$Target,
-    [string]$Dir,
+    [Parameter(Mandatory = $true)][string]$Dir,
+    [Parameter(Mandatory = $true)][string]$Package,
+    [string]$Target,
     [string]$Ignore,
     [string]$Defer,
     [string]$Override,
     [switch]$Restow,
     [switch]$Delete,
-    [int]$Verbose = 0,
     [switch]$Simulate,
     [switch]$NoFolding,
     [switch]$Adopt
 )
 
-$SourcePath = (Resolve-Path $Source).Path
+$SourcePath = (Resolve-Path $Dir).Path
 $SourceRoot = [System.IO.Path]::GetFullPath($SourcePath)
 $TargetRoot = [System.IO.Path]::GetFullPath($Target)
 
@@ -43,18 +43,12 @@ function Is-Under($child, $parent) {
     return $child.StartsWith($parent, [System.StringComparison]::OrdinalIgnoreCase)
 }
 
-function Write-Log($msg) {
-    if ($Verbose -ge 2) {
-        Write-Host $msg
-    }
-}
-
 if ($Delete -or $Restow) {
     Get-ChildItem -Path $TargetRoot -Recurse -Force | ForEach-Object {
         if ($_.LinkType -eq 'SymbolicLink') {
             $linkTarget = (Get-Item $_.FullName -Force).Target
             if ($linkTarget -and (Is-Under $linkTarget $SourceRoot)) {
-                Write-Log "Unlinking: $($_.FullName) -> $linkTarget"
+                Write-Verbose "Unlinking: $($_.FullName) -> $linkTarget"
                 if (-not $Simulate) {
                     Remove-Item $_.FullName
                 }
@@ -71,13 +65,13 @@ if ($Stow -or $Restow) {
         $targetDir = Split-Path $targetFile
     
         if (-not (Test-Path $targetDir)) {
-            Write-Log "Creating dir: $targetDir"
+            Write-Verbose "Creating dir: $targetDir"
             if (-not $Simulate) {
                 New-Item -ItemType Directory -Path $targetDir -Force | Out-Null
             }
         }
     
-        Write-Log "Linking: $targetFile -> $($_.FullName)"
+        Write-Verbose "Linking: $targetFile -> $($_.FullName)"
         if (-not $Simulate) {
             New-Item -ItemType SymbolicLink -Path $targetFile -Target $_.FullName | Out-Null
         }