diff --git a/src/Microsoft.PowerShell.CoreConsoleHost/main.cs b/src/Microsoft.PowerShell.CoreConsoleHost/main.cs
index ba3f0be18..697774b59 100644
--- a/src/Microsoft.PowerShell.CoreConsoleHost/main.cs
+++ b/src/Microsoft.PowerShell.CoreConsoleHost/main.cs
@@ -14,6 +14,30 @@ namespace Microsoft.PowerShell.CoreConsoleHost
public static class Program
{
+ private enum Options {Help, File, Command, NoProfile, NonInteractive, EncodedCommand, Invalid};
+ private class CommandOptions
+ {
+ public Options opt;
+ public string optString;
+
+ public CommandOptions(Options o, string s)
+ {
+ opt = o;
+ optString = s;
+ }
+ }
+
+ private static CommandOptions[] commandOptions = new CommandOptions[]
+ {
+ new CommandOptions(Options.Help, "help"),
+ new CommandOptions(Options.Help, "?"),
+ new CommandOptions(Options.File, "file"),
+ new CommandOptions(Options.Command, "command"),
+ new CommandOptions(Options.NoProfile, "noprofile"),
+ new CommandOptions(Options.NonInteractive, "noninteractive"),
+ new CommandOptions(Options.EncodedCommand, "encodedcommand")
+ };
+
///
/// Creates and initiates the listener instance.
///
@@ -25,6 +49,7 @@ namespace Microsoft.PowerShell.CoreConsoleHost
// here eliminates the need for a custom native host.
PowerShellAssemblyLoadContextInitializer.SetPowerShellAssemblyLoadContext(string.Empty);
+
// Argument parsing
string initialScript = null;
bool loadProfiles = true;
@@ -37,15 +62,33 @@ namespace Microsoft.PowerShell.CoreConsoleHost
bool hasNext = (i+1) < args.Length;
string nextArg = hasNext ? args[i+1] : string.Empty;
- // --help was specified
- if (arg == "--help" || arg == "-h")
+ // options start with "-" or "--"
+
+ string option;
+ if (arg.StartsWith("-"))
{
- Console.WriteLine(@"
-usage: powershell[.exe] [ (--help | -h) ]
+ if (arg.StartsWith("--"))
+ {
+ option = arg.Remove(0, 2);
+ }
+ else
+ {
+ option = arg.Remove(0, 1);
+ }
+
+ Options bestOption = FindOption(option);
+
+ switch (bestOption)
+ {
+ case Options.Help:
+ Console.WriteLine(@"
+usage: powershell[.exe] [ (--help | -h | -?) ]
[ (--file | -f) ]
[