Skip to content

Commit bbd1963

Browse files
add InputString to ExecutionOptions to override what goes in History and to the Host
1 parent 20ba99e commit bbd1963

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

src/PowerShellEditorServices/Services/PowerShellContext/Handlers/GetVersionHandler.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ private async Task CheckPackageManagement()
124124
{
125125
WriteInputToHost = true,
126126
WriteErrorsToHost = true,
127-
WriteOutputToHost = true
127+
WriteOutputToHost = true,
128+
InputString = "Install-Module -Name PackageManagement -Force -MinimumVersion 1.4.6 -Scope CurrentUser -AllowClobber"
128129
}).ConfigureAwait(false);
129130

130131
// There were errors installing PackageManagement.

src/PowerShellEditorServices/Services/PowerShellContext/PowerShellContextService.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ public async Task<IEnumerable<TResult>> ExecuteCommandAsync<TResult>(
597597
// cancelled prompt when it's called again.
598598
if (executionOptions.AddToHistory)
599599
{
600-
this.PromptContext.AddToHistory(psCommand.Commands[0].CommandText);
600+
this.PromptContext.AddToHistory(executionOptions.InputString ?? psCommand.Commands[0].CommandText);
601601
}
602602

603603
bool hadErrors = false;
@@ -686,7 +686,7 @@ public async Task<IEnumerable<TResult>> ExecuteCommandAsync<TResult>(
686686
if (executionOptions.WriteInputToHost)
687687
{
688688
this.WriteOutput(
689-
psCommand.Commands[0].CommandText,
689+
executionOptions.InputString ?? psCommand.Commands[0].CommandText,
690690
includeNewLine: true);
691691
}
692692

src/PowerShellEditorServices/Services/PowerShellContext/Session/ExecutionOptions.cs

+6
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ internal class ExecutionOptions
4646
/// </summary>
4747
public bool WriteInputToHost { get; set; }
4848

49+
/// <summary>
50+
/// If this is set, we will use this string for history and writing to the host
51+
/// instead of grabbing the command from the PSCommand.
52+
/// </summary>
53+
public string InputString { get; set; }
54+
4955
/// <summary>
5056
/// Gets or sets a value indicating whether the command to
5157
/// be executed is a console input prompt, such as the

0 commit comments

Comments
 (0)