]> git.ardis.lu - ArdisUtilities/commitdiff
Use advanced function for install script
authorArdis Lu <ardisglu@gmail.com>
Wed, 21 Jun 2023 04:10:08 +0000 (21:10 -0700)
committerArdis Lu <ardisglu@gmail.com>
Wed, 21 Jun 2023 04:10:08 +0000 (21:10 -0700)
Required to use the clean block (interrupt trap)

install.ps1

index 941a2040d0eefa34ee0d49ae1cb1b884c1fbc63c..7fbd6dbeef0323f9c54e770a9f5e006f6a7a78ba 100644 (file)
@@ -1,14 +1,24 @@
-# Create a temporary working folder
-$tempFolder = Join-Path $Env:Temp $(New-Guid)
-New-Item -Type Directory -Path $tempFolder | Out-Null
+function Install-ArdisUtilities {
+  begin {
+    # Create a temporary working folder
+    $tempFolder = Join-Path $Env:Temp $(New-Guid)
+    New-Item -Type Directory -Path $tempFolder | Out-Null
+  }
 
-# Download and extract the repository from GitHub
-$zipFile = Join-Path $tempFolder /ArdisUtilities.zip
-Invoke-WebRequest 'https://github.com/ardislu/ArdisUtilities/archive/refs/heads/main.zip' -OutFile $zipFile
-Expand-Archive $zipFile $tempFolder
+  process {
+    # Download and extract the repository from GitHub
+    $zipFile = Join-Path $tempFolder /ArdisUtilities.zip
+    Invoke-WebRequest 'https://github.com/ardislu/ArdisUtilities/archive/refs/heads/main.zip' -OutFile $zipFile
+    Expand-Archive $zipFile $tempFolder
 
-# Import the module from the extraction
-Import-Module (Join-Path $tempFolder /ArdisUtilities-main/ArdisUtilities)
+    # Import the module from the extraction
+    Import-Module (Join-Path $tempFolder /ArdisUtilities-main/ArdisUtilities)
+  }
 
-# Clean up the temporary folder
-Remove-Item $tempFolder -Force -Recurse
+  clean {
+    # Clean up the temporary folder
+    Remove-Item $tempFolder -Force -Recurse
+  }
+}
+
+Install-ArdisUtilities
This page took 0.043773 seconds and 4 git commands to generate.