Browse Source

only print actions when verbosity > 1

Daniel Sheffield 4 weeks ago
parent
commit
cf9437fc3c
1 changed files with 20 additions and 16 deletions
  1. 20 16
      park.ps1

+ 20 - 16
park.ps1

@@ -4,29 +4,33 @@
 #
 # Park is inspired by GNU Stow.
 #
-# It can't stow your files properly,
-# but it will park them.
+# It can't stow your files properly, but it will park them. Hopefully that is good enough.
 #
-# Hopefully that is good enough.
+# Park is designed to be a "drop-in" replacement to GNU Stow, with the following
+# limitations:
+#   * Only long options are supported
+#   * All options are ignored except:
+#      * --stow
+#      * --delete
+#      * --restow
+#      * --verbose
+#      * --simulate
+#   * No tree folding by default (regardless of --nofolding option)
 #
 
 param(
-    [Parameter(Mandatory = $true)]
-    [string]$Source,
-
-    [Parameter(Mandatory = $true)]
-    [string]$Target,
-
+    [Parameter(Mandatory = $true)][string]$Source,
+    [Parameter(Mandatory = $true)][string]$Target,
     [string]$Dir,
     [string]$Ignore,
     [string]$Defer,
     [string]$Override,
     [switch]$Restow,
     [switch]$Delete,
-    [int]$Verbose = 1
+    [int]$Verbose = 0,
     [switch]$Simulate,
     [switch]$NoFolding,
-    [switch]$Adopt,
+    [switch]$Adopt
 )
 
 $SourcePath = (Resolve-Path $Source).Path
@@ -39,13 +43,13 @@ function Is-Under($child, $parent) {
     return $child.StartsWith($parent, [System.StringComparison]::OrdinalIgnoreCase)
 }
 
-function Write-Log($msg, $level = 1) {
-    if ($Verbose -ge $level) {
+function Write-Log($msg) {
+    if ($Verbose -ge 2) {
         Write-Host $msg
     }
 }
 
-if ($Delete) {
+if ($Delete -or $Restow) {
     Get-ChildItem -Path $TargetRoot -Recurse -Force | ForEach-Object {
         if ($_.LinkType -eq 'SymbolicLink') {
             $linkTarget = (Get-Item $_.FullName -Force).Target
@@ -60,14 +64,14 @@ if ($Delete) {
     return
 }
 
-if ($Stow) {
+if ($Stow -or $Restow) {
     Get-ChildItem -Path $SourceRoot -Recurse -File -Force | ForEach-Object {
         $relativePath = $_.FullName.Substring($SourceRoot.Length).TrimStart('\', '/')
         $targetFile = Join-Path $TargetRoot $relativePath
         $targetDir = Split-Path $targetFile
     
         if (-not (Test-Path $targetDir)) {
-            Write-Log "Creating dir: $targetDir" 2
+            Write-Log "Creating dir: $targetDir"
             if (-not $Simulate) {
                 New-Item -ItemType Directory -Path $targetDir -Force | Out-Null
             }