Skip to content

Commit

Permalink
feat: Present utils command (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ash258 committed Mar 15, 2021
1 parent 4fb735c commit c628fe9
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 6 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

### 0.6-pre2

- **scoop-psmodules**: Add global modules to path only if global manifest is installed
- New command `utils` added
- Native parameter binding for aliases works again
- **git**: Fix proxy handling
- **psmodules**: Add global modules to path only if global manifest is installed
- **decompress**: Support `INNOSETUP_USE_INNOEXTRACT` config option and `Expand-InnoArchive -UseInnoextract`
- **format**: Extract checkver fixes into own function and add generic adjust property function
- **schema**
Expand All @@ -22,6 +25,7 @@
- Refactor all git/hub calls to use -C option
- **scoop-checkup**: Test full shovel adoption
- **scoop-alias**: First alias addition is correctly registered and created
- **autoupdate**: Do not autoupdate unless URL is accessible after successful hash extraction

### 0.6-pre1

Expand Down
6 changes: 1 addition & 5 deletions bin/scoop.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,7 @@ if ($version) {
Invoke-ScoopCommand 'help' @{ 'cmd' = $cmd }
$exitCode = $LASTEXITCODE
} elseif ($validCommand) {
# Filter out --help and -h to prevent handling them in each command
# This should never be needed, but just in case to prevent failures of installation, etc
$newArgs = ($args -notlike '--help') -notlike '-h'

Invoke-ScoopCommand $cmd $newArgs
Invoke-ScoopCommand $cmd $args
$exitCode = $LASTEXITCODE
} else {
Write-UserMessage -Message "scoop: '$cmd' isn't a scoop command. See 'scoop help'." -Output
Expand Down
86 changes: 86 additions & 0 deletions libexec/scoop-utils.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Usage: scoop utils [utility] [path] [options] [--additional-options ...]
# Summary: Wrapper around utilities for maintaining buckets and manifests.
# Help: Bucket maintainers no longer need to have own 'bin' folder and they can use native command.
#
# Two possible ways how to pass parameters to this command:
# 1. Pass fullname of the manifest. No wildcard support
# 2. Pass simple string (with wildcard support) to search in ./bucket/ folder
# Or pass --bucketdir to override default bucket path
#
# Options:
# -b, --bucketdir Use specific bucket directory instead of default './bucket/'.
# --additional-options Valid, powershell-like parameters passed to specific utility binary.
# Refer to each utility for all available parameters/options.
# -h, --help Show help for this command.
#
# Example usage:
# 'scoop utils checkver $env:SCOOP\buckets\main\bucket\pwsh.json' => Check explicitly passed manfiest files
# 'scoop utils checkver manifest*' => Check all manifests matching manifest* in ./bucket/
# 'scoop utils checkhashes manifest*' --bucketdir ..\..\testbucket\bucket => Check all manifests matching manifest* in provided directory
# 'scoop utils auto-pr --additional-options -Upstream "user/repo:branch" -skipcheckver -push' => Execute auto-pr with specific upstream string
#

'core', 'getopt', 'Helpers', 'help' | ForEach-Object {
. (Join-Path $PSScriptRoot "..\lib\$_.ps1")
}

$getopt = $args
$AdditionalArgs = @()
# Remove additional args before processing arguments
if ($args -contains '--additional-options') {
$index = $args.IndexOf('--additional-options')
$getopt = $args[0..($index - 1)]
$AdditionalArgs = $args[($index + 1)..($args.Count - 1)]
}

#region Parameter handling/validation
$opt, $rem, $err = getopt $getopt 'b:' 'bucketdir='
if ($err) { Stop-ScoopExecution -Message "scoop utils: $err" -ExitCode 1 -Usage (my_usage) }

$Utility = $rem[0]
$VALID_UTILITIES = @(
'auto-pr'
'checkhashes'
'checkurl'
'checkver'
'describe'
'format'
'missing-checkver'
)

if (!$Utility) { Stop-ScoopExecution -Message 'No utility provided' -ExitCode 1 -Usage (my_usage) }
if ($Utility -notin $VALID_UTILITIES) { Stop-ScoopExecution -Message "$Utility is not valid Scoop utility" -ExitCode 1 -Usage (my_usage) }

$UtilityPath = (Join-Path $PSScriptRoot '..\bin' | Get-ChildItem -Filter "$Utility.ps1" -File).FullName
$BucketFolder = Join-Path $PWD 'bucket'

if ($opt.b -or $opt.bucketdir) { $BucketFolder = $opt.b, $opt.bucketdir | Where-Object { $null -ne $_ } | Select-Object -First 1 }

$ManifestPath = $rem[1]
# Edge case for fullpath or nothing, which needed specific handling
if (!$ManifestPath) {
$ManifestPath = '*'
} elseif (Test-Path -LiteralPath $ManifestPath -ErrorAction 'SilentlyContinue') {
$item = Get-Item $ManifestPath
$BucketFolder = $item.Directory.FullName
$ManifestPath = $item.BaseName
}

try {
$BucketFolder = Resolve-Path $BucketFolder -ErrorAction 'Stop'
} catch {
Stop-ScoopExecution -Message "scoop utils: $BucketFolder is not valid directory" -ExitCode 2
}
#endregion Parameter handling/validation

$exitCode = 0

try {
& $UtilityPath -App $ManifestPath -Dir $BucketFolder @AdditionalArgs
$exitCode = $LASTEXITCODE
} catch {
Write-UserMessage -Message "Utility issue: $($_.Exception.Message)" -Err
$exitCode = 3
}

exit $exitCode
4 changes: 4 additions & 0 deletions supporting/completion/Scoop-Completion.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ $script:SCOOP_COMMANDS = @(
'unhold'
'uninstall'
'update'
'utils'
'virustotal'
'which'
)
Expand All @@ -37,6 +38,7 @@ $script:SCOOP_SUB_COMMANDS = @{
'bucket' = 'add known list rm'
'cache' = 'rm show'
'config' = 'rm show'
'utils' = 'auto-pr checkhashes checkurl checkver describe format missing-checkver'
}
$script:SCOOP_SHORT_PARAMETERS = @{
'cleanup' = 'g k'
Expand All @@ -48,6 +50,7 @@ $script:SCOOP_SHORT_PARAMETERS = @{
'unhold' = 'g'
'uninstall' = 'g p'
'update' = 'f g i k s q'
'utils' = 'b'
'virustotal' = 'a s n'
}
$script:SCOOP_LONG_PARAMETERS = @{
Expand All @@ -60,6 +63,7 @@ $script:SCOOP_LONG_PARAMETERS = @{
'unhold' = 'global'
'uninstall' = 'global purge'
'update' = 'force global independent no-cache skip quiet'
'utils' = 'bucketdir additional-options'
'virustotal' = 'arch scan no-depends'
}
# Add --help and -h to all
Expand Down
5 changes: 5 additions & 0 deletions supporting/completion/scoop.lua
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,11 @@ local scoopParser = parser({
'-q', '--quiet',
'-h', '--help'
):loop(1),
'utils' .. parser({'auto-pr', 'checkhashes', 'checkurl', 'checkver', 'describe', 'format', 'missing-checkver'},
'--additional-options',
'-b', '--bucketdir',
'-h', '--help'
):loop(1),
'virustotal' .. parser({getLocallyAvailableApplicationsByScoop},
'-a' .. architectureParser, '--arch' .. architectureParser,
'-s', '--scan',
Expand Down

0 comments on commit c628fe9

Please sign in to comment.