Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(GH-8) Host PowerShell #524

Merged
merged 9 commits into from
Jan 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added lib/PowerShell/System.Management.Automation.dll
Binary file not shown.
4 changes: 4 additions & 0 deletions src/chocolatey.console/chocolatey.console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Management.Automation">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\PowerShell\System.Management.Automation.dll</HintPath>
</Reference>
<Reference Include="System.Security" />
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
$packageName = 'badpackage'
try {

try {

Write-Host "Ya!"
Write-Debug "A debug message"
Write-Output "This is $packageName v$packageVersion being installed to `n '$packageFolder'."
Write-Host "PowerShell Version is '$($PSVersionTable.PSVersion)' and CLR Version is '$($PSVersionTable.CLRVersion)'."
Write-Host "Execution Policy is '$(Get-ExecutionPolicy)'."
Write-Host "PSScriptRoot is '$PSScriptRoot'."
Write-Debug "A debug message."
Write-Verbose "Yo!"
Write-Warning "A warning!"
Write-Error "Oh no! An error"
throw "We had an error captain!"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
$packageName = 'badpackage'
try {

try {

Write-Host "Ya!"
Write-Debug "A debug message"
Write-Output "This is $packageName v$packageVersion being installed to `n '$packageFolder'."
Write-Host "PowerShell Version is '$($PSVersionTable.PSVersion)' and CLR Version is '$($PSVersionTable.CLRVersion)'."
Write-Host "Execution Policy is '$(Get-ExecutionPolicy)'."
Write-Host "PSScriptRoot is '$PSScriptRoot'."
Write-Debug "A debug message."
Write-Verbose "Yo!"
Write-Warning "A warning!"
Write-Error "Oh no! An error"
throw "We had an error captain!"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
$toolsDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)"
"simple file" | Out-File "$toolsDir\simplefile.txt" -force

Write-Output "$env:PackageName $env:PackageVersion Installed"
Write-Output "This is $packageName v$packageVersion being installed to `n $packageFolder"
Write-Host "Ya!"
Write-Debug "A debug message"
Write-Verbose "Yo!"
Write-Warning "A warning!"

Write-Output "$packageName v$packageVersion has been installed to `n $packageFolder"
21 changes: 21 additions & 0 deletions src/chocolatey/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace chocolatey
{
using System;
using System.Globalization;
using System.Security;
using System.Text.RegularExpressions;
using infrastructure.app;
using infrastructure.logging;
Expand Down Expand Up @@ -83,6 +84,26 @@ public static string to_string(this string input)
return input;
}

/// <summary>
/// Takes a string and returns a secure string
/// </summary>
/// <param name="input">The input.</param>
/// <returns></returns>
public static SecureString to_secure_string(this string input)
{
var secureString = new SecureString();

if (string.IsNullOrWhiteSpace(input)) return secureString;

foreach (char character in input)
{
secureString.AppendChar(character);
}

return secureString;
}


private static readonly Regex _spacePattern = new Regex(@"\s", RegexOptions.Compiled);

/// <summary>
Expand Down
12 changes: 11 additions & 1 deletion src/chocolatey/chocolatey.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Management.Automation">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\PowerShell\System.Management.Automation.dll</HintPath>
</Reference>
<Reference Include="System.Reactive.Core">
<HintPath>..\packages\Rx-Core.2.1.30214.0\lib\Net40\System.Reactive.Core.dll</HintPath>
</Reference>
Expand All @@ -78,6 +82,8 @@
<Link>Properties\SolutionVersion.cs</Link>
</Compile>
<Compile Include="AssemblyExtensions.cs" />
<Compile Include="infrastructure\commandline\ReadKeyTimeout.cs" />
<Compile Include="infrastructure\commands\Execute.cs" />
<Compile Include="GetChocolatey.cs" />
<Compile Include="infrastructure.app\commands\ChocolateyConfigCommand.cs" />
<Compile Include="infrastructure.app\commands\ChocolateyFeatureCommand.cs" />
Expand Down Expand Up @@ -116,6 +122,9 @@
<Compile Include="infrastructure.app\services\IConfigTransformService.cs" />
<Compile Include="infrastructure.app\services\IFilesService.cs" />
<Compile Include="infrastructure.app\services\ISourceRunner.cs" />
<Compile Include="infrastructure\powershell\PoshHost.cs" />
<Compile Include="infrastructure\powershell\PoshHostRawUserInterface.cs" />
<Compile Include="infrastructure\powershell\PoshHostUserInterface.cs" />
<Compile Include="infrastructure.app\templates\ChocolateyReadMeTemplate.cs" />
<Compile Include="infrastructure.app\services\PythonService.cs" />
<Compile Include="infrastructure.app\services\RubyGemsService.cs" />
Expand Down Expand Up @@ -203,6 +212,7 @@
<Compile Include="infrastructure.app\domain\CommandNameType.cs" />
<Compile Include="infrastructure\events\EventManager.cs" />
<Compile Include="infrastructure\events\IEvent.cs" />
<Compile Include="infrastructure\commandline\ReadLineTimeout.cs" />
<Compile Include="infrastructure\registration\SimpleInjectorContainer.cs" />
<Compile Include="infrastructure\results\IResult.cs" />
<Compile Include="infrastructure\results\PackageResult.cs" />
Expand Down Expand Up @@ -288,4 +298,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>
1 change: 1 addition & 0 deletions src/chocolatey/infrastructure.app/ApplicationParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public static class Features
public static readonly string FailOnAutoUninstaller = "failOnAutoUninstaller";
public static readonly string AllowGlobalConfirmation = "allowGlobalConfirmation";
public static readonly string FailOnStandardError = "failOnStandardError";
public static readonly string UsePowerShellHost = "powershellHost";
}

public static class Messages
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ private static void set_feature_flags(ChocolateyConfiguration config, ConfigFile
config.Features.AutoUninstaller = set_feature_flag(ApplicationParameters.Features.AutoUninstaller, configFileSettings, defaultEnabled: true, description: "Uninstall from programs and features without requiring an explicit uninstall script.");
config.Features.FailOnAutoUninstaller = set_feature_flag(ApplicationParameters.Features.FailOnAutoUninstaller, configFileSettings, defaultEnabled: false, description: "Fail if automatic uninstaller fails.");
config.Features.FailOnStandardError = set_feature_flag(ApplicationParameters.Features.FailOnStandardError, configFileSettings, defaultEnabled: false, description: "Fail if install provider writes to stderr.");
config.Features.UsePowerShellHost = set_feature_flag(ApplicationParameters.Features.UsePowerShellHost, configFileSettings, defaultEnabled: true, description: "Use Chocolatey's built-in PowerShell host.");
config.PromptForConfirmation = !set_feature_flag(ApplicationParameters.Features.AllowGlobalConfirmation, configFileSettings, defaultEnabled: false, description: "Prompt for confirmation in scripts or bypass.");
}

Expand Down Expand Up @@ -264,6 +265,9 @@ private static void set_global_options(IList<string> args, ChocolateyConfigurati
.Add("failstderr|failonstderr|fail-on-stderr|fail-on-standard-error|fail-on-error-output",
"FailOnStandardError - Fail on standard error output (stderr), typically received when running external commands during install providers. This overrides the feature failOnStandardError.",
option => config.Features.FailOnStandardError = option != null)
.Add("use-system-powershell",
"UseSystemPowerShell - Execute PowerShell using an external process instead of the built-in PowerShell host.",
option => config.Features.UsePowerShellHost = option == null)
;
},
(unparsedArgs) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ public sealed class FeaturesConfiguration
public bool CheckSumFiles { get; set; }
public bool FailOnAutoUninstaller { get; set; }
public bool FailOnStandardError { get; set; }
public bool UsePowerShellHost { get; set; }
}

//todo: retrofit other command configs this way
Expand Down
Loading