Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Invoke-Expression #18

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion PSScriptAnalyzerSettings.psd1
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
@{
ExcludeRules = @(
'PSAvoidUsingInvokeExpression',
'PSAvoidUsingPositionalParameters'
)
}
57 changes: 31 additions & 26 deletions src/Scoop.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ function Get-ScoopApp {
)

begin {
$apps = & scoop list 6>$null
$apps = scoop list 6>$null
}

process {
Expand Down Expand Up @@ -191,21 +191,21 @@ function Install-ScoopApp {
$_name += "@$version"
}

$command = "& scoop install $_name"
$command = @('install', $_name)

if ($PSBoundParameters.ContainsKey('Architecture')) {
$command += " --arch $Architecture"
$command += "--arch $Architecture"
}

if ($Global) { $command += " --global" }
if ($SkipDependencies) { $command += " --independent" }
if ($NoCache) { $command += " --no-cache" }
if ($NoScoopUpdate) { $command += " --no-update-scoop" }
if ($SkipHash) { $command += " --skip" }
if ($Global) { $command += "--global" }
if ($SkipDependencies) { $command += "--independent" }
if ($NoCache) { $command += "--no-cache" }
if ($NoScoopUpdate) { $command += "--no-update-scoop" }
if ($SkipHash) { $command += "--skip" }

Write-Verbose -Message $command
Write-Verbose -Message "scoop $($command -join ' ')"

Invoke-Expression $command 6>&1 |
scoop @command 6>&1 |
ForEach-Object {
if ($_ -match '^ERROR') {
throw ($_ -replace '^ERROR ')
Expand Down Expand Up @@ -272,15 +272,17 @@ function Update-ScoopApp {
process {
foreach ($_name in $Name) {
if ($PSCmdlet.ShouldProcess($_name)) {
$command = "& scoop update $_name"
$command = @('update', $_name)

if ($Global) { $command += " --global" }
if ($SkipDependencies) { $command += " --independent" }
if ($NoCache) { $command += " --no-cache" }
if ($SkipHashCheck) { $command += " --skip" }
if ($Force) { $command += " --force" }
if ($Global) { $command += "--global" }
if ($SkipDependencies) { $command += "--independent" }
if ($NoCache) { $command += "--no-cache" }
if ($SkipHashCheck) { $command += "--skip" }
if ($Force) { $command += "--force" }

Invoke-Expression $command 6>&1 |
Write-Verbose -Message "scoop $($command -join ' ')"

scoop @command 6>&1 |
ForEach-Object {
if ($_ -match '^ERROR') {
throw ($_ -replace '^ERROR ')
Expand Down Expand Up @@ -336,11 +338,14 @@ function Uninstall-ScoopApp {
process {
foreach ($_name in $Name) {
if ($PSCmdlet.ShouldProcess($_name)) {
$command = "& scoop uninstall $_name"
if ($Global) { $command += " --global" }
if ($Purge) { $command += " --purge" }
$command = @('uninstall', $_name)

if ($Global) { $command += "--global" }
if ($Purge) { $command += "--purge" }

Write-Verbose -Message "scoop $($command -join ' ')"

Invoke-Expression $command 6>&1 |
scoop @command 6>&1 |
ForEach-Object {
if ($_ -match '^ERROR') {
throw ($_ -replace '^ERROR ')
Expand Down Expand Up @@ -376,7 +381,7 @@ function Get-ScoopBucket {
)

begin {
$sources = & scoop bucket list 6>$null
$sources = scoop bucket list 6>$null
}

process {
Expand Down Expand Up @@ -426,7 +431,7 @@ function Register-ScoopBucket {
[Parameter(Mandatory,
ParameterSetName = 'Official')]
[ValidateScript({
if ($_ -in (& scoop bucket known)) {
if ($_ -in (scoop bucket known)) {
$true
}
else {
Expand All @@ -453,10 +458,10 @@ function Register-ScoopBucket {

if ($PSCmdlet.ShouldProcess($Name)) {
if ($existing) {
& scoop bucket rm $Name
scoop bucket rm $Name
}

& scoop bucket add $Name $Uri 6>&1 |
scoop bucket add $Name $Uri 6>&1 |
ForEach-Object {
if ($_ -match '^ERROR') {
throw ($_ -replace '^ERROR ')
Expand Down Expand Up @@ -491,7 +496,7 @@ function Unregister-ScoopBucket {
}

if ($PSCmdlet.ShouldProcess($Name)) {
& scoop bucket rm $Name
scoop bucket rm $Name
}

if (Get-ScoopBucket -Name $Name) {
Expand Down
Loading