From 5614014479217aee25d43032dd864c830323007e Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Sat, 19 Mar 2016 22:03:31 -0500 Subject: [PATCH 1/6] (doc) update how to pass args The wiki is the most up to date on how to pass arguments. Update the local help menu to have the same. --- .../builders/ConfigurationBuilder.cs | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs b/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs index 3a50ac18a2..60f0147ce4 100644 --- a/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs +++ b/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs @@ -360,6 +360,8 @@ each command. "chocolatey".Log().Info(@" You can pass options and switches in the following ways: + * Unless stated otherwise, an option/switch should only be passed one + time. Otherwise you may find weird/non-supported behavior. * `-`, `/`, or `--` (one character switches should not use `--`) * **Option Bundling / Bundled Options**: One character switches can be bundled. e.g. `-d` (debug), `-f` (force), `-v` (verbose), and `-y` @@ -369,13 +371,20 @@ each command. the local options are parsed. * **Use Equals**: You can also include or not include an equals sign `=` between options and values. - * **Quote Values**: When you need to quote things, such as when using - spaces, please use apostrophes (`'value'`). In cmd.exe you may be - able to use just double quotes (`""value""`) but in powershell.exe - you may need to either escape the quotes with backticks - (`` `""value`"" ``) or use a combination of double quotes and - apostrophes (`""'value'""`). This is due to the hand off to - PowerShell - it seems to strip off the outer set of quotes. + * **Quote Values**: When you need to quote an entire argument, such as + when using spaces, please use a combination of double quotes and + apostrophes (`""'value'""`). In cmd.exe you can just use double quotes + (`""value""`) but in powershell.exe you should use backticks + (`` `""value`"" ``) or apostrophes (`'value'`). Using the combination + allows for both shells to work without issue, except for when the next + section applies. + * **Pass quotes in arguments**: When you need to pass quoted values to + to something like a native installer, you are in for a world of fun. In + cmd.exe you must pass it like this: `-ia ""/yo=""""Spaces spaces""""""`. In + PowerShell.exe, you must pass it like this: `-ia '/yo=""""Spaces spaces""""'`. + No other combination will work. In PowerShell.exe if you are on version + v3+, you can try `--%` before `-ia` to just pass the args through as is, + which means it should not require any special workarounds. * Options and switches apply to all items passed, so if you are installing multiple packages, and you use `--version=1.0.0`, choco is going to look for and try to install version 1.0.0 of every From 132825b2bb34d977e4ec6e9abfcaf51bdff91da9 Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Sun, 20 Mar 2016 09:44:54 -0500 Subject: [PATCH 2/6] (GH-663) Search just by id Similar to #453 which searches by exact id, you should also be able to filter the search results where the filter is part of the id only. --- .../infrastructure.app/commands/ChocolateyListCommand.cs | 3 +++ .../configuration/ChocolateyConfiguration.cs | 1 + src/chocolatey/infrastructure.app/nuget/NugetList.cs | 5 +++++ 3 files changed, 9 insertions(+) diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs index 5487230860..a1bca53762 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyListCommand.cs @@ -81,6 +81,9 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon .Add("e|exact", "Exact - Only return packages with this exact name.", option => configuration.ListCommand.Exact = option != null) + .Add("id|idonly|id-only", + "ByIdOnly - Only return packages with the filter being part of the id.", + option => configuration.ListCommand.ByIdOnly = option != null) ; } diff --git a/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs b/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs index 929eeaba2a..f4e25a4508 100644 --- a/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs +++ b/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs @@ -356,6 +356,7 @@ public ListCommandConfiguration() public int? Page { get; set; } public int PageSize { get; set; } public bool Exact { get; set; } + public bool ByIdOnly { get; set; } } [Serializable] diff --git a/src/chocolatey/infrastructure.app/nuget/NugetList.cs b/src/chocolatey/infrastructure.app/nuget/NugetList.cs index 8b740f915b..6c844f550b 100644 --- a/src/chocolatey/infrastructure.app/nuget/NugetList.cs +++ b/src/chocolatey/infrastructure.app/nuget/NugetList.cs @@ -98,6 +98,11 @@ private static IQueryable execute_package_search(ChocolateyConfigurati results = results.Where(p => p.Id == configuration.Input); } + if (configuration.ListCommand.ByIdOnly) + { + results = results.Where(p => p.Id.Contains(configuration.Input)); + } + return results.OrderBy(p => p.Id); } From 584ade9f4dd2cd12723c196bae1ffd81504f1a35 Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Sun, 20 Mar 2016 09:53:28 -0500 Subject: [PATCH 3/6] (GH-412) update parameter name for skip scripts The name of the skip powershell should be skip scripts for future expansion into other automation providers. --- .../infrastructure.app/commands/ChocolateyInstallCommand.cs | 2 +- .../infrastructure.app/commands/ChocolateyUninstallCommand.cs | 2 +- .../infrastructure.app/commands/ChocolateyUpgradeCommand.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyInstallCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyInstallCommand.cs index 5c7084b27e..ef82b92050 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyInstallCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyInstallCommand.cs @@ -73,7 +73,7 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon .Add("x|forcedependencies|force-dependencies", "ForceDependencies - Force dependencies to be reinstalled when force installing package(s). Must be used in conjunction with --force. Defaults to false.", option => configuration.ForceDependencies = option != null) - .Add("n|skippowershell|skip-powershell", + .Add("n|skippowershell|skip-powershell|skipscripts|skip-scripts|skip-automation-scripts", "Skip Powershell - Do not run chocolateyInstall.ps1. Defaults to false.", option => configuration.SkipPackageInstallProvider = option != null) .Add("u=|user=", diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyUninstallCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyUninstallCommand.cs index 925d4618bf..b6012fc31e 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyUninstallCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyUninstallCommand.cs @@ -61,7 +61,7 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon .Add("x|forcedependencies|force-dependencies|removedependencies|remove-dependencies", "RemoveDependencies - Uninstall dependencies when uninstalling package(s). Defaults to false.", option => configuration.ForceDependencies = option != null) - .Add("n|skippowershell|skip-powershell", + .Add("n|skippowershell|skip-powershell|skipscripts|skip-scripts|skip-automation-scripts", "Skip Powershell - Do not run chocolateyUninstall.ps1. Defaults to false.", option => configuration.SkipPackageInstallProvider = option != null) ; diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyUpgradeCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyUpgradeCommand.cs index c0f722d14b..389f2f802a 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyUpgradeCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyUpgradeCommand.cs @@ -72,7 +72,7 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon .Add("i|ignoredependencies|ignore-dependencies", "IgnoreDependencies - Ignore dependencies when upgrading package(s). Defaults to false.", option => configuration.IgnoreDependencies = option != null) - .Add("n|skippowershell|skip-powershell", + .Add("n|skippowershell|skip-powershell|skipscripts|skip-scripts|skip-automation-scripts", "Skip Powershell - Do not run chocolateyInstall.ps1. Defaults to false.", option => configuration.SkipPackageInstallProvider = option != null) .Add("failonunfound|fail-on-unfound", From 7c84bb28b9e0bdc06a2009fa970a111f0fb863c5 Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Sun, 20 Mar 2016 10:03:55 -0500 Subject: [PATCH 4/6] (GH-664) RefreshEnv Should also work in PowerShell cmd.exe has long had a nice command to run to update environment variables without needing to close the shell: `refreshenv`. Bring that functionality to PowerShell.exe as well. --- .../functions/Update-SessionEnvironment.ps1 | 21 +++++++++++++++++-- .../services/ChocolateyPackageService.cs | 2 +- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/chocolatey.resources/helpers/functions/Update-SessionEnvironment.ps1 b/src/chocolatey.resources/helpers/functions/Update-SessionEnvironment.ps1 index 1a70b4016b..84d2ac16a7 100644 --- a/src/chocolatey.resources/helpers/functions/Update-SessionEnvironment.ps1 +++ b/src/chocolatey.resources/helpers/functions/Update-SessionEnvironment.ps1 @@ -32,10 +32,21 @@ powershell session with all environment settings possibly performed by chocolatey package installs. #> - Write-Debug "Running 'Update-SessionEnvironment' - Updating the environment variables for the session." + Write-Debug "Running 'Update-SessionEnvironment'" + $refreshEnv = $false + $invocation = $MyInvocation + if ($invocation.InvocationName -eq 'refreshenv') { + $refreshEnv = $true + } + + if ($refreshEnv) { + Write-Output "Refreshing environment variables from the registry..." + } else { + Write-Verbose "Refreshing environment variables from the registry." + } #ordering is important here, $user comes after so we can override $machine - 'Machine', 'User' | + 'Process', 'Machine', 'User' | % { $scope = $_ Get-EnvironmentVariableNames -Scope $scope | @@ -51,4 +62,10 @@ chocolatey package installs. } | Select -Unique $Env:PATH = $paths -join ';' + + if ($refreshEnv) { + Write-Output "Finished" + } } + +Set-Alias refreshenv Update-SessionEnvironment \ No newline at end of file diff --git a/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs b/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs index 446a7a206b..a6fd2efa08 100644 --- a/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs +++ b/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs @@ -979,7 +979,7 @@ private void get_environment_after(ChocolateyConfiguration config, IEnumerable Date: Sun, 20 Mar 2016 10:05:35 -0500 Subject: [PATCH 5/6] (GH-295) Do not replace PSModulePath When running Chocolatey install / refreshenv, Chocolatey should not replace PSModulePath. It should keep the current value. --- .../helpers/functions/Update-SessionEnvironment.ps1 | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/chocolatey.resources/helpers/functions/Update-SessionEnvironment.ps1 b/src/chocolatey.resources/helpers/functions/Update-SessionEnvironment.ps1 index 84d2ac16a7..965e6f1815 100644 --- a/src/chocolatey.resources/helpers/functions/Update-SessionEnvironment.ps1 +++ b/src/chocolatey.resources/helpers/functions/Update-SessionEnvironment.ps1 @@ -44,6 +44,8 @@ chocolatey package installs. } else { Write-Verbose "Refreshing environment variables from the registry." } + + $psModulePath = $env:PSModulePath #ordering is important here, $user comes after so we can override $machine 'Process', 'Machine', 'User' | @@ -63,6 +65,9 @@ chocolatey package installs. Select -Unique $Env:PATH = $paths -join ';' + # PSModulePath is almost always updated by process, so we want to preserve it. + $env:PSModulePath = $psModulePath + if ($refreshEnv) { Write-Output "Finished" } From b480d6b0d5700ff0478a4eb24b6d88dc0eedf3d7 Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Sun, 20 Mar 2016 10:11:37 -0500 Subject: [PATCH 6/6] (GH-412)(GH-664) PoSh tab completion / refreshenv Provide PowerShell tab completion for Chocolatey commands including - searching for installed packages for upgrade/uninstall - searching for packages to install - only return the top 5 results from a search and only search by id Also set refreshenv as part of the profile additions. --- .../chocolatey.resources.csproj | 6 + .../helpers/ChocolateyTabExpansion.ps1 | 129 ++++++++++++++++++ .../helpers/chocolateyProfile.psm1 | 9 ++ 3 files changed, 144 insertions(+) create mode 100644 src/chocolatey.resources/helpers/ChocolateyTabExpansion.ps1 create mode 100644 src/chocolatey.resources/helpers/chocolateyProfile.psm1 diff --git a/src/chocolatey.resources/chocolatey.resources.csproj b/src/chocolatey.resources/chocolatey.resources.csproj index 508345384a..c6d570b8b7 100644 --- a/src/chocolatey.resources/chocolatey.resources.csproj +++ b/src/chocolatey.resources/chocolatey.resources.csproj @@ -131,6 +131,12 @@ + + + + + +