From f771812fce8cb3b4e9b5706d88a8b80694606efb Mon Sep 17 00:00:00 2001 From: Asaf Rosentswaig Date: Sun, 2 Jun 2019 18:38:35 +0300 Subject: [PATCH 1/4] Add ability to pass InitialSessionState to the ConsoleShell --- .../host/msh/ConsoleShell.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleShell.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleShell.cs index 6eb9059df18..db729da8eee 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleShell.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleShell.cs @@ -14,6 +14,24 @@ namespace Microsoft.PowerShell public static class ConsoleShell { + /// Entry point in to ConsoleShell. This method is called by main of minishell. + /// InitialSessionState to be used by the ConsoleHost + /// Banner text to be displayed by ConsoleHost. + /// Help text for minishell. This is displayed on 'minishell -?'. + /// Commandline parameters specified by user. + /// An integer value which should be used as exit code for the process. + public static int Start(InitialSessionState initialSessionState, string bannerText, string helpText, string[] args) + { + if (initialSessionState == null) + { + throw PSTraceSource.NewArgumentNullException("initialSessionState"); + } + + ConsoleHost.DefaultInitialSessionState = initialSessionState; + + return Start(bannerText, helpText, args); + } + /// Entry point in to ConsoleShell. This method is called by main of minishell. /// Banner text to be displayed by ConsoleHost. /// Help text for minishell. This is displayed on 'minishell -?'. From 28b959f65e6c9bc0ca588fbca44493298952982c Mon Sep 17 00:00:00 2001 From: Asaf Rosentswaig Date: Sun, 2 Jun 2019 19:22:49 +0300 Subject: [PATCH 2/4] revision 2 --- .../host/msh/ConsoleShell.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleShell.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleShell.cs index db729da8eee..d1c258ae304 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleShell.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleShell.cs @@ -14,8 +14,8 @@ namespace Microsoft.PowerShell public static class ConsoleShell { - /// Entry point in to ConsoleShell. This method is called by main of minishell. - /// InitialSessionState to be used by the ConsoleHost + /// Entry point in to ConsoleShell. + /// InitialSessionState to be used by the ConsoleHost. /// Banner text to be displayed by ConsoleHost. /// Help text for minishell. This is displayed on 'minishell -?'. /// Commandline parameters specified by user. @@ -24,7 +24,7 @@ public static int Start(InitialSessionState initialSessionState, string bannerTe { if (initialSessionState == null) { - throw PSTraceSource.NewArgumentNullException("initialSessionState"); + throw PSTraceSource.NewArgumentNullException(nameof(initialSessionState)); } ConsoleHost.DefaultInitialSessionState = initialSessionState; @@ -41,7 +41,7 @@ public static int Start(string bannerText, string helpText, string[] args) { if (args == null) { - throw PSTraceSource.NewArgumentNullException("args"); + throw PSTraceSource.NewArgumentNullException(nameof(args)); } return ConsoleHost.Start(bannerText, helpText, args); From 841994b4b3c9b47a26a157ed152ecddc841d3ffb Mon Sep 17 00:00:00 2001 From: Asaf Rosentswaig Date: Sun, 2 Jun 2019 19:26:37 +0300 Subject: [PATCH 3/4] revision 3 --- src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleShell.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleShell.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleShell.cs index d1c258ae304..c1f0b3c0dc9 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleShell.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleShell.cs @@ -14,10 +14,10 @@ namespace Microsoft.PowerShell public static class ConsoleShell { - /// Entry point in to ConsoleShell. + /// Entry point in to ConsoleShell. Used to create a custom Powershell console application /// InitialSessionState to be used by the ConsoleHost. /// Banner text to be displayed by ConsoleHost. - /// Help text for minishell. This is displayed on 'minishell -?'. + /// Help text for the shell. /// Commandline parameters specified by user. /// An integer value which should be used as exit code for the process. public static int Start(InitialSessionState initialSessionState, string bannerText, string helpText, string[] args) From 1c1992d1efb9a5fb60f7460b20ae83ea745349b3 Mon Sep 17 00:00:00 2001 From: Asaf Rosentswaig Date: Mon, 3 Jun 2019 19:15:38 +0300 Subject: [PATCH 4/4] revision 3 --- .../host/msh/ConsoleShell.cs | 25 ++++++++++--------- .../host/msh/ManagedEntrance.cs | 2 -- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleShell.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleShell.cs index c1f0b3c0dc9..51db1e5f36c 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleShell.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleShell.cs @@ -3,6 +3,7 @@ using System.Management.Automation; using System.Management.Automation.Runspaces; +using System.Runtime.CompilerServices; namespace Microsoft.PowerShell { @@ -14,6 +15,16 @@ namespace Microsoft.PowerShell public static class ConsoleShell { + /// Entry point in to ConsoleShell. This method is called by main of minishell. + /// Banner text to be displayed by ConsoleHost. + /// Help text for minishell. This is displayed on 'minishell -?'. + /// Commandline parameters specified by user. + /// An integer value which should be used as exit code for the process. + public static int Start(string bannerText, string helpText, string[] args) + { + return Start(InitialSessionState.CreateDefault2(), bannerText, helpText, args); + } + /// Entry point in to ConsoleShell. Used to create a custom Powershell console application /// InitialSessionState to be used by the ConsoleHost. /// Banner text to be displayed by ConsoleHost. @@ -27,23 +38,13 @@ public static int Start(InitialSessionState initialSessionState, string bannerTe throw PSTraceSource.NewArgumentNullException(nameof(initialSessionState)); } - ConsoleHost.DefaultInitialSessionState = initialSessionState; - - return Start(bannerText, helpText, args); - } - - /// Entry point in to ConsoleShell. This method is called by main of minishell. - /// Banner text to be displayed by ConsoleHost. - /// Help text for minishell. This is displayed on 'minishell -?'. - /// Commandline parameters specified by user. - /// An integer value which should be used as exit code for the process. - public static int Start(string bannerText, string helpText, string[] args) - { if (args == null) { throw PSTraceSource.NewArgumentNullException(nameof(args)); } + ConsoleHost.DefaultInitialSessionState = initialSessionState; + return ConsoleHost.Start(bannerText, helpText, args); } } diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ManagedEntrance.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ManagedEntrance.cs index 4094da9931d..b400f7ed0f4 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ManagedEntrance.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ManagedEntrance.cs @@ -63,8 +63,6 @@ public static int Start(string consoleFilePath, [MarshalAs(UnmanagedType.LPArray System.Diagnostics.Debugger.Break(); } #endif - ConsoleHost.DefaultInitialSessionState = InitialSessionState.CreateDefault2(); - int exitCode = 0; try {