Skip to content

Commit

Permalink
(chocolateyGH-1118) Feature to disable non-elevated warnings
Browse files Browse the repository at this point in the history
showNonElevatedWarnings is the feature to disable to turn off
non-elevated warnings that pop up when running as a non-admin in the
default installation location (that is locked down to Administrators
only).
  • Loading branch information
ferventcoder authored and Russell Mora committed Jan 23, 2017
1 parent 03b2656 commit becb090
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/chocolatey/infrastructure.app/ApplicationParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ public static class Features
public static readonly string UsePackageExitCodes = "usePackageExitCodes";
public static readonly string UseFipsCompliantChecksums = "useFipsCompliantChecksums";
public static readonly string ScriptsCheckLastExitCode = "scriptsCheckLastExitCode";
public static readonly string ShowNonElevatedWarnings = "showNonElevatedWarnings";
}

public static class Messages
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ private static void set_feature_flags(ChocolateyConfiguration config, ConfigFile
config.Features.IgnoreInvalidOptionsSwitches = set_feature_flag(ApplicationParameters.Features.IgnoreInvalidOptionsSwitches, configFileSettings, defaultEnabled: true, description: "Ignore Invalid Options/Switches - If a switch or option is passed that is not recognized, should choco fail? Available in 0.9.10+.");
config.Features.UsePackageExitCodes = set_feature_flag(ApplicationParameters.Features.UsePackageExitCodes, configFileSettings, defaultEnabled: true, description: "Use Package Exit Codes - Package scripts can provide exit codes. With this on, package exit codes will be what choco uses for exit when non-zero (this value can come from a dependency package). Chocolatey defines valid exit codes as 0, 1605, 1614, 1641, 3010. With this feature off, choco will exit with a 0 or a 1 (matching previous behavior). Available in 0.9.10+.");
config.Features.UseFipsCompliantChecksums = set_feature_flag(ApplicationParameters.Features.UseFipsCompliantChecksums, configFileSettings, defaultEnabled: false, description: "Use FIPS Compliant Checksums - Ensure checksumming done by choco uses FIPS compliant algorithms. Not recommended unless required by FIPS Mode. Enabling on an existing installation could have unintended consequences related to upgrades/uninstalls. Available in 0.9.10+.");
config.Features.ShowNonElevatedWarnings = set_feature_flag(ApplicationParameters.Features.ShowNonElevatedWarnings, configFileSettings, defaultEnabled: true, description: "Show Non-Elevated Warnings - Display non-elevated warnings. Available in 0.10.4+.");
config.Features.ScriptsCheckLastExitCode = set_feature_flag(ApplicationParameters.Features.ScriptsCheckLastExitCode, configFileSettings, defaultEnabled: false, description: "Scripts Check $LastExitCode (external commands) - Leave this off unless you absolutely need it while you fix your package scripts to use `throw 'error message'` or `Set-PowerShellExitCode #` instead of `exit #`. This behavior started in 0.9.10 and produced hard to find bugs. If the last external process exits successfully but with an exit code of not zero, this could cause hard to detect package failures. Available in 0.10.3+. Will be removed in 0.11.0.");
config.PromptForConfirmation = !set_feature_flag(ApplicationParameters.Features.AllowGlobalConfirmation, configFileSettings, defaultEnabled: false, description: "Prompt for confirmation in scripts or bypass.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ public sealed class FeaturesConfiguration
public bool IgnoreInvalidOptionsSwitches { get; set; }
public bool UsePackageExitCodes { get; set; }
public bool UseFipsCompliantChecksums { get; set; }
public bool ShowNonElevatedWarnings { get; set; }
//todo remove in 0.11.0
public bool ScriptsCheckLastExitCode { get; set; }
}
Expand Down
3 changes: 3 additions & 0 deletions src/chocolatey/infrastructure.app/runners/GenericRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ public int count(ChocolateyConfiguration config, Container container, bool isCon
public void warn_when_admin_needs_elevation(ChocolateyConfiguration config)
{
if (config.HelpRequested) return;

// skip when commands will set or for background mode
if (!config.Features.ShowNonElevatedWarnings) return;

var shouldWarn = (!config.Information.IsProcessElevated && config.Information.IsUserAdministrator)
|| (!config.Information.IsUserAdministrator && ApplicationParameters.InstallLocation.is_equal_to(ApplicationParameters.CommonAppDataChocolatey));
Expand Down

0 comments on commit becb090

Please sign in to comment.