From 7d2f726748982fa848c22b191a9b1a46e0d89c4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C4=8C=C3=A1bera?= Date: Sat, 28 Nov 2020 15:13:24 -0800 Subject: [PATCH] test --- lib/getopt.ps1 | 15 +++++++++++++-- libexec/scoop-install.ps1 | 8 +++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/lib/getopt.ps1 b/lib/getopt.ps1 index 5dafb58e91..4b68c460e4 100644 --- a/lib/getopt.ps1 +++ b/lib/getopt.ps1 @@ -7,7 +7,7 @@ # longopts: # array of strings that are long-form options. options that take # a parameter should end with '=' -# returns @(opts hash, remaining_args array, error string) +# returns @(opts hash, remaining_args array, error string, customOptions) function getopt($argv, $shortopts, $longopts) { $opts = @{ } $rem = @() @@ -19,6 +19,7 @@ function getopt($argv, $shortopts, $longopts) { # Ensure these are arrays $argv = @($argv) $longopts = @($longopts) + $customOptions = [Ordered] @{ } for ($i = 0; $i -lt $argv.length; $i++) { $arg = $argv[$i] @@ -31,6 +32,16 @@ function getopt($argv, $shortopts, $longopts) { if ($arg.startswith('--')) { $name = $arg.substring(2) + if ($name -eq 'parameters') { + # Get only provided parameters + $special = $argv[($i + 1)..($argv.Length - 1)] + foreach ($sp in $special) { + $key, $value = $sp -split '=' + $customOptions.Add($key.ToLower(), $value) + } + break + } + $longopt = $longopts | Where-Object { $_ -match "^$name=?$" } if ($longopt) { @@ -69,5 +80,5 @@ function getopt($argv, $shortopts, $longopts) { } } - return $opts, $rem + return $opts, $rem, $null, $customOptions } diff --git a/libexec/scoop-install.ps1 b/libexec/scoop-install.ps1 index d64b82fbca..192f3d3c0d 100644 --- a/libexec/scoop-install.ps1 +++ b/libexec/scoop-install.ps1 @@ -10,6 +10,9 @@ # To install an app from a manifest on your computer # scoop install \path\to\app.json # +# To install an app from a manifest using specific options +# scoop install vscode --parameters 'CONTEXT=1' 'FULLPORTABLE=1' +# # Options: # -h, --help Show help for this command. # -g, --global Install the app globally. @@ -17,6 +20,7 @@ # -k, --no-cache Don't use the download cache. # -s, --skip Skip hash validation (use with caution!). # -a, --arch <32bit|64bit> Use the specified architecture, if the app supports it. +# -p, --parameters Manifest specific parameters (KEY=VALUE). Hash to be always last option 'Helpers', 'core', 'manifest', 'buckets', 'decompress', 'install', 'shortcuts', 'psmodules', 'Update', 'Versions', 'help', 'getopt', 'depends' | ForEach-Object { . (Join-Path $PSScriptRoot "..\lib\$_.ps1") @@ -50,9 +54,11 @@ function is_installed($app, $global) { return $false } -$opt, $apps, $err = getopt $args 'gfiksa:' 'global', 'force', 'independent', 'no-cache', 'skip', 'arch=' +$opt, $apps, $err, $configOptions = getopt $args 'gfiksa:' 'global', 'force', 'independent', 'no-cache', 'skip', 'arch=' if ($err) { Stop-ScoopExecution -Message "scoop install: $err" -ExitCode 2 } +# Write-Host $configOptions.beta +# exit 0 $exitCode = 0 $problems = 0 $global = $opt.g -or $opt.global