Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
5 changes: 2 additions & 3 deletions lib/buckets.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,8 @@ function add_bucket($name, $repo) {
if (!$repo) { "Unknown bucket '$name'. Try specifying <repo>."; $usage_add; exit 1 }
}

$git = try { Get-Command 'git' -ea stop } catch { $null }
if (!$git) {
abort "Git is required for buckets. Run 'scoop install git'."
if (!(Test-CommandAvailable git)) {
abort "Git is required for buckets. Run 'scoop install git' and try again."
}

$dir = bucketdir $name
Expand Down
9 changes: 8 additions & 1 deletion lib/core.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,13 @@ function file_path($app, $file) {
return $null
}

Function Test-CommandAvailable {
Param (
[String]$Name
)
Return [Boolean](Get-Command $Name -ErrorAction Ignore)
}

function 7zip_path() {
return (file_path '7zip' '7z.exe')
}
Expand Down Expand Up @@ -486,7 +493,7 @@ function ensure_scoop_in_path($global) {
}

function ensure_robocopy_in_path {
if(!(Get-Command robocopy -ea ignore)) {
if(!(Test-CommandAvailable robocopy)) {
shim "C:\Windows\System32\Robocopy.exe" $false
}
}
Expand Down
3 changes: 1 addition & 2 deletions lib/diagnostic.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ function check_windows_defender($global) {
$defender = get-service -name WinDefend -errorAction SilentlyContinue
if($defender -and $defender.status) {
if($defender.status -eq [system.serviceprocess.servicecontrollerstatus]::running) {
$hasGetMpPreference = Get-Command get-mppreference -errorAction SilentlyContinue
if($hasGetMpPreference) {
if (Test-CommandAvailable Get-MpPreference) {
$installPath = $scoopdir;
if($global) { $installPath = $globaldir; }

Expand Down
7 changes: 1 addition & 6 deletions lib/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ function check_hash($file, $hash, $app_name) {

function compute_hash($file, $algname) {
try {
if([bool](Get-Command -Name Get-FileHash -ErrorAction SilentlyContinue) -eq $true) {
if(Test-CommandAvailable Get-FileHash) {
return (Get-FileHash -Path $file -Algorithm $algname).Hash.ToLower()
} else {
$fs = [system.io.file]::openread($file)
Expand All @@ -683,11 +683,6 @@ function compute_hash($file, $algname) {
return ''
}

function cmd_available($cmd) {
try { Get-Command $cmd -ea stop | out-null } catch { return $false }
$true
}

# for dealing with installers
function args($config, $dir, $global) {
if($config) { return $config | ForEach-Object { (format $_ @{'dir'=$dir;'global'=$global}) } }
Expand Down
3 changes: 1 addition & 2 deletions libexec/scoop-update.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ if (!$branch) {

function update_scoop() {
# check for git
$git = try { Get-Command git -ea stop } catch { $null }
if(!$git) { abort "Scoop uses Git to update itself. Run 'scoop install git' and try again." }
if(!(Test-CommandAvailable git)) { abort "Scoop uses Git to update itself. Run 'scoop install git' and try again." }

write-host "Updating Scoop..."
$last_update = $(last_scoop_update)
Expand Down
2 changes: 1 addition & 1 deletion libexec/scoop-which.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ if(!$command) { 'ERROR: <command> missing'; my_usage; exit 1 }
try {
$gcm = Get-Command "$command" -ea stop
} catch {
[console]::error.writeline("'$command' not found"); exit 3
abort "'$command' not found" 3
}

$path = "$($gcm.path)"
Expand Down
14 changes: 5 additions & 9 deletions test/Scoop-Core.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,6 @@ Describe "get_app_name_from_ps1_shim" -Tag 'Scoop' {
get_app_name_from_ps1_shim "$shim_path" | should -be "mockapp"
}

It "returns app name if file exists and is a shim to an app cerca August 2018" -skip:$isUnix {
Comment thread
r15ch13 marked this conversation as resolved.
Write-Output '$path = join-path "$psscriptroot" "..\apps\vim\current\vim.exe"' | Out-File "$working_dir/moch-shim.ps1" -Encoding utf8
Write-Output 'if($myinvocation.expectingInput) { $input | & $path @args } else { & $path @args }' | Out-File "$working_dir/moch-shim.ps1" -Append -Encoding utf8
get_app_name_from_ps1_shim "$working_dir/moch-shim.ps1" | should -be "vim"
}

It "returns empty string if file exists and is not a shim" -skip:$isUnix {
Write-Output "lorem ipsum" | Out-File -Encoding ascii "$working_dir/mock-shim.ps1"
get_app_name_from_ps1_shim "$working_dir/mock-shim.ps1" | should -be ""
Expand All @@ -165,8 +159,8 @@ describe "ensure_robocopy_in_path" -Tag 'Scoop' {

context "robocopy is not in path" {
it "shims robocopy when not on path" -skip:$isUnix {
mock gcm { $false }
Get-Command robocopy | should -be $false
mock Test-CommandAvailable { $false }
Test-CommandAvailable robocopy | should -be $false

ensure_robocopy_in_path

Expand All @@ -180,7 +174,9 @@ describe "ensure_robocopy_in_path" -Tag 'Scoop' {

context "robocopy is in path" {
it "does not shim robocopy when it is in path" -skip:$isUnix {
mock gcm { $true }
mock Test-CommandAvailable { $true }
Test-CommandAvailable robocopy | should -be $true

ensure_robocopy_in_path

"$shimdir/robocopy.ps1" | should -not -exist
Expand Down