Skip to content

Found GetStringForPSCommand - moved parameter dump code into it #607

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

Merged
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
30 changes: 16 additions & 14 deletions src/PowerShellEditorServices/Session/PowerShellContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -534,20 +534,9 @@ await Task.Factory.StartNew<IEnumerable<TResult>>(

if (this.powerShell.HadErrors)
{
// Get the command/params that we were trying execute as a string in order to log it
string commandText = "";
foreach (var cmd in psCommand.Commands)
{
commandText += cmd.CommandText;
foreach (var param in cmd.Parameters)
{
commandText += $" -{param.Name} {param.Value}";
}
commandText += ";";
}

var strBld = new StringBuilder(1024);
strBld.Append($"Execution of command '{commandText}' completed with errors:\r\n\r\n");
strBld.AppendFormat("Execution of the following command(s) completed with errors:\r\n\r\n{0}\r\n",
GetStringForPSCommand(psCommand));

int i = 1;
foreach (var error in this.powerShell.Streams.Error)
Expand Down Expand Up @@ -1433,7 +1422,20 @@ private static string GetStringForPSCommand(PSCommand psCommand)
foreach (var command in psCommand.Commands)
{
stringBuilder.Append(" ");
stringBuilder.AppendLine(command.ToString());
stringBuilder.Append(command.CommandText);
foreach (var param in command.Parameters)
{
if (param.Name != null)
{
stringBuilder.Append($" -{param.Name} {param.Value}");
}
else
{
stringBuilder.Append($" {param.Value}");
}
}

stringBuilder.AppendLine();
}

return stringBuilder.ToString();
Expand Down