From 72fd1838bf9f2369323b57b45915445416234d39 Mon Sep 17 00:00:00 2001 From: Ilya Date: Wed, 3 Jan 2018 23:25:01 +0500 Subject: [PATCH 1/2] Show short help if command line parameter is wrong --- .../host/msh/CommandLineParameterParser.cs | 13 +++++++++++-- .../host/msh/ManagedEntrance.cs | 2 +- .../resources/ManagedEntranceStrings.resx | 15 +++++++++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs index cbce5c675dc..d24ea531008 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs @@ -393,7 +393,14 @@ private void ShowHelp() { Dbg.Assert(_helpText != null, "_helpText should not be null"); _hostUI.WriteLine(""); - _hostUI.Write(_helpText); + if (_showFullHelp) + { + _hostUI.Write(ManagedEntranceStrings.ShellHelp); + } + else + { + _hostUI.Write(_helpText); + } _hostUI.WriteLine(""); } @@ -536,6 +543,7 @@ private void ParseHelper(string[] args) else if (MatchSwitch(switchKey, "help", "h") || MatchSwitch(switchKey, "?", "?")) { _showHelp = true; + _showFullHelp = true; _abortStartup = true; } else if (MatchSwitch(switchKey, "noexit", "noe")) @@ -955,7 +963,7 @@ bool TryGetBoolValue(string arg, out bool boolValue) } WriteCommandLineError( string.Format(CultureInfo.CurrentCulture, CommandLineParameterParserStrings.ArgumentFileDoesNotExist, args[i]), - showBanner: false); + showHelp: true); return false; } @@ -1164,6 +1172,7 @@ private bool CollectArgs(string[] args, ref int i) private string _configurationName; private PSHostUserInterface _hostUI; private bool _showHelp; + private bool _showFullHelp; private bool _showBanner = true; private bool _noInteractive; private string _bannerText; diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ManagedEntrance.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ManagedEntrance.cs index c8e233c20fb..f844ac65c55 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ManagedEntrance.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ManagedEntrance.cs @@ -74,7 +74,7 @@ public static int Start(string consoleFilePath, [MarshalAs(UnmanagedType.LPArray var formattedBanner = string.Format(CultureInfo.InvariantCulture, banner, PSVersionInfo.GitCommitId); exitCode = Microsoft.PowerShell.ConsoleShell.Start( formattedBanner, - ManagedEntranceStrings.ShellHelp, + ManagedEntranceStrings.ShortShellHelp, args); } catch (System.Management.Automation.Host.HostException e) diff --git a/src/Microsoft.PowerShell.ConsoleHost/resources/ManagedEntranceStrings.resx b/src/Microsoft.PowerShell.ConsoleHost/resources/ManagedEntranceStrings.resx index 46e84767cb0..d6816496d69 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/resources/ManagedEntranceStrings.resx +++ b/src/Microsoft.PowerShell.ConsoleHost/resources/ManagedEntranceStrings.resx @@ -123,6 +123,21 @@ Copyright (c) Microsoft Corporation. All rights reserved. https://aka.ms/pscore6-docs Type 'help' to get help. + + + Usage: pwsh[.exe] [[-File] <filePath> [args]] + [-Command { - | <script-block> [-args <arg-array>] + | <string> [<CommandParameters>] } ] + [-ConfigurationName <string>] [-EncodedCommand <Base64EncodedCommand>] + [-ExecutionPolicy <ExecutionPolicy>] [-InputFormat {Text | XML}] + [-Interactive] [-NoExit] [-NoLogo] [-NonInteractive] [-NoProfile] + [-OutputFormat {Text | XML}] [-Version] [-WindowStyle <style>] + + pwsh[.exe] -h | -Help | -? | /? + +PowerShell Online Help https://aka.ms/pscore6-docs + +All parameters are case-insensitive. Usage: pwsh[.exe] [[-File] <filePath> [args]] From eb1b06907688d1173463657511668e8b4012746a Mon Sep 17 00:00:00 2001 From: Ilya Date: Thu, 4 Jan 2018 23:35:20 +0500 Subject: [PATCH 2/2] Split Help message on Usage and Extended --- .../host/msh/CommandLineParameterParser.cs | 13 +++++-------- .../host/msh/ManagedEntrance.cs | 2 +- .../resources/ManagedEntranceStrings.resx | 18 +++--------------- 3 files changed, 9 insertions(+), 24 deletions(-) diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs index d24ea531008..0652b325344 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs @@ -393,13 +393,10 @@ private void ShowHelp() { Dbg.Assert(_helpText != null, "_helpText should not be null"); _hostUI.WriteLine(""); - if (_showFullHelp) + _hostUI.Write(_helpText); + if (_showExtendedHelp) { - _hostUI.Write(ManagedEntranceStrings.ShellHelp); - } - else - { - _hostUI.Write(_helpText); + _hostUI.Write(ManagedEntranceStrings.ExtendedHelp); } _hostUI.WriteLine(""); } @@ -543,7 +540,7 @@ private void ParseHelper(string[] args) else if (MatchSwitch(switchKey, "help", "h") || MatchSwitch(switchKey, "?", "?")) { _showHelp = true; - _showFullHelp = true; + _showExtendedHelp = true; _abortStartup = true; } else if (MatchSwitch(switchKey, "noexit", "noe")) @@ -1172,7 +1169,7 @@ private bool CollectArgs(string[] args, ref int i) private string _configurationName; private PSHostUserInterface _hostUI; private bool _showHelp; - private bool _showFullHelp; + private bool _showExtendedHelp; private bool _showBanner = true; private bool _noInteractive; private string _bannerText; diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ManagedEntrance.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ManagedEntrance.cs index f844ac65c55..b82b277b7bc 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ManagedEntrance.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ManagedEntrance.cs @@ -74,7 +74,7 @@ public static int Start(string consoleFilePath, [MarshalAs(UnmanagedType.LPArray var formattedBanner = string.Format(CultureInfo.InvariantCulture, banner, PSVersionInfo.GitCommitId); exitCode = Microsoft.PowerShell.ConsoleShell.Start( formattedBanner, - ManagedEntranceStrings.ShortShellHelp, + ManagedEntranceStrings.UsageHelp, args); } catch (System.Management.Automation.Host.HostException e) diff --git a/src/Microsoft.PowerShell.ConsoleHost/resources/ManagedEntranceStrings.resx b/src/Microsoft.PowerShell.ConsoleHost/resources/ManagedEntranceStrings.resx index d6816496d69..8bef56e8c24 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/resources/ManagedEntranceStrings.resx +++ b/src/Microsoft.PowerShell.ConsoleHost/resources/ManagedEntranceStrings.resx @@ -124,7 +124,7 @@ Copyright (c) Microsoft Corporation. All rights reserved. https://aka.ms/pscore6-docs Type 'help' to get help. - + Usage: pwsh[.exe] [[-File] <filePath> [args]] [-Command { - | <script-block> [-args <arg-array>] | <string> [<CommandParameters>] } ] @@ -139,20 +139,8 @@ PowerShell Online Help https://aka.ms/pscore6-docs All parameters are case-insensitive. - - Usage: pwsh[.exe] [[-File] <filePath> [args]] - [-Command { - | <script-block> [-args <arg-array>] - | <string> [<CommandParameters>] } ] - [-ConfigurationName <string>] [-EncodedCommand <Base64EncodedCommand>] - [-ExecutionPolicy <ExecutionPolicy>] [-InputFormat {Text | XML}] - [-Interactive] [-NoExit] [-NoLogo] [-NonInteractive] [-NoProfile] - [-OutputFormat {Text | XML}] [-Version] [-WindowStyle <style>] - - pwsh[.exe] -h | -Help | -? | /? - -PowerShell Online Help https://aka.ms/pscore6-docs - -All parameters are case-insensitive. + + -Command | -c Executes the specified commands (and any parameters) as though they were typed