diff --git a/assets/files.wxs b/assets/files.wxs
index cc24064ddb8..5d7b42ca97e 100644
--- a/assets/files.wxs
+++ b/assets/files.wxs
@@ -3108,6 +3108,9 @@
+
+
+
@@ -4110,6 +4113,7 @@
+
diff --git a/src/System.Management.Automation/System.Management.Automation.csproj b/src/System.Management.Automation/System.Management.Automation.csproj
index 187d3d7611e..bf5543607b8 100644
--- a/src/System.Management.Automation/System.Management.Automation.csproj
+++ b/src/System.Management.Automation/System.Management.Automation.csproj
@@ -29,6 +29,7 @@
+
diff --git a/src/System.Management.Automation/help/HelpCommands.cs b/src/System.Management.Automation/help/HelpCommands.cs
index 852db86c267..ca630180fbf 100644
--- a/src/System.Management.Automation/help/HelpCommands.cs
+++ b/src/System.Management.Automation/help/HelpCommands.cs
@@ -14,6 +14,8 @@
using System.Management.Automation.Internal;
using System.Management.Automation.Runspaces;
using System.Runtime.InteropServices;
+using System.Text;
+using Microsoft.PowerShell;
#if !UNIX
using Microsoft.Win32;
#endif
@@ -115,15 +117,21 @@ public SwitchParameter Detailed
[Parameter(ParameterSetName = "AllUsersView")]
public SwitchParameter Full
{
+ private get => _full;
+
set
{
- if (value.ToBool())
+ _full = value.ToBool();
+
+ if (_full)
{
_viewTokenToAdd = HelpView.FullView;
}
}
}
+ private bool _full;
+
///
/// Changes the view of HelpObject returned.
///
@@ -141,15 +149,24 @@ public SwitchParameter Full
[Parameter(ParameterSetName = "Examples", Mandatory = true)]
public SwitchParameter Examples
{
+ private get
+ {
+ return _examples;
+ }
+
set
{
- if (value.ToBool())
+ _examples = value.ToBool();
+
+ if (_examples)
{
_viewTokenToAdd = HelpView.ExamplesView;
}
}
}
+ private bool _examples;
+
///
/// Parameter name.
///
@@ -202,6 +219,23 @@ public SwitchParameter Online
private bool _showOnlineHelp;
+ ///
+ /// This parameter, if true, will direct get-help cmdlet to
+ /// display the help content using Microsoft.PowerShell.Pager on alternate screen buffer.
+ ///
+ [Parameter]
+ public SwitchParameter Paged
+ {
+ get;
+ set;
+ }
+
+ private Microsoft.PowerShell.Pager Pager => _pager ??= new Microsoft.PowerShell.Pager();
+
+ private Pager _pager;
+
+ private string _multiItemPagerBuffer;
+
#if !UNIX
private GraphicalHostReflectionWrapper graphicalHostReflectionWrapper;
private bool showWindow;
@@ -336,6 +370,10 @@ protected override void ProcessRecord()
{
throw PSTraceSource.NewInvalidOperationException(HelpErrors.MultipleOnlineTopicsNotSupported, "Online");
}
+ else if (Paged && countOfHelpInfos > 1)
+ {
+ Pager.Write(_multiItemPagerBuffer);
+ }
// show errors only if there is no wildcard search or VerboseHelpErrors is true.
if (((countOfHelpInfos == 0) && (!WildcardPattern.ContainsWildcardCharacters(helpRequest.Target)))
@@ -496,7 +534,7 @@ private void GetAndWriteParameterInfo(HelpInfo helpInfo)
{
foreach (PSObject pInfo in pInfos)
{
- WriteObject(pInfo);
+ WriteObjectPaged(pInfo, bufferOutputWhenPaged: false);
}
}
}
@@ -597,7 +635,7 @@ private void WriteObjectsOrShowOnlineHelp(HelpInfo helpInfo, bool showFullHelp)
{
PSObject objectToReturn = TransformView(helpInfo.FullHelp);
objectToReturn.IsHelpObject = true;
- WriteObject(objectToReturn);
+ WriteObjectPaged(objectToReturn, bufferOutputWhenPaged: false);
}
}
else
@@ -612,12 +650,92 @@ private void WriteObjectsOrShowOnlineHelp(HelpInfo helpInfo, bool showFullHelp)
}
}
- WriteObject(helpInfo.ShortHelp);
+ WriteObjectPaged(helpInfo.ShortHelp, bufferOutputWhenPaged: true);
}
}
}
}
+ private void WriteObjectPaged(object sendToPipeline, bool bufferOutputWhenPaged)
+ {
+ if (Paged)
+ {
+ var helpText = GetHelpOutput();
+
+ if (bufferOutputWhenPaged)
+ {
+ // The output from GetHelpOutput has all the item in the output.
+ // We just need to store it and then write to Pager later.
+ // No need to append them.
+ _multiItemPagerBuffer = helpText;
+ }
+ else
+ {
+ Pager.Write(helpText);
+ }
+ }
+ else
+ {
+ WriteObject(sendToPipeline);
+ }
+ }
+
+ private string GetHelpOutput()
+ {
+ using System.Management.Automation.PowerShell ps = System.Management.Automation.PowerShell.Create(RunspaceMode.CurrentRunspace);
+
+ ps.AddCommand(@"Microsoft.PowerShell.Core\Get-Help");
+
+ if (!string.IsNullOrEmpty(this.Name))
+ {
+ ps.AddParameter(nameof(this.Name), this.Name);
+ }
+
+ if (this.Category is not null)
+ {
+ ps.AddParameter(nameof(this.Category), this.Category);
+ }
+
+ if (this.Component is not null)
+ {
+ ps.AddParameter(nameof(this.Component), this.Component);
+ }
+
+ if (this.Functionality is not null)
+ {
+ ps.AddParameter(nameof(this.Functionality), this.Functionality);
+ }
+
+ if (!string.IsNullOrEmpty(this.Path))
+ {
+ ps.AddParameter(nameof(this.Path), this.Path);
+ }
+
+ if (this.Role is not null)
+ {
+ ps.AddParameter(nameof(this.Role), this.Role);
+ }
+
+ if (this.Examples)
+ {
+ ps.AddParameter(nameof(this.Examples), this.Examples);
+ }
+
+ if (this.Full)
+ {
+ ps.AddParameter(nameof(this.Full), this.Full);
+ }
+
+ if (this.Parameter is not null)
+ {
+ ps.AddParameter(nameof(this.Parameter), this.Parameter);
+ }
+
+ ps.AddCommand(@"Microsoft.PowerShell.Utility\Out-String");
+
+ return ps.Invoke().FirstOrDefault();
+ }
+
///
/// Opens the Uri. System's default application will be used
/// to show the uri.
@@ -888,4 +1006,3 @@ Uri result in
}
}
}
-