Skip to content

Commit

Permalink
2023-11-16 22:39:01
Browse files Browse the repository at this point in the history
  • Loading branch information
uidHUB committed Nov 16, 2023
1 parent 4969f9b commit f6aca5c
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 53 deletions.
1 change: 0 additions & 1 deletion PkgStore.cURL.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
Description = 'PowerShell module for cURL.'
PowerShellVersion = '7.2'
RequiredModules = @('PkgStore.Kernel')
FunctionsToExport = @('Start-cURLDownload')
PrivateData = @{
PSData = @{
Tags = @('pwsh', 'curl')
Expand Down
69 changes: 17 additions & 52 deletions PkgStore.cURL.psm1
Original file line number Diff line number Diff line change
@@ -1,58 +1,23 @@
<#PSScriptInfo
.VERSION 0.1.0
.GUID 02d8b827-f39b-484c-8e8d-f7d6aa8e8915
.AUTHOR Kitsune Solar
.AUTHOREMAIL [email protected]
.COMPANYNAME iHub.TO
.COPYRIGHT 2023 Kitsune Solar. All rights reserved.
.LICENSEURI https://github.com/pkgstore/pwsh-curl/blob/main/LICENSE
.PROJECTURI https://github.com/pkgstore/pwsh-curl
#>

$App = @('curl.exe', 'curl-ca-bundle.crt', 'libcurl-x64.def', 'libcurl-x64.dll')
$AppExe = @{LiteralPath = "${PSScriptRoot}"; Filter = "$($App[0])"; Recurse = $true; File = $true}
$AppExe = ((Get-ChildItem @AppExe) | Select-Object -First 1)
$NL = "$([Environment]::NewLine)"

function Start-cURLDownload() {
<#
.SYNOPSIS
.DESCRIPTION
#>

Param(
[Parameter(Mandatory)][Alias('URL')][string[]]$P_URL
)

# Checking cURL location.
Test-cURL

$P_URL | ForEach-Object {
$Param = @('--location') # If the server reports that the requested page has moved to a different location.
$Param += @('--remote-name') # Write output to a local file named like the remote file we get.
$Param += @("${_}") # Input URL.

& "${AppExe}" $Param
$Aliases = @()
$PrivateFunctions = (Get-ChildItem -Path (Join-Path $PSScriptRoot 'Private') -Include '*.ps1' -File -Recurse)
$PublicFunctions = (Get-ChildItem -Path (Join-Path $PSScriptRoot 'Public') -Include '*.ps1' -File -Recurse)

(@($PrivateFunctions) + @($PublicFunctions)) | ForEach-Object {
try {
Write-Verbose "Loading '$($_.FullName)'."
. $_.FullName
} catch {
Write-Warning $_.Exception.Message
}
}

function Test-cURL {
<#
.SYNOPSIS
.DESCRIPTION
#>

# Getting 'curl.exe' directory.
$Dir = "$($AppExe.DirectoryName)"
@($PublicFunctions) | ForEach-Object {
$Alias = (Get-Alias -Definition $_.BaseName -ErrorAction 'SilentlyContinue')

# Checking the location of files.
$App | ForEach-Object {
if (-not (Test-Data -T 'F' -P "${Dir}\${_}")) {
Write-Msg -T 'W' -A 'Stop' -M ("'${_}' not found!${NL}${NL}" +
"1. Download '${_}' from 'https://curl.se/windows/'.${NL}" +
"2. Extract all the contents of the archive into a directory '${PSScriptRoot}'.")
}
if ($Alias) {
$Aliases += $Alias
Export-ModuleMember -Function $_.BaseName -Alias $Alias
} else {
Export-ModuleMember -Function $_.BaseName
}
}
26 changes: 26 additions & 0 deletions Private/Start-cURL.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
function Start-cURL {
<#
.SYNOPSIS
.DESCRIPTION
#>

Param(
[Alias('AD')][string[]]$AppData = @('curl.exe', 'curl-ca-bundle.crt', 'libcurl-x64.def', 'libcurl-x64.dll')
)

$AppPath = (Split-Path -Path "${PSScriptRoot}" -Parent)
$App = @{LiteralPath = "${AppPath}"; Filter = "$($AppData[0])"; Recurse = $true; File = $true}
$App = ((Get-ChildItem @App) | Select-Object -First 1)
$NL = [Environment]::NewLine

$AppData | ForEach-Object {
if (-not (Test-Data -T 'F' -P "$($App.DirectoryName)\${_}")) {
Write-Msg -T 'W' -A 'Stop' -M ("'${_}' not found!${NL}${NL}" +
"1. Download '${_}' from 'https://curl.se/windows/'.${NL}" +
"2. Extract all the contents of the archive into a directory '${AppPath}'.")
}
}

$App
}
19 changes: 19 additions & 0 deletions Public/Start-cURLDownload.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
function Start-cURLDownload() {
<#
.SYNOPSIS
.DESCRIPTION
#>

Param(
[Parameter(Mandatory)][Alias('URL')][string[]]$P_URL
)

$P_URL | ForEach-Object {
$Param = @('--location') # If the server reports that the requested page has moved to a different location.
$Param += @('--remote-name') # Write output to a local file named like the remote file we get.
$Param += @("${_}") # Input URL.

& $(Start-cURL) $Param
}
}

0 comments on commit f6aca5c

Please sign in to comment.