Lint: PSAvoidUsingCmdletAliases (#2075)

This commit is contained in:
Chawye Hsu
2018-03-04 01:41:19 +08:00
committed by Richard Kuhnt
parent 0c555991f8
commit e1bb1e91d0
45 changed files with 212 additions and 212 deletions
+4 -4
View File
@@ -59,7 +59,7 @@ if(!($upstream -match "^(.*)\/(.*):(.*)$")) {
function execute($cmd) {
Write-Host -f Green $cmd
$output = iex $cmd
$output = Invoke-Expression $cmd
if($LASTEXITCODE -gt 0) {
Write-Host -f Red "^^^ Error! See above ^^^ (last command: $cmd)"
@@ -125,12 +125,12 @@ if($push -eq $true) {
. "$psscriptroot\checkver.ps1" * -update -dir $dir
if($specialSnowflakes) {
write-host -f DarkCyan "Forcing update on our special snowflakes: $($specialSnowflakes -join ',')"
$specialSnowflakes -split ',' | % {
$specialSnowflakes -split ',' | ForEach-Object {
. "$psscriptroot\checkver.ps1" $_ -update -forceUpdate -dir $dir
}
}
hub diff --name-only | % {
hub diff --name-only | ForEach-Object {
$manifest = $_
if(!$manifest.EndsWith(".json")) {
return
@@ -149,7 +149,7 @@ hub diff --name-only | % {
execute "hub add $manifest"
# detect if file was staged, because it's not when only LF or CRLF have changed
$status = iex "hub status --porcelain -uno"
$status = Invoke-Expression "hub status --porcelain -uno"
$status = $status | select-object -first 1
if($status -and $status.StartsWith('M ') -and $status.EndsWith("$app.json")) {
execute "hub commit -m 'Update $app to version $version'"
+7 -7
View File
@@ -20,7 +20,7 @@ $dir = resolve-path $dir
# get apps to check
$queue = @()
gci $dir "$search.json" | % {
Get-ChildItem $dir "$search.json" | ForEach-Object {
$manifest = parse_json "$dir\$_"
$queue += ,@($_, $manifest)
}
@@ -63,7 +63,7 @@ function test_dl($url, $cookies) {
}
}
$queue | % {
$queue | ForEach-Object {
$name, $manifest = $_
$urls = @()
$ok = 0
@@ -71,13 +71,13 @@ $queue | % {
$errors = @()
if($manifest.url) {
$manifest.url | % { $urls += $_ }
$manifest.url | ForEach-Object { $urls += $_ }
} else {
url $manifest "64bit" | % { $urls += $_ }
url $manifest "32bit" | % { $urls += $_ }
url $manifest "64bit" | ForEach-Object { $urls += $_ }
url $manifest "32bit" | ForEach-Object { $urls += $_ }
}
$urls | % {
$urls | ForEach-Object {
$url, $status, $msg = test_dl $_ $manifest.cookie
if($msg) { $errors += "$msg ($url)" }
if($status -eq "OK" -or $status -eq "OpeningData") { $ok += 1 } else { $failed += 1 }
@@ -106,7 +106,7 @@ $queue | % {
write-host "] " -nonewline
write-host (strip_ext $name)
$errors | % {
$errors | ForEach-Object {
write-host -f darkred " > $_"
}
}
+4 -4
View File
@@ -31,7 +31,7 @@ if($app) { $search = $app }
# get apps to check
$queue = @()
gci $dir "$search.json" | % {
Get-ChildItem $dir "$search.json" | ForEach-Object {
$json = parse_json "$dir\$_"
if($json.checkver) {
$queue += ,@($_, $json)
@@ -39,14 +39,14 @@ gci $dir "$search.json" | % {
}
# clear any existing events
get-event | % {
get-event | ForEach-Object {
remove-event $_.sourceidentifier
}
$original = use_any_https_protocol
# start all downloads
$queue | % {
$queue | ForEach-Object {
$wc = new-object net.webclient
$wc.Headers.Add("user-agent", "Scoop/1.0 (+http://scoop.sh/) (Windows NT 6.1; WOW64)")
register-objectevent $wc downloadstringcompleted -ea stop | out-null
@@ -168,7 +168,7 @@ while($in_progress -gt 0) {
if($match -and $match.Success) {
$matchesHashtable = @{}
$regex.GetGroupNames() | % { $matchesHashtable.Add($_, $match.Groups[$_].Value) }
$regex.GetGroupNames() | ForEach-Object { $matchesHashtable.Add($_, $match.Groups[$_].Value) }
$ver = $matchesHashtable['1']
if ($replace) {
$ver = $regex.replace($match.Value, $replace)
+2 -2
View File
@@ -14,12 +14,12 @@ if($app) { $search = $app }
# get apps to check
$apps = @()
gci $dir "$search.json" | % {
Get-ChildItem $dir "$search.json" | ForEach-Object {
$json = parse_json "$dir\$_"
$apps += ,@(($_ -replace '\.json$', ''), $json)
}
$apps |% {
$apps | ForEach-Object {
$app, $json = $_
write-host "$app`: " -nonewline
+1 -1
View File
@@ -20,7 +20,7 @@ if ($type -is [System.IO.DirectoryInfo]) {
exit
}
$files | % {
$files | ForEach-Object {
# beautify
$json = parse_json "$dir$_" | ConvertToPrettyJson
+1 -1
View File
@@ -18,7 +18,7 @@ write-host -f cyan "A" -nonewline
write-host "]utoupdate"
write-host " | |"
gci $dir "*.json" | % {
Get-ChildItem $dir "*.json" | ForEach-Object {
$json = parse_json "$dir\$_"
if ($skipSupported -and $json.checkver -and $json.autoupdate) {
+2 -2
View File
@@ -10,9 +10,9 @@ if("$src" -eq "$dest") { abort "$(strip_ext $myinvocation.mycommand.name) is for
'copying files...'
$output = robocopy $src $dest /mir /njh /njs /nfl /ndl /xd .git tmp /xf .DS_Store last_updated
$output | ? { $_ -ne "" }
$output | Where-Object { $_ -ne "" }
echo 'creating shim...'
Write-Output 'creating shim...'
shim "$dest\bin\scoop.ps1" $false
ensure_scoop_in_path
+5 -5
View File
@@ -12,20 +12,20 @@ reset_aliases
$commands = commands
if ('--version' -contains $cmd -or (!$cmd -and '-v' -contains $args)) {
pushd $(versiondir 'scoop' 'current')
Push-Location $(versiondir 'scoop' 'current')
write-host "Current Scoop version:"
git_log --oneline HEAD -n 1
write-host ""
popd
Pop-Location
buckets | % {
pushd $(bucketdir $_)
buckets | ForEach-Object {
Push-Location $(bucketdir $_)
if(test-path '.git') {
write-host "'$_' bucket:"
git_log --oneline HEAD -n 1
write-host ""
}
popd
Pop-Location
}
}
elseif (@($null, '--help', '/?') -contains $cmd -or $args -contains '-h') { exec 'help' $args }
+5 -5
View File
@@ -22,7 +22,7 @@ function do_uninstall($app, $global) {
$install = install_info $app $version $global
$architecture = $install.architecture
echo "Uninstalling '$app'"
Write-Output "Uninstalling '$app'"
run_uninstaller $manifest $architecture $dir
rm_shims $manifest $global $architecture
@@ -36,7 +36,7 @@ function do_uninstall($app, $global) {
$appdir = appdir $app $global
try {
rm -r -force $appdir -ea stop
Remove-Item -r -force $appdir -ea stop
} catch {
$errors = $true
warn "Couldn't remove $(friendly_path $appdir): $_.exception"
@@ -44,7 +44,7 @@ function do_uninstall($app, $global) {
}
function rm_dir($dir) {
try {
rm -r -force $dir -ea stop
Remove-Item -r -force $dir -ea stop
} catch {
abort "Couldn't remove $(friendly_path $dir): $_"
}
@@ -53,11 +53,11 @@ function rm_dir($dir) {
# run uninstallation for each app if necessary, continuing if there's
# a problem deleting a directory (which is quite likely)
if($global) {
installed_apps $true | % { # global apps
installed_apps $true | ForEach-Object { # global apps
do_uninstall $_ $true
}
}
installed_apps $false | % { # local apps
installed_apps $false | ForEach-Object { # local apps
do_uninstall $_ $false
}
+4 -4
View File
@@ -23,7 +23,7 @@ function find_hash_in_rdf([String] $url, [String] $filename) {
}
# Find file content
$digest = $data.RDF.Content | ? { [String]$_.about -eq $filename }
$digest = $data.RDF.Content | Where-Object { [String]$_.about -eq $filename }
return format_hash $digest.sha256
}
@@ -195,7 +195,7 @@ function update_manifest_prop([String] $prop, $json, [Hashtable] $substitutions)
# check if there are architecture specific variants
if ($json.architecture -and $json.autoupdate.architecture) {
$json.architecture | Get-Member -MemberType NoteProperty | % {
$json.architecture | Get-Member -MemberType NoteProperty | ForEach-Object {
$architecture = $_.Name
if ($json.architecture.$architecture.$prop -and $json.autoupdate.architecture.$architecture.$prop) {
$json.architecture.$architecture.$prop = substitute (arch_specific $prop $json.autoupdate $architecture) $substitutions
@@ -223,7 +223,7 @@ function get_version_substitutions([String] $version, [Hashtable] $customMatches
$versionVariables.Set_Item('$matchTail', $matches['tail'])
}
if($customMatches) {
$customMatches.GetEnumerator() | % {
$customMatches.GetEnumerator() | ForEach-Object {
if($_.Name -ne "0") {
$versionVariables.Set_Item('$match' + (Get-Culture).TextInfo.ToTitleCase($_.Name), $_.Value)
}
@@ -262,7 +262,7 @@ function autoupdate([String] $app, $dir, $json, [String] $version, [Hashtable] $
throw "Could not update $app"
}
} else {
$json.architecture | Get-Member -MemberType NoteProperty | % {
$json.architecture | Get-Member -MemberType NoteProperty | ForEach-Object {
$valid = $true
$architecture = $_.Name
+3 -3
View File
@@ -9,7 +9,7 @@ function bucketdir($name) {
function known_bucket_repos {
$dir = versiondir 'scoop' 'current'
$json = "$dir\buckets.json"
gc $json -raw | convertfrom-json -ea stop
Get-Content $json -raw | convertfrom-json -ea stop
}
function known_bucket_repo($name) {
@@ -18,13 +18,13 @@ function known_bucket_repo($name) {
}
function apps_in_bucket($dir) {
gci $dir | ? { $_.name.endswith('.json') } | % { $_ -replace '.json$', '' }
Get-ChildItem $dir | Where-Object { $_.name.endswith('.json') } | ForEach-Object { $_ -replace '.json$', '' }
}
function buckets {
$buckets = @()
if(test-path $bucketsdir) {
gci $bucketsdir | % { $buckets += $_.name }
Get-ChildItem $bucketsdir | ForEach-Object { $buckets += $_.name }
}
$buckets
}
+7 -7
View File
@@ -1,15 +1,15 @@
function command_files {
(gci (relpath '..\libexec')) `
+ (gci "$scoopdir\shims") `
| where { $_.name -match 'scoop-.*?\.ps1$' }
(Get-ChildItem (relpath '..\libexec')) `
+ (Get-ChildItem "$scoopdir\shims") `
| Where-Object { $_.name -match 'scoop-.*?\.ps1$' }
}
function commands {
command_files | % { command_name $_ }
command_files | ForEach-Object { command_name $_ }
}
function command_name($filename) {
$filename.name | sls 'scoop-(.*?)\.ps1$' | % { $_.matches[0].groups[1].value }
$filename.name | Select-String 'scoop-(.*?)\.ps1$' | ForEach-Object { $_.matches[0].groups[1].value }
}
function command_path($cmd) {
@@ -19,9 +19,9 @@ function command_path($cmd) {
if (!(Test-Path $cmd_path)) {
# get path from shim
$shim_path = "$scoopdir\shims\scoop-$cmd.ps1"
$line = ((gc $shim_path) | where { $_.startswith('$path') })
$line = ((Get-Content $shim_path) | Where-Object { $_.startswith('$path') })
if($line) {
iex -command "$line"
Invoke-Expression -command "$line"
$cmd_path = $path
}
else { $cmd_path = $shim_path }
+4 -4
View File
@@ -2,7 +2,7 @@ $cfgpath = "~/.scoop"
function hashtable($obj) {
$h = @{ }
$obj.psobject.properties | % {
$obj.psobject.properties | ForEach-Object {
$h[$_.name] = hashtable_val $_.value
}
return $h
@@ -12,7 +12,7 @@ function hashtable_val($obj) {
if($obj -eq $null) { return $null }
if($obj -is [array]) {
$arr = @()
$obj | % {
$obj | ForEach-Object {
$val = hashtable_val $_
if($val -is [array]) {
$arr += ,@($val)
@@ -32,7 +32,7 @@ function load_cfg {
if(!(test-path $cfgpath)) { return $null }
try {
hashtable (gc $cfgpath -raw | convertfrom-json -ea stop)
hashtable (Get-Content $cfgpath -raw | convertfrom-json -ea stop)
} catch {
write-host "ERROR loading $cfgpath`: $($_.exception.message)"
}
@@ -77,7 +77,7 @@ if($p) {
if($cred -eq 'currentuser') {
[net.webrequest]::defaultwebproxy.credentials = [net.credentialcache]::defaultcredentials
} elseif($cred) {
$user, $pass = $cred -split '(?<!\\):' |% { $_ -replace '\\([@:])','$1' }
$user, $pass = $cred -split '(?<!\\):' | ForEach-Object { $_ -replace '\\([@:])','$1' }
[net.webrequest]::defaultwebproxy.credentials = new-object net.networkcredential($user, $pass)
}
} catch {
+21 -21
View File
@@ -3,20 +3,20 @@
# Old installations should continue to work using the old path.
# There is currently no automatic migration path to deal
# with updating old installations to the new path.
$scoopdir = $env:SCOOP, "$env:USERPROFILE\scoop" | select -first 1
$scoopdir = $env:SCOOP, "$env:USERPROFILE\scoop" | Select-Object -first 1
$oldscoopdir = "$env:LOCALAPPDATA\scoop"
if((test-path $oldscoopdir) -and !$env:SCOOP) {
$scoopdir = $oldscoopdir
}
$globaldir = $env:SCOOP_GLOBAL, "$env:ProgramData\scoop" | select -first 1
$globaldir = $env:SCOOP_GLOBAL, "$env:ProgramData\scoop" | Select-Object -first 1
# Note: Setting the SCOOP_CACHE environment variable to use a shared directory
# is experimental and untested. There may be concurrency issues when
# multiple users write and access cached files at the same time.
# Use at your own risk.
$cachedir = $env:SCOOP_CACHE, "$scoopdir\cache" | select -first 1
$cachedir = $env:SCOOP_CACHE, "$scoopdir\cache" | Select-Object -first 1
# Note: Github disabled TLS 1.0 support on 2018-02-23. Need to enable TLS 1.2
# for all communication with api.github.com
@@ -29,7 +29,7 @@ enable-encryptionscheme "Tls12"
function coalesce($a, $b) { if($a) { return $a } $b }
function format($str, $hash) {
$hash.keys | % { set-variable $_ $hash[$_] }
$hash.keys | ForEach-Object { set-variable $_ $hash[$_] }
$executionContext.invokeCommand.expandString($str)
}
function is_admin {
@@ -82,7 +82,7 @@ function installed($app, $global=$null) {
function installed_apps($global) {
$dir = appsdir $global
if(test-path $dir) {
gci $dir | where { $_.psiscontainer -and $_.name -ne 'scoop' } | % { $_.name }
Get-ChildItem $dir | Where-Object { $_.psiscontainer -and $_.name -ne 'scoop' } | ForEach-Object { $_.name }
}
}
@@ -108,7 +108,7 @@ function app_status($app, $global) {
}
$status.missing_deps = @()
$deps = @(runtime_deps $manifest) | ? { !(installed $_) }
$deps = @(runtime_deps $manifest) | Where-Object { !(installed $_) }
if($deps) {
$status.missing_deps += ,$deps
}
@@ -213,9 +213,9 @@ function shim($path, $global, $name, $arg) {
$shim = "$abs_shimdir\$($name.tolower())"
# convert to relative path
pushd $abs_shimdir
Push-Location $abs_shimdir
$relative_path = resolve-path -relative $path
popd
Pop-Location
$resolved_path = resolve-path $path
# if $path points to another drive resolve-path prepends .\ which could break shims
@@ -237,7 +237,7 @@ function shim($path, $global, $name, $arg) {
if($path -match '\.exe$') {
# for programs with no awareness of any shell
cp "$(versiondir 'scoop' 'current')\supporting\shimexe\bin\shim.exe" "$shim.exe" -force
Copy-Item "$(versiondir 'scoop' 'current')\supporting\shimexe\bin\shim.exe" "$shim.exe" -force
write-output "path = $resolved_path" | out-file "$shim.shim" -encoding utf8
if($arg) {
write-output "args = $arg" | out-file "$shim.shim" -encoding utf8 -append
@@ -292,7 +292,7 @@ function ensure_architecture($architecture_opt) {
function ensure_all_installed($apps, $global) {
$installed = @()
$apps | Select-Object -Unique | Where-Object { $_.name -ne 'scoop' } | % {
$apps | Select-Object -Unique | Where-Object { $_.name -ne 'scoop' } | ForEach-Object {
$app = $_
if(installed $app $false) {
$installed += ,@($app, $false)
@@ -312,7 +312,7 @@ function ensure_all_installed($apps, $global) {
function strip_path($orig_path, $dir) {
if($orig_path -eq $null) { $orig_path = '' }
$stripped = [string]::join(';', @( $orig_path.split(';') | ? { $_ -and $_ -ne $dir } ))
$stripped = [string]::join(';', @( $orig_path.split(';') | Where-Object { $_ -and $_ -ne $dir } ))
return ($stripped -ne $orig_path), $stripped
}
@@ -338,7 +338,7 @@ function ensure_scoop_in_path($global) {
}
function ensure_robocopy_in_path {
if(!(gcm robocopy -ea ignore)) {
if(!(Get-Command robocopy -ea ignore)) {
shim "C:\Windows\System32\Robocopy.exe" $false
}
}
@@ -347,9 +347,9 @@ function wraptext($text, $width) {
if(!$width) { $width = $host.ui.rawui.windowsize.width };
$width -= 1 # be conservative: doesn't seem to print the last char
$text -split '\r?\n' | % {
$text -split '\r?\n' | ForEach-Object {
$line = ''
$_ -split ' ' | % {
$_ -split ' ' | ForEach-Object {
if($line.length -eq 0) { $line = $_ }
elseif($line.length + $_.length + 1 -le $width) { $line += " $_" }
else { $lines += ,$line; $line = $_ }
@@ -383,7 +383,7 @@ $default_aliases = @{
}
function reset_alias($name, $value) {
if($existing = get-alias $name -ea ignore |? { $_.options -match 'readonly' }) {
if($existing = get-alias $name -ea ignore | Where-Object { $_.options -match 'readonly' }) {
if($existing.definition -ne $value) {
write-host "Alias $name is read-only; can't reset it." -f darkyellow
}
@@ -401,8 +401,8 @@ function reset_alias($name, $value) {
function reset_aliases() {
# for aliases where there's a local function, re-alias so the function takes precedence
$aliases = get-alias |? { $_.options -notmatch 'readonly|allscope' } |% { $_.name }
get-childitem function: | % {
$aliases = get-alias | Where-Object { $_.options -notmatch 'readonly|allscope' } | ForEach-Object { $_.name }
get-childitem function: | ForEach-Object {
$fn = $_.name
if($aliases -contains $fn) {
set-alias $fn local:$fn -scope script
@@ -410,13 +410,13 @@ function reset_aliases() {
}
# set default aliases
$default_aliases.keys | % { reset_alias $_ $default_aliases[$_] }
$default_aliases.keys | ForEach-Object { reset_alias $_ $default_aliases[$_] }
}
# convert list of apps to list of ($app, $global) tuples
function applist($apps, $global) {
if(!$apps) { return @() }
return ,@($apps |% { ,@($_, $global) })
return ,@($apps | ForEach-Object { ,@($_, $global) })
}
function app($app) {
@@ -459,9 +459,9 @@ function is_scoop_outdated() {
function substitute($entity, [Hashtable] $params) {
if ($entity -is [Array]) {
return $entity | % { substitute $_ $params }
return $entity | ForEach-Object { substitute $_ $params }
} elseif ($entity -is [String]) {
$params.GetEnumerator() | % {
$params.GetEnumerator() | ForEach-Object {
$entity = $entity.Replace($_.Name, $_.Value)
}
return $entity
+3 -3
View File
@@ -10,9 +10,9 @@ function requires_lessmsi ($manifest, $architecture) {
$useLessMsi = get_config MSIEXTRACT_USE_LESSMSI
if (!$useLessMsi) { return $false }
$(url $manifest $architecture |? {
$(url $manifest $architecture | Where-Object {
$_ -match '\.(msi)$'
} | measure | select -exp count) -gt 0
} | Measure-Object | Select-Object -exp count) -gt 0
}
function file_requires_7zip($fname) {
@@ -29,5 +29,5 @@ function extract_7zip($path, $to, $recurse) {
if(test-path "$to\$tar") { extract_7zip "$to\$tar" $to $true }
}
if($recurse) { rm $path } # clean up intermediate files
if($recurse) { Remove-Item $path } # clean up intermediate files
}
+1 -1
View File
@@ -27,7 +27,7 @@ function dep_resolve($app, $arch, $resolved, $unresolved) {
$null, $manifest, $null, $null = locate $app $bucket
if(!$manifest) { abort "Couldn't find manifest for '$app'$(if(!$bucket) { '.' } else { " from '$bucket' bucket." })" }
$deps = @(install_deps $manifest $arch) + @(runtime_deps $manifest) | select -uniq
$deps = @(install_deps $manifest $arch) + @(runtime_deps $manifest) | Select-Object -uniq
foreach($dep in $deps) {
if($resolved -notcontains $dep) {
+3 -3
View File
@@ -47,10 +47,10 @@ function clean_description($description) {
function meta_tags($html) {
$tags = @()
$meta = ([regex]'<meta [^>]+>').matches($html)
$meta |% {
$meta | ForEach-Object {
$attrs = ([regex]'([\w-]+)="([^"]+)"').matches($_.value)
$hash = @{}
$attrs |% {
$attrs | ForEach-Object {
$hash[$_.groups[1].value] = $_.groups[2].value
}
$tags += $hash
@@ -60,7 +60,7 @@ function meta_tags($html) {
function meta_content($tags, $attribute, $search) {
if(!$tags) { return }
return $tags |? { $_[$attribute] -eq $search } |% { $_['content'] }
return $tags | Where-Object { $_[$attribute] -eq $search } | ForEach-Object { $_['content'] }
}
# Looks for a redirect URL in a <meta> refresh tag.
+1 -1
View File
@@ -9,7 +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 = gcm get-mppreference -errorAction SilentlyContinue
$hasGetMpPreference = Get-Command get-mppreference -errorAction SilentlyContinue
if($hasGetMpPreference) {
$installPath = $scoopdir;
if($global) { $installPath = $globaldir; }
+1 -1
View File
@@ -32,7 +32,7 @@ function getopt($argv, $shortopts, $longopts) {
if($arg.startswith('--')) {
$name = $arg.substring(2)
$longopt = $longopts | ? { $_ -match "^$name=?$" }
$longopt = $longopts | Where-Object { $_ -match "^$name=?$" }
if($longopt) {
if($longopt.endswith('=')) { # requires arg
+1 -1
View File
@@ -1,6 +1,6 @@
function git_proxy_cmd {
$proxy = $(scoop config proxy)
$cmd = "git $($args |% { "$_ " })"
$cmd = "git $($args | ForEach-Object { "$_ " })"
if($proxy) {
$cmd = "SET HTTPS_PROXY=$proxy&&SET HTTP_PROXY=$proxy&&$cmd"
}
+4 -4
View File
@@ -1,16 +1,16 @@
function usage($text) {
$text | sls '(?m)^# Usage: ([^\n]*)$' | % { "Usage: " + $_.matches[0].groups[1].value }
$text | Select-String '(?m)^# Usage: ([^\n]*)$' | ForEach-Object { "Usage: " + $_.matches[0].groups[1].value }
}
function summary($text) {
$text | sls '(?m)^# Summary: ([^\n]*)$' | % { $_.matches[0].groups[1].value }
$text | Select-String '(?m)^# Summary: ([^\n]*)$' | ForEach-Object { $_.matches[0].groups[1].value }
}
function help($text) {
$help_lines = $text | sls '(?ms)^# Help:(.(?!^[^#]))*' | % { $_.matches[0].value; }
$help_lines = $text | Select-String '(?ms)^# Help:(.(?!^[^#]))*' | ForEach-Object { $_.matches[0].value; }
$help_lines -replace '(?ms)^#\s?(Help: )?', ''
}
function my_usage { # gets usage for the calling script
usage (gc $myInvocation.PSCommandPath -raw)
usage (Get-Content $myInvocation.PSCommandPath -raw)
}
+39 -39
View File
@@ -314,7 +314,7 @@ function dl_urls($app, $version, $manifest, $architecture, $dir, $use_cache = $t
if(!$ok) {
# rm cached
$cached = cache_path $app $version $url
if(test-path $cached) { rm -force $cached }
if(test-path $cached) { Remove-Item -force $cached }
abort $err
}
}
@@ -352,7 +352,7 @@ function dl_urls($app, $version, $manifest, $architecture, $dir, $use_cache = $t
write-host "Extracting... " -nonewline
$null = mkdir "$dir\_tmp"
& $extract_fn "$dir\$fname" "$dir\_tmp"
rm "$dir\$fname"
Remove-Item "$dir\$fname"
if ($extract_to) {
$null = mkdir "$dir\$extract_to" -force
}
@@ -362,7 +362,7 @@ function dl_urls($app, $version, $manifest, $architecture, $dir, $use_cache = $t
if(test-path "$dir\_tmp") { # might have been moved by movedir
try {
rm -r -force "$dir\_tmp" -ea stop
Remove-Item -r -force "$dir\_tmp" -ea stop
} catch [system.io.pathtoolongexception] {
& "$env:COMSPEC" /c "rmdir /s /q $dir\_tmp"
} catch [system.unauthorizedaccessexception] {
@@ -394,7 +394,7 @@ function lessmsi_config ($extract_dir) {
function cookie_header($cookies) {
if(!$cookies) { return }
$vals = $cookies.psobject.properties | % {
$vals = $cookies.psobject.properties | ForEach-Object {
"$($_.name)=$($_.value)"
}
@@ -415,7 +415,7 @@ function ftp_file_size($url) {
# hashes
function hash_for_url($manifest, $url, $arch) {
$hashes = @(hash $manifest $arch) | ? { $_ -ne $null };
$hashes = @(hash $manifest $arch) | Where-Object { $_ -ne $null };
if($hashes.length -eq 0) { return $null }
@@ -462,7 +462,7 @@ function compute_hash($file, $algname) {
} else {
$fs = [system.io.file]::openread($file)
$alg = [system.security.cryptography.hashalgorithm]::create($algname)
$hexbytes = $alg.computehash($fs) | % { $_.tostring('x2') }
$hexbytes = $alg.computehash($fs) | ForEach-Object { $_.tostring('x2') }
return [string]::join('', $hexbytes)
}
} catch {
@@ -474,13 +474,13 @@ function compute_hash($file, $algname) {
}
function cmd_available($cmd) {
try { gcm $cmd -ea stop | out-null } catch { return $false }
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 | % { (format $_ @{'dir'=$dir;'global'=$global}) } }
if($config) { return $config | ForEach-Object { (format $_ @{'dir'=$dir;'global'=$global}) } }
@()
}
@@ -521,11 +521,11 @@ function unpack_inno($fname, $manifest, $dir) {
abort "Failed to unpack innosetup file. See $dir\innounp.log"
}
gci "$dir\_scoop_unpack\{app}" -r | mv -dest "$dir" -force
Get-ChildItem "$dir\_scoop_unpack\{app}" -r | Move-Item -dest "$dir" -force
rmdir -r -force "$dir\_scoop_unpack"
Remove-Item -r -force "$dir\_scoop_unpack"
rm "$dir\$fname"
Remove-Item "$dir\$fname"
write-host "done."
}
@@ -535,7 +535,7 @@ function run_installer($fname, $manifest, $architecture, $dir, $global) {
$installer = installer $manifest $architecture
if($installer.script) {
write-output "Running installer script..."
iex $installer.script
Invoke-Expression $installer.script
return
}
@@ -569,19 +569,19 @@ function install_msi($fname, $dir, $msi) {
if(!$installed) {
abort "Installation aborted. You might need to run 'scoop uninstall $app' before trying again."
}
rm $logfile
rm $msifile
Remove-Item $logfile
Remove-Item $msifile
}
function extract_msi($path, $to) {
$logfile = "$(split-path $path)\msi.log"
$ok = run 'msiexec' @('/a', "`"$path`"", '/qn', "TARGETDIR=`"$to`"", "/lwe `"$logfile`"")
if(!$ok) { abort "Failed to extract files from $path.`nLog file:`n $(friendly_path $logfile)" }
if(test-path $logfile) { rm $logfile }
if(test-path $logfile) { Remove-Item $logfile }
}
function extract_lessmsi($path, $to) {
iex "lessmsi x `"$path`" `"$to\`""
Invoke-Expression "lessmsi x `"$path`" `"$to\`""
}
# deprecated
@@ -591,7 +591,7 @@ function extract_lessmsi($path, $to) {
function msi_installed($code) {
$path = "hklm:\software\microsoft\windows\currentversion\uninstall\$code"
if(!(test-path $path)) { return $false }
$key = gi $path
$key = Get-Item $path
$name = $key.getvalue('displayname')
$version = $key.getvalue('displayversion')
$classkey = "IdentifyingNumber=`"$code`",Name=`"$name`",Version=`"$version`""
@@ -615,7 +615,7 @@ function install_prog($fname, $dir, $installer, $global) {
# Don't remove installer if "keep" flag is set to true
if(!($installer.keep -eq "true")) {
rm $prog
Remove-Item $prog
}
}
}
@@ -625,7 +625,7 @@ function run_uninstaller($manifest, $architecture, $dir) {
$uninstaller = uninstaller $manifest $architecture
if($uninstaller.script) {
write-output "Running uninstaller script..."
iex $uninstaller.script
Invoke-Expression $uninstaller.script
return
}
@@ -675,7 +675,7 @@ function shim_def($item) {
function create_shims($manifest, $dir, $global, $arch) {
$shims = @(arch_specific 'bin' $manifest $arch)
$shims | ?{ $_ -ne $null } | % {
$shims | Where-Object { $_ -ne $null } | ForEach-Object {
$target, $name, $arg = shim_def $_
write-output "Creating shim for '$name'."
@@ -697,13 +697,13 @@ function rm_shim($name, $shimdir) {
warn "Shim for '$name' is missing. Skipping."
} else {
write-output "Removing shim for '$name'."
rm $shim
Remove-Item $shim
}
# other shim types might be present
'', '.exe', '.shim', '.cmd' | % {
'', '.exe', '.shim', '.cmd' | ForEach-Object {
if(test-path -Path "$shimdir\$name$_" -PathType leaf) {
rm "$shimdir\$name$_"
Remove-Item "$shimdir\$name$_"
}
}
}
@@ -711,7 +711,7 @@ function rm_shim($name, $shimdir) {
function rm_shims($manifest, $global, $arch) {
$shims = @(arch_specific 'bin' $manifest $arch)
$shims | ?{ $_ -ne $null } | % {
$shims | Where-Object { $_ -ne $null } | ForEach-Object {
$target, $name, $null = shim_def $_
$shimdir = shimdir $global
@@ -782,14 +782,14 @@ function ensure_install_dir_not_in_path($dir, $global) {
$fixed, $removed = find_dir_or_subdir $path "$dir"
if($removed) {
$removed | % { "Installer added '$(friendly_path $_)' to path. Removing."}
$removed | ForEach-Object { "Installer added '$(friendly_path $_)' to path. Removing."}
env 'path' $global $fixed
}
if(!$global) {
$fixed, $removed = find_dir_or_subdir (env 'path' $true) "$dir"
if($removed) {
$removed | % { warn "Installer added '$_' to system path. You might want to remove this manually (requires admin permission)."}
$removed | ForEach-Object { warn "Installer added '$_' to system path. You might want to remove this manually (requires admin permission)."}
}
}
}
@@ -798,7 +798,7 @@ function find_dir_or_subdir($path, $dir) {
$dir = $dir.trimend('\')
$fixed = @()
$removed = @()
$path.split(';') | % {
$path.split(';') | ForEach-Object {
if($_) {
if(($_ -eq $dir) -or ($_ -like "$dir\*")) { $removed += $_ }
else { $fixed += $_ }
@@ -808,7 +808,7 @@ function find_dir_or_subdir($path, $dir) {
}
function env_add_path($manifest, $dir, $global) {
$manifest.env_add_path | ? { $_ } | % {
$manifest.env_add_path | Where-Object { $_ } | ForEach-Object {
$path_dir = join-path $dir $_
if(!(is_in_dir $dir $path_dir)) {
@@ -832,7 +832,7 @@ function add_first_in_path($dir, $global) {
function env_rm_path($manifest, $dir, $global) {
# remove from path
$manifest.env_add_path | ? { $_ } | % {
$manifest.env_add_path | Where-Object { $_ } | ForEach-Object {
$path_dir = join-path $dir $_
remove_from_path $path_dir $global
@@ -841,20 +841,20 @@ function env_rm_path($manifest, $dir, $global) {
function env_set($manifest, $dir, $global) {
if($manifest.env_set) {
$manifest.env_set | gm -member noteproperty | % {
$manifest.env_set | Get-Member -member noteproperty | ForEach-Object {
$name = $_.name;
$val = format $manifest.env_set.$($_.name) @{ "dir" = $dir }
env $name $global $val
sc env:\$name $val
Set-Content env:\$name $val
}
}
}
function env_rm($manifest, $global) {
if($manifest.env_set) {
$manifest.env_set | gm -member noteproperty | % {
$manifest.env_set | Get-Member -member noteproperty | ForEach-Object {
$name = $_.name
env $name $global $null
if(test-path env:\$name) { rm env:\$name }
if(test-path env:\$name) { Remove-Item env:\$name }
}
}
}
@@ -886,7 +886,7 @@ function pre_install($manifest, $arch) {
$pre_install = arch_specific 'pre_install' $manifest $arch
if($pre_install) {
write-output "Running pre-install script..."
iex (@($pre_install) -join "`r`n")
Invoke-Expression (@($pre_install) -join "`r`n")
}
}
@@ -894,7 +894,7 @@ function post_install($manifest, $arch) {
$post_install = arch_specific 'post_install' $manifest $arch
if($post_install) {
write-output "Running post-install script..."
iex (@($post_install) -join "`r`n")
Invoke-Expression (@($post_install) -join "`r`n")
}
}
@@ -907,7 +907,7 @@ function show_notes($manifest, $dir, $original_dir, $persist_dir) {
}
function all_installed($apps, $global) {
$apps | ? {
$apps | Where-Object {
$app, $null = app $_
installed $app $global
}
@@ -917,7 +917,7 @@ function all_installed($apps, $global) {
function prune_installed($apps, $global) {
$installed = @(all_installed $apps $global)
$uninstalled = $apps | ? { $installed -notcontains $_ }
$uninstalled = $apps | Where-Object { $installed -notcontains $_ }
return @($uninstalled), @($installed)
}
@@ -943,7 +943,7 @@ function show_suggestions($suggested) {
$installed_apps = (installed_apps $true) + (installed_apps $false)
foreach($app in $suggested.keys) {
$features = $suggested[$app] | get-member -type noteproperty |% { $_.name }
$features = $suggested[$app] | get-member -type noteproperty | ForEach-Object { $_.name }
foreach($feature in $features) {
$feature_suggestions = $suggested[$app].$feature
@@ -990,7 +990,7 @@ function persist_data($manifest, $original_dir, $persist_dir) {
$persist = @($persist);
}
$persist | % {
$persist | ForEach-Object {
$source, $target = persist_def $_
write-host "Persisting $source"
+4 -4
View File
@@ -7,7 +7,7 @@ function manifest_path($app, $bucket) {
function parse_json($path) {
if(!(test-path $path)) { return $null }
gc $path -raw -Encoding UTF8 | convertfrom-json -ea stop
Get-Content $path -raw -Encoding UTF8 | convertfrom-json -ea stop
}
function url_manifest($url) {
@@ -30,7 +30,7 @@ function manifest($app, $bucket, $url) {
function save_installed_manifest($app, $bucket, $dir, $url) {
if($url) { (new-object net.webclient).downloadstring($url) > "$dir\manifest.json" }
else { cp (manifest_path $app $bucket) "$dir\manifest.json" }
else { Copy-Item (manifest_path $app $bucket) "$dir\manifest.json" }
}
function installed_manifest($app, $version, $global) {
@@ -38,8 +38,8 @@ function installed_manifest($app, $version, $global) {
}
function save_install_info($info, $dir) {
$nulls = $info.keys | ? { $info[$_] -eq $null }
$nulls | % { $info.remove($_) } # strip null-valued
$nulls = $info.keys | Where-Object { $info[$_] -eq $null }
$nulls | ForEach-Object { $info.remove($_) } # strip null-valued
$info | convertto-json | out-file "$dir\install.json"
}
+2 -2
View File
@@ -1,7 +1,7 @@
# Creates shortcut for the app in the start menu
function create_startmenu_shortcuts($manifest, $dir, $global, $arch) {
$shortcuts = @(arch_specific 'shortcuts' $manifest $arch)
$shortcuts | ?{ $_ -ne $null } | % {
$shortcuts | Where-Object { $_ -ne $null } | ForEach-Object {
$target = [System.IO.Path]::Combine($dir, $_.item(0))
$target = New-Object System.IO.FileInfo($target)
$name = $_.item(1)
@@ -59,7 +59,7 @@ function startmenu_shortcut([System.IO.FileInfo] $target, $shortcutName, $argume
# Removes the Startmenu shortcut if it exists
function rm_startmenu_shortcuts($manifest, $global, $arch) {
$shortcuts = @(arch_specific 'shortcuts' $manifest $arch)
$shortcuts | ?{ $_ -ne $null } | % {
$shortcuts | Where-Object { $_ -ne $null } | ForEach-Object {
$name = $_.item(1)
$shortcut = "$(shortcut_folder $global)\$name.lnk"
write-host "Removing shortcut $(friendly_path $shortcut)"
+4 -4
View File
@@ -10,9 +10,9 @@ if(!(is_unix)) {
}
# core.ps1
$scoopdir = $env:SCOOP, (Join-Path $env:HOME "scoop") | select -first 1
$globaldir = $env:SCOOP_GLOBAL, "/usr/local/scoop" | select -first 1
$cachedir = $env:SCOOP_CACHE, (Join-Path $scoopdir "cache") | select -first 1
$scoopdir = $env:SCOOP, (Join-Path $env:HOME "scoop") | Select-Object -first 1
$globaldir = $env:SCOOP_GLOBAL, "/usr/local/scoop" | Select-Object -first 1
$cachedir = $env:SCOOP_CACHE, (Join-Path $scoopdir "cache") | Select-Object -first 1
# core.ps1
function ensure($dir) {
@@ -41,5 +41,5 @@ function compute_hash($file, $algname) {
default { $result = (sha256sum -b $file) }
}
}
return $result.split(' ') | select -first 1
return $result.split(' ') | Select-Object -first 1
}
+4 -4
View File
@@ -9,11 +9,11 @@ function versions($app, $global) {
$appdir = appdir $app $global
if(!(test-path $appdir)) { return @() }
sort_versions (gci $appdir -dir -attr !reparsePoint | % { $_.name })
sort_versions (Get-ChildItem $appdir -dir -attr !reparsePoint | ForEach-Object { $_.name })
}
function version($ver) {
$ver -split '[\.-]' | % {
$ver -split '[\.-]' | ForEach-Object {
$num = $_ -as [int]
if($num) { $num } else { $_ }
}
@@ -44,9 +44,9 @@ function qsort($ary, $fn) {
$pivot = $ary[0]
$rem = $ary[1..($ary.length-1)]
$lesser = qsort ($rem | where { (& $fn $_ $pivot) -lt 0 }) $fn
$lesser = qsort ($rem | Where-Object { (& $fn $_ $pivot) -lt 0 }) $fn
$greater = qsort ($rem | where { (& $fn $_ $pivot) -ge 0 }) $fn
$greater = qsort ($rem | Where-Object { (& $fn $_ $pivot) -ge 0 }) $fn
return @() + $lesser + @($pivot) + $greater
}
+3 -3
View File
@@ -76,8 +76,8 @@ function rm_alias($name) {
function list_aliases {
$aliases = @{}
(init_alias_config).getenumerator() |% {
$summary = summary (gc (command_path $_.name) -raw)
(init_alias_config).getenumerator() | ForEach-Object {
$summary = summary (Get-Content (command_path $_.name) -raw)
if(!($summary)) { $summary = '' }
$aliases.add("$($_.name) ", $summary)
}
@@ -86,7 +86,7 @@ function list_aliases {
warn "No aliases founds."
}
$aliases.getenumerator() | sort name | ft -hidetablehead -autosize -wrap
$aliases.getenumerator() | Sort-Object name | Format-Table -hidetablehead -autosize -wrap
}
switch($opt) {
+3 -3
View File
@@ -36,7 +36,7 @@ function add_bucket($name, $repo) {
if(!$repo) { "Unknown bucket '$name'. Try specifying <repo>."; $usage_add; exit 1 }
}
$git = try { gcm 'git' -ea stop } catch { $null }
$git = try { Get-Command 'git' -ea stop } catch { $null }
if(!$git) {
abort "Git is required for buckets. Run 'scoop install git'."
}
@@ -67,7 +67,7 @@ function rm_bucket($name) {
abort "'$name' bucket not found."
}
rm $dir -r -force -ea stop
Remove-Item $dir -r -force -ea stop
}
function list_buckets {
@@ -75,7 +75,7 @@ function list_buckets {
}
function known_buckets {
known_bucket_repos |% { $_.psobject.properties | select -expand 'name' }
known_bucket_repos | ForEach-Object { $_.psobject.properties | Select-Object -expand 'name' }
}
switch($cmd) {
+4 -4
View File
@@ -23,15 +23,15 @@ function cacheinfo($file) {
}
function show($app) {
$files = @(gci "$cachedir" | ? { $_.name -match "^$app" })
$total_length = ($files | measure length -sum).sum -as [double]
$files = @(Get-ChildItem "$cachedir" | Where-Object { $_.name -match "^$app" })
$total_length = ($files | Measure-Object length -sum).sum -as [double]
$f_app = @{ expression={"$($_.app) ($($_.version))" }}
$f_url = @{ expression={$_.url};alignment='right'}
$f_size = @{ expression={$_.size}; alignment='right'}
$files | % { cacheinfo $_ } | ft $f_size, $f_app, $f_url -auto -hide
$files | ForEach-Object { cacheinfo $_ } | Format-Table $f_size, $f_app, $f_url -auto -hide
"Total: $($files.length) $(pluralize $files.length 'file' 'files'), $(filesize $total_length)"
}
@@ -39,7 +39,7 @@ function show($app) {
switch($cmd) {
'rm' {
if(!$app) { 'ERROR: <app> missing'; my_usage; exit 1 }
rm "$cachedir\$app#*"
Remove-Item "$cachedir\$app#*"
}
'show' {
show $app
+2 -2
View File
@@ -35,11 +35,11 @@ function cleanup($app, $global, $verbose) {
}
write-host -f yellow "Removing $app`:" -nonewline
$versions | % {
$versions | ForEach-Object {
$version = $_
write-host " $version" -nonewline
$dir = versiondir $app $version $global
gci $dir | % {
Get-ChildItem $dir | ForEach-Object {
$file = $_
if($file.LinkType -ne $null) {
fsutil.exe reparsepoint delete $file.FullName | out-null
+3 -3
View File
@@ -10,8 +10,8 @@
reset_aliases
$def_arch = default_architecture
$local = installed_apps $false | % { @{ name = $_; global = $false } }
$global = installed_apps $true | % { @{ name = $_; global = $true } }
$local = installed_apps $false | ForEach-Object { @{ name = $_; global = $false } }
$global = installed_apps $true | ForEach-Object { @{ name = $_; global = $true } }
$apps = @($local) + @($global)
$count = 0
@@ -20,7 +20,7 @@ $count = 0
# echo "{["
if($apps) {
$apps | sort { $_.name } | ? { !$query -or ($_.name -match $query) } | % {
$apps | Sort-Object { $_.name } | Where-Object { !$query -or ($_.name -match $query) } | ForEach-Object {
$app = $_.name
$global = $_.global
$ver = current_version $app $global
+4 -4
View File
@@ -9,7 +9,7 @@ param($cmd)
reset_aliases
function print_help($cmd) {
$file = gc (command_path $cmd) -raw
$file = Get-Content (command_path $cmd) -raw
$usage = usage $file
$summary = summary $file
@@ -22,14 +22,14 @@ function print_help($cmd) {
function print_summaries {
$commands = @{}
command_files | % {
command_files | ForEach-Object {
$command = command_name $_
$summary = summary (gc (command_path $command) -raw)
$summary = summary (Get-Content (command_path $command) -raw)
if(!($summary)) { $summary = '' }
$commands.add("$command ", $summary) # add padding
}
$commands.getenumerator() | sort name | ft -hidetablehead -autosize -wrap
$commands.getenumerator() | Sort-Object name | Format-Table -hidetablehead -autosize -wrap
}
$commands = commands
+1 -1
View File
@@ -15,7 +15,7 @@ if($app) {
if([string]::isnullorempty($manifest.homepage)) {
abort "Could not find homepage in manifest for '$app'."
}
start $manifest.homepage
Start-Process $manifest.homepage
}
else {
abort "Could not find manifest for '$app'."
+2 -2
View File
@@ -109,13 +109,13 @@ ensure_none_failed $apps $global
$apps, $skip = prune_installed $apps $global
$skip | ? { $explicit_apps -contains $_} | % {
$skip | Where-Object { $explicit_apps -contains $_} | ForEach-Object {
$version = @(versions $_ $global)[-1]
warn "'$_' ($version) is already installed. Skipping."
}
$suggested = @{};
$apps | % { install_app $_ $architecture $global $suggested $use_cache }
$apps | ForEach-Object { install_app $_ $architecture $global $suggested $use_cache }
show_suggestions $suggested
+3 -3
View File
@@ -11,14 +11,14 @@ param($query)
reset_aliases
$def_arch = default_architecture
$local = installed_apps $false | % { @{ name = $_ } }
$global = installed_apps $true | % { @{ name = $_; global = $true } }
$local = installed_apps $false | ForEach-Object { @{ name = $_ } }
$global = installed_apps $true | ForEach-Object { @{ name = $_; global = $true } }
$apps = @($local) + @($global)
if($apps) {
write-host "Installed apps$(if($query) { `" matching '$query'`"}): `n"
$apps | sort { $_.name } | ? { !$query -or ($_.name -match $query) } | % {
$apps | Sort-Object { $_.name } | Where-Object { !$query -or ($_.name -match $query) } | ForEach-Object {
$app = $_.name
$global = $_.global
$ver = current_version $app $global
+2 -2
View File
@@ -20,8 +20,8 @@ if($err) { "scoop reset: $err"; exit 1 }
if(!$apps) { error 'ERROR: <app> missing'; my_usage; exit 1 }
if($apps -eq '*') {
$local = installed_apps $false | % { ,@($_, $false) }
$global = installed_apps $true | % { ,@($_, $true) }
$local = installed_apps $false | ForEach-Object { ,@($_, $false) }
$global = installed_apps $true | ForEach-Object { ,@($_, $true) }
$apps = @($local) + @($global)
}
+13 -13
View File
@@ -25,7 +25,7 @@ function bin_match($manifest, $query) {
}
function search_bucket($bucket, $query) {
$apps = apps_in_bucket (bucketdir $bucket) | % {
$apps = apps_in_bucket (bucketdir $bucket) | ForEach-Object {
@{ name = $_ }
}
@@ -36,7 +36,7 @@ function search_bucket($bucket, $query) {
abort "Invalid regular expression: $($_.exception.innerexception.message)"
}
$apps = $apps | ? {
$apps = $apps | Where-Object {
if($_.name -match $query) { return $true }
$bin = bin_match (manifest $_.name $bucket) $query
if($bin) {
@@ -44,12 +44,12 @@ function search_bucket($bucket, $query) {
}
}
}
$apps | % { $_.version = (latest_version $_.name $bucket); $_ }
$apps | ForEach-Object { $_.version = (latest_version $_.name $bucket); $_ }
}
function download_json($url) {
$progressPreference = 'silentlycontinue'
$result = invoke-webrequest $url -UseBasicParsing | select -exp content | convertfrom-json
$result = invoke-webrequest $url -UseBasicParsing | Select-Object -exp content | convertfrom-json
$progressPreference = 'continue'
$result
}
@@ -67,9 +67,9 @@ function search_remote($bucket, $query) {
$user = $matches[1]
$repo_name = $matches[2]
$api_link = "https://api.github.com/repos/$user/$repo_name/git/trees/HEAD?recursive=1"
$result = download_json $api_link | select -exp tree |? {
$result = download_json $api_link | Select-Object -exp tree | Where-Object {
$_.path -match "(^(.*$query.*).json$)"
} |% { $matches[2] }
} | ForEach-Object { $matches[2] }
}
$result
@@ -77,11 +77,11 @@ function search_remote($bucket, $query) {
function search_remotes($query) {
$buckets = known_bucket_repos
$names = $buckets | get-member -m noteproperty | select -exp name
$names = $buckets | get-member -m noteproperty | Select-Object -exp name
$results = $names |? { !(test-path $(bucketdir $_)) } |% {
$results = $names | Where-Object { !(test-path $(bucketdir $_)) } | ForEach-Object {
@{"bucket" = $_; "results" = (search_remote $_ $query)}
} |? { $_.results }
} | Where-Object { $_.results }
if ($results.count -gt 0) {
"Results from other known buckets..."
@@ -89,14 +89,14 @@ function search_remotes($query) {
""
}
$results |% {
$results | ForEach-Object {
"'$($_.bucket)' bucket:"
$_.results |% { " $_" }
$_.results | ForEach-Object { " $_" }
""
}
}
@($null) + @(buckets) | % { # $null is main bucket
@($null) + @(buckets) | ForEach-Object { # $null is main bucket
$res = search_bucket $_ $query
$local_results = $local_results -or $res
if($res) {
@@ -104,7 +104,7 @@ function search_remotes($query) {
if(!$_) { $name = "main" }
"'$name' bucket:"
$res | % {
$res | ForEach-Object {
$item = " $($_.name) ($($_.version))"
if($_.bin) { $item += " --> includes '$($_.bin)'" }
$item
+8 -8
View File
@@ -16,11 +16,11 @@ $currentdir = fullpath $(versiondir 'scoop' 'current')
$needs_update = $false
if(test-path "$currentdir\.git") {
pushd $currentdir
Push-Location $currentdir
git_fetch -q origin
$commits = $(git log "HEAD..origin/$(scoop config SCOOP_BRANCH)" --oneline)
if($commits) { $needs_update = $true }
popd
Pop-Location
}
else {
$needs_update = $true
@@ -36,12 +36,12 @@ $outdated = @()
$removed = @()
$missing_deps = @()
$true, $false | % { # local and global apps
$true, $false | ForEach-Object { # local and global apps
$global = $_
$dir = appsdir $global
if(!(test-path $dir)) { return }
gci $dir | ? name -ne 'scoop' | % {
Get-ChildItem $dir | Where-Object name -ne 'scoop' | ForEach-Object {
$app = $_.name
$status = app_status $app $global
if($status.failed) {
@@ -61,7 +61,7 @@ $true, $false | % { # local and global apps
if($outdated) {
write-host -f DarkCyan 'Updates are available for:'
$outdated.keys | % {
$outdated.keys | ForEach-Object {
$versions = $outdated.$_
" $_`: $($versions[0]) -> $($versions[1])"
}
@@ -69,21 +69,21 @@ if($outdated) {
if($removed) {
write-host -f DarkCyan 'These app manifests have been removed:'
$removed.keys | % {
$removed.keys | ForEach-Object {
" $_"
}
}
if($failed) {
write-host -f DarkCyan 'These apps failed to install:'
$failed.keys | % {
$failed.keys | ForEach-Object {
" $_"
}
}
if($missing_deps) {
write-host -f DarkCyan 'Missing runtime dependencies:'
$missing_deps | % {
$missing_deps | ForEach-Object {
$app, $deps = $_
" '$app' requires '$([string]::join("', '", $deps))'"
}
+5 -5
View File
@@ -36,7 +36,7 @@ if($apps -eq 'scoop') {
$apps = ensure_all_installed $apps $global
if(!$apps) { exit 0 }
$apps | % {
$apps | ForEach-Object {
($app, $global) = $_
$version = current_version $app $global
@@ -71,7 +71,7 @@ $apps | % {
env_rm $manifest $global
try {
rm -r $dir -ea stop -force
Remove-Item -r $dir -ea stop -force
} catch {
error "Couldn't remove '$(friendly_path $dir)'; it may be in use."
continue
@@ -83,7 +83,7 @@ $apps | % {
write-host "Removing older version ($oldver)."
$dir = versiondir $app $oldver $global
try {
rm -r -force -ea stop $dir
Remove-Item -r -force -ea stop $dir
} catch {
error "Couldn't remove '$(friendly_path $dir)'; it may be in use."
continue
@@ -95,7 +95,7 @@ $apps | % {
try {
# if last install failed, the directory seems to be locked and this
# will throw an error about the directory not existing
rm -r $appdir -ea stop -force
Remove-Item -r $appdir -ea stop -force
} catch {
if((test-path $appdir)) { throw } # only throw if the dir still exists
}
@@ -107,7 +107,7 @@ $apps | % {
if (Test-Path $persist_dir) {
try {
rm -r $persist_dir -ea stop -force
Remove-Item -r $persist_dir -ea stop -force
} catch {
error "Couldn't remove '$(friendly_path $persist_dir)'; it may be in use."
continue
+12 -12
View File
@@ -49,7 +49,7 @@ if(!$branch) {
function update_scoop() {
# check for git
$git = try { gcm git -ea stop } catch { $null }
$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." }
write-host "Updating Scoop..."
@@ -66,27 +66,27 @@ function update_scoop() {
}
# replace non-git scoop with the git version
rm -r -force $currentdir -ea stop
mv $newdir $currentdir
Remove-Item -r -force $currentdir -ea stop
Move-Item $newdir $currentdir
}
else {
pushd $currentdir
Push-Location $currentdir
git_pull -q
$res = $lastexitcode
if($res -ne 0) {
abort 'Update failed.'
}
popd
Pop-Location
}
ensure_scoop_in_path
shim "$currentdir\bin\scoop.ps1" $false
@(buckets) | % {
@(buckets) | ForEach-Object {
write-host "Updating '$_' bucket..."
pushd (bucketdir $_)
Push-Location (bucketdir $_)
git_pull -q
popd
Pop-Location
}
scoop config lastupdate (get-date)
@@ -106,8 +106,8 @@ function update($app, $global, $quiet = $false, $independent, $suggested, $use_c
if(!$independent) {
# check dependencies
$deps = @(deps $app $architecture) | ? { !(installed $_) }
$deps | % { install_app $_ $architecture $global $suggested $use_cache }
$deps = @(deps $app $architecture) | Where-Object { !(installed $_) }
$deps | ForEach-Object { install_app $_ $architecture $global $suggested $use_cache }
}
$version = latest_version $app $bucket $url
@@ -181,7 +181,7 @@ if(!$apps) {
$apps = ensure_all_installed $apps_param $global
}
if($apps) {
$apps | % {
$apps | ForEach-Object {
($app, $global) = $_
$status = app_status $app $global
if($force -or $status.outdated) {
@@ -199,7 +199,7 @@ if(!$apps) {
$suggested = @{};
# # $outdated is a list of ($app, $global) tuples
$outdated | % { update @_ $quiet $independent $suggested $use_cache }
$outdated | ForEach-Object { update @_ $quiet $independent $suggested $use_cache }
}
exit 0
+2 -2
View File
@@ -162,7 +162,7 @@ if($apps_param -eq '*') {
$requests = 0
$apps | % {
$apps | ForEach-Object {
($app, $global) = $_
$manifest, $bucket = find_manifest $app
if(!$manifest) {
@@ -189,7 +189,7 @@ $apps | % {
$url = @($url)
}
$hash | % { $i = 0 } {
$hash | ForEach-Object { $i = 0 } {
$requests += 1
if ($requests -eq 5) {
info("Sleeping 60+ seconds between requests due to VirusTotal's 4/min limit")
+3 -3
View File
@@ -9,7 +9,7 @@ reset_aliases
if(!$command) { 'ERROR: <command> missing'; my_usage; exit 1 }
try { $gcm = gcm "$command" -ea stop } catch { } #
try { $gcm = Get-Command "$command" -ea stop } catch { } #
if(!$gcm) { [console]::error.writeline("'$command' not found"); exit 3 }
$path = "$($gcm.path)"
@@ -17,9 +17,9 @@ $usershims = "$(resolve-path $(shimdir $false))"
$globalshims = fullpath (shimdir $true) # don't resolve: may not exist
if($path.endswith(".ps1") -and ($path -like "$usershims*" -or $path -like "$globalshims*")) {
$shimtext = gc $path
$shimtext = Get-Content $path
$exepath = ($shimtext |? { $_.startswith('$path') }).split(' ') | select -Last 1 | iex
$exepath = ($shimtext | Where-Object { $_.startswith('$path') }).split(' ') | Select-Object -Last 1 | Invoke-Expression
if(![system.io.path]::ispathrooted($exepath)) {
# Expand relative path
+1 -1
View File
@@ -16,7 +16,7 @@ describe "add_alias" {
$alias_file | should not exist
add_alias "rm" '"hello, world!"'
iex $alias_file | should be "hello, world!"
Invoke-Expression $alias_file | should be "hello, world!"
}
}
+2 -2
View File
@@ -92,7 +92,7 @@ describe "unzip_old" {
$to | should exist
(gci $to).count | should be 0
(Get-ChildItem $to).count | should be 0
}
}
@@ -183,7 +183,7 @@ describe "ensure_robocopy_in_path" {
context "robocopy is not in path" {
it "shims robocopy when not on path" -skip:$isUnix {
mock gcm { $false }
gcm robocopy | should be $false
Get-Command robocopy | should be $false
ensure_robocopy_in_path
+2 -2
View File
@@ -46,13 +46,13 @@ describe "manifest-validation" {
context "manifest validates against the schema" {
beforeall {
$bucketdir = "$psscriptroot\..\bucket\"
$manifest_files = gci $bucketdir *.json
$manifest_files = Get-ChildItem $bucketdir *.json
$validator = new-object Scoop.Validator($schema, $true)
}
$global:quota_exceeded = $false
$manifest_files | % {
$manifest_files | ForEach-Object {
it "$_" {
$file = $_ # exception handling may overwrite $_