├── test
└── Pester
│ ├── assets
│ ├── bad-commandhelp.md
│ ├── ThreadJob.md
│ ├── Bad.Metadata.Order.md
│ ├── Microsoft.PowerShell.Host.md
│ ├── Microsoft.PowerShell.Archive.md
│ ├── Microsoft.PowerShell.Diagnostics.md
│ ├── CBH_ASSET1.ps1
│ ├── Get-MPIOSetting.md
│ ├── PSDiagnostics.md
│ ├── New-EmptyCommand.md
│ ├── Exit-PSHostProcess.md
│ ├── PSReadLine.md
│ ├── CimCmdlets.md
│ ├── CimCmdlets2.md
│ ├── Microsoft.WSMan.Management.md
│ ├── Microsoft.PowerShell.Security.md
│ ├── Compare-CommandHelp2.md
│ ├── Out-Null.md
│ ├── Compare-CommandHelp.md
│ └── Microsoft.SystemCenter.ServiceManagementAutomation.md
│ ├── CommonFunction.ps1
│ ├── Miscellaneous.Tests.ps1
│ ├── YamlFormatting.Tests.ps1
│ ├── InteractiveExperience.Tests.ps1
│ ├── MeasurePlatyPSMarkdown.Tests.ps1
│ ├── MarkdownYaml.Tests.ps1
│ ├── ImportYamlCommandHelp.Tests.ps1
│ ├── TestMarkdownCommandHelp.Tests.ps1
│ ├── DiagnosticMessage.Tests.ps1
│ ├── ImportMamlHelp.Tests.ps1
│ ├── Model.Tests.ps1
│ ├── CompareCommandHelp.Tests.ps1
│ ├── GetMarkdownMetadata.Tests.ps1
│ ├── ParagraphFormatting.Tests.ps1
│ ├── ExportMarkdownModuleFile.Tests.ps1
│ └── ExportYamlModuleFile.Tests.ps1
├── global.json
├── src
├── AssemblyInfo.cs
├── Common
│ ├── CommandHelpWriterSettings.cs
│ ├── StringBuilderPool.cs
│ ├── YamlLayoutSerializer.cs
│ ├── OrderedSet.cs
│ ├── TransformationAttribute.cs
│ └── ParagraphFormatHelper.cs
├── YamlWriter
│ ├── YamlWriterSettings.cs
│ ├── QuotedNullStringEventEmitter.cs
│ ├── YamlConstants.cs
│ └── CommandHelpYamlWriterHelper.cs
├── MarkdownWriter
│ ├── MarkdownWriterSettings.cs
│ └── MarkdownConstants.cs
├── MamlWriter
│ ├── CommandLine.cs
│ ├── AlertSet.cs
│ ├── PipelineInputType.cs
│ ├── SyntaxItem.cs
│ ├── ParameterValue.cs
│ ├── CommandValue.cs
│ ├── CommandDetails.cs
│ ├── CommandExample.cs
│ ├── HelpItems.cs
│ ├── Constants.cs
│ ├── RelatedLink.cs
│ ├── MamlConstants.cs
│ ├── DataType.cs
│ └── Parameter.cs
├── Diagnostics
│ ├── DiagnosticMessageSource.cs
│ ├── DiagnosticSeverity.cs
│ ├── Diagnostics.cs
│ └── DiagnosticMessage.cs
├── MarkdownReader
│ ├── MarkdownProbe.cs
│ ├── MarkdownCommandHelpValidationResult.cs
│ ├── ModuleCommandInfo.cs
│ └── ModuleCommandGroup.cs
├── Transform
│ ├── TransformModule.cs
│ ├── TransformSettings.cs
│ └── TransformCommand.cs
├── Microsoft.PowerShell.PlatyPS.csproj
├── Command
│ ├── ConvertToCommandHelpCommand.cs
│ ├── ImportModuleFileCommand.cs
│ ├── Measure-PlatyPSMarkdown.cs
│ ├── TestMarkdownCommandHelp.cs
│ ├── ImportMamlCommand.cs
│ ├── ImportMarkdownCommand.cs
│ └── ImportYamlModuleFileCommand.cs
├── Model
│ ├── Links.cs
│ ├── Example.cs
│ ├── ParameterSet.cs
│ └── InputOutput.cs
└── Microsoft.PowerShell.PlatyPS.psd1
├── .vscode
├── settings.json
└── tasks.json
├── .config
├── suppress.json
└── tsaoptions.json
├── .github
├── CODEOWNERS
└── ISSUE_TEMPLATE.md
├── nuget.config
├── docs
├── README.md
└── archive
│ ├── alias-prototype.md
│ ├── platyps_2.0_about_schema.md
│ └── Schema-Notes.md
├── LICENSE
├── tools
└── releaseBuild
│ └── template
│ └── publish.yml
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── .ci
├── test.yml
└── ci.yml
├── platyPS.sln
├── ThirdPartyNotices.txt
├── README.md
└── .gitignore
/test/Pester/assets/bad-commandhelp.md:
--------------------------------------------------------------------------------
1 | echo # Bad Help
2 |
--------------------------------------------------------------------------------
/global.json:
--------------------------------------------------------------------------------
1 | {
2 | "sdk": {
3 | "version": "8.0.100",
4 | "rollForward": "latestMajor"
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/test/Pester/CommonFunction.ps1:
--------------------------------------------------------------------------------
1 | # Copyright (c) Microsoft Corporation.
2 | # Licensed under the MIT License.
3 |
4 | function normalizeEnds([string]$text)
5 | {
6 | $text -replace "`r`n?|`n", "`r`n"
7 | }
8 |
--------------------------------------------------------------------------------
/src/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System.Runtime.CompilerServices;
5 |
6 | [assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Microsoft.PowerShell.PlatyPS.Tests")]
7 |
--------------------------------------------------------------------------------
/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | // Place your settings in this file to overwrite default and user settings.
2 | {
3 | "files.exclude": {
4 | "out/**": true
5 | },
6 | "dotnet.defaultSolution": "platyPS.sln",
7 | "sarif-viewer.connectToGithubCodeScanning": "off"
8 | }
--------------------------------------------------------------------------------
/.config/suppress.json:
--------------------------------------------------------------------------------
1 | {
2 | "tool": "Credential Scanner",
3 | "suppressions": [
4 | {
5 | "file": "\\test\\Pester\\assets\\Microsoft.PowerShell.Commands.Utility.dll-Help.xml",
6 | "_justification": "Documentation example."
7 | }
8 | ]
9 | }
10 |
--------------------------------------------------------------------------------
/.github/CODEOWNERS:
--------------------------------------------------------------------------------
1 | # https://help.github.com/articles/about-codeowners/
2 |
3 | # These owners will be the default owners for everything in
4 | # the repo. Unless a later match takes precedence,
5 | # the following owners will be requested for
6 | # review when someone opens a pull request.
7 | * @adityapatwardhan @sdwheeler
8 |
--------------------------------------------------------------------------------
/.config/tsaoptions.json:
--------------------------------------------------------------------------------
1 | {
2 | "instanceUrl": "https://msazure.visualstudio.com",
3 | "projectName": "One",
4 | "areaPath": "One\\MGMT\\Compute\\Powershell\\Powershell\\PowerShell Core\\Platyps",
5 | "codebaseName": "TFSMSAzure_platyPS",
6 | "notificationAliases": [ "jimtru@microsoft.com", "slee@microsoft.com" ],
7 | "tools": [ "CredScan", "PoliCheck", "BinSkim" ]
8 | }
9 |
--------------------------------------------------------------------------------
/.vscode/tasks.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": "2.0.0",
3 | "tasks": [
4 | {
5 | "label": "build",
6 | "command": "dotnet",
7 | "type": "process",
8 | "args": [
9 | "build",
10 | "${workspaceFolder}/test/Markdown.MAML.Test/Markdown.MAML.Test.csproj"
11 | ],
12 | "problemMatcher": "$msCompile"
13 | }
14 | ]
15 | }
--------------------------------------------------------------------------------
/nuget.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | Steps to reproduce
7 | ------------------
8 |
9 |
10 | Expected behavior
11 | -----------------
12 |
13 |
14 | Actual behavior
15 | ---------------
16 |
17 |
18 | Environment data
19 | ----------------
20 |
21 |
22 |
23 | v0.5.0
24 |
--------------------------------------------------------------------------------
/docs/README.md:
--------------------------------------------------------------------------------
1 | # PlatyPS design documentation
2 |
3 | This folder contains design documentation for the PlatyPS project. The documentation is intended for
4 | contributors to the PlatyPS project and provides information on the design decisions, architecture,
5 | and implementation details of the module.
6 |
7 | The `archive` folder contains older versions of the design documents for reference. These documents
8 | don't reflect the current state of the project and are provided for historical context.
9 |
10 | New design documents will be added to this folder.
11 |
--------------------------------------------------------------------------------
/src/Common/CommandHelpWriterSettings.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System.Text;
5 |
6 | namespace Microsoft.PowerShell.PlatyPS
7 | {
8 | ///
9 | /// Settings for the command help writers.
10 | ///
11 | internal class WriterSettings
12 | {
13 | internal Encoding Encoding { get; set; }
14 | internal string DestinationPath { get; set; }
15 |
16 | public WriterSettings(Encoding encoding, string destinationPath)
17 | {
18 | Encoding = encoding;
19 | DestinationPath = destinationPath;
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/YamlWriter/YamlWriterSettings.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System.Text;
5 |
6 | namespace Microsoft.PowerShell.PlatyPS.YamlWriter
7 | {
8 | ///
9 | /// Settings for the yaml writer.
10 | ///
11 | internal class YamlWriterSettings
12 | {
13 | internal Encoding Encoding { get; set; }
14 | internal string DestinationPath { get; set; }
15 |
16 | public YamlWriterSettings(Encoding encoding, string destinationPath)
17 | {
18 | Encoding = encoding;
19 | DestinationPath = destinationPath;
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/MarkdownWriter/MarkdownWriterSettings.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System.Text;
5 |
6 | namespace Microsoft.PowerShell.PlatyPS.MarkdownWriter
7 | {
8 | ///
9 | /// Settings for the markdown writer.
10 | ///
11 | internal class MarkdownWriterSettings
12 | {
13 | internal Encoding Encoding { get; set; }
14 | internal string DestinationPath { get; set; }
15 |
16 | public MarkdownWriterSettings(Encoding encoding, string destinationPath)
17 | {
18 | Encoding = encoding;
19 | DestinationPath = destinationPath;
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/MamlWriter/CommandLine.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System.Xml.Serialization;
5 |
6 | namespace Microsoft.PowerShell.PlatyPS.MAML
7 | {
8 | ///
9 | /// Represents a "command" element in a Powershell MAML help document.
10 | ///
11 | [XmlRoot("commandLine", Namespace = Constants.XmlNamespace.Command)]
12 | public class CommandLine
13 | {
14 | ///
15 | /// The command text.
16 | ///
17 | [XmlElement("commandText", Namespace = Constants.XmlNamespace.Command)]
18 | public string CommandText { get; set; } = string.Empty;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/test/Pester/assets/ThreadJob.md:
--------------------------------------------------------------------------------
1 | ---
2 | Download Help Link: https://aka.ms/powershell75-help
3 | Help Version: 7.5.0.0
4 | Locale: en-US
5 | Module Guid: 0e7b895d-2fec-43f7-8cae-11e8d16f6e40
6 | Module Name: ThreadJob
7 | ms.date: 07/09/2019
8 | title: ThreadJob Module
9 | ---
10 |
11 | # ThreadJob Module
12 |
13 | ## Description
14 | This module extends the existing PowerShell BackgroundJob to include a new thread based
15 | **ThreadJob** job. This is a lighter weight solution for running concurrent PowerShell scripts that
16 | works within the existing PowerShell job infrastructure.
17 |
18 | ## ThreadJob Cmdlets
19 |
20 | ### [Start-ThreadJob](Start-ThreadJob.md)
21 | Creates background jobs similar to the `Start-Job` cmdlet.
22 |
--------------------------------------------------------------------------------
/src/Diagnostics/DiagnosticMessageSource.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | ///
5 | /// The diagnostic message source; Something that identifies the element to which diagnostic message pertains.
6 | ///
7 | public enum DiagnosticMessageSource
8 | {
9 | Metadata,
10 | Synopsis,
11 | Syntax,
12 | Alias,
13 | Description,
14 | Example,
15 | Parameter,
16 | Inputs,
17 | Outputs,
18 | Notes,
19 | Links,
20 | General,
21 | Merge,
22 | ModuleFileTitle,
23 | ModuleFileDescription,
24 | ModuleFileGroup,
25 | ModuleFileCommand,
26 | Identify
27 | }
--------------------------------------------------------------------------------
/src/MarkdownReader/MarkdownProbe.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System;
5 |
6 | namespace Microsoft.PowerShell.PlatyPS
7 | {
8 | ///
9 | /// A class used for probing markdown to determine its characteristics.
10 | ///
11 | public class MarkdownProbe
12 | {
13 | ///
14 | /// Identify the type of platyps file based on the path.
15 | ///
16 | /// The path to a markdown file.
17 | /// MarkdownProbeInfo
18 | public static MarkdownProbeInfo Identify(string path)
19 | {
20 | return new MarkdownProbeInfo(path);
21 | }
22 | }
23 | }
--------------------------------------------------------------------------------
/src/MamlWriter/AlertSet.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System.Collections.Generic;
5 | using System.Xml.Serialization;
6 |
7 | namespace Microsoft.PowerShell.PlatyPS.MAML
8 | {
9 | ///
10 | /// Represents a "command:syntaxItem" element in a Powershell MAML help document.
11 | ///
12 | public class AlertItem
13 | {
14 | ///
15 | /// The command name for this syntax.
16 | ///
17 | [XmlElement("para", Namespace = Constants.XmlNamespace.MAML, Order = 0)]
18 | public List Remark { get; set; }
19 |
20 | public AlertItem()
21 | {
22 | Remark = new();
23 | }
24 |
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/test/Pester/assets/Bad.Metadata.Order.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Bad.Metadata.Order
3 | Module Guid: 56d66100-99a0-4ffc-a12d-eee9a6718aef
4 | Module Name: Microsoft.PowerShell.Host
5 | Help Version: 7.5.0.0
6 | Locale: en-US
7 | ms.date: 06/09/2017
8 | Download Help Link: https://aka.ms/powershell75-help
9 | PlatyPS version schema: 2024-05-01
10 | ---
11 |
12 | # Bad.Metadata.Order Module
13 |
14 | ## Description
15 |
16 | This section contains the help topics for the cmdlets that are installed with the PowerShell
17 | Microsoft.PowerShell.Host module. The Host module contains cmdlets that manage data from host
18 | programs.
19 |
20 | ## Bad.Metadata.Order Cmdlets
21 |
22 | ### [Start-Transcript](Start-Transcript.md)
23 | Creates a record of all or part of a PowerShell session to a text file.
24 |
25 | ### [Stop-Transcript](Stop-Transcript.md)
26 | Stops a transcript.
27 |
28 |
--------------------------------------------------------------------------------
/test/Pester/assets/Microsoft.PowerShell.Host.md:
--------------------------------------------------------------------------------
1 | ---
2 | Download Help Link: https://aka.ms/powershell75-help
3 | Help Version: 7.5.0.0
4 | Locale: en-US
5 | Module Guid: 56d66100-99a0-4ffc-a12d-eee9a6718aef
6 | Module Name: Microsoft.PowerShell.Host
7 | ms.date: 06/09/2017
8 | schema: 2.0.0
9 | title: Microsoft.PowerShell.Host
10 | ---
11 | # Microsoft.PowerShell.Host Module
12 |
13 | ## Description
14 |
15 | This section contains the help topics for the cmdlets that are installed with the PowerShell
16 | Microsoft.PowerShell.Host module. The Host module contains cmdlets that manage data from host
17 | programs.
18 |
19 | ## Microsoft.PowerShell.Host Cmdlets
20 |
21 | ### [Start-Transcript](Start-Transcript.md)
22 | Creates a record of all or part of a PowerShell session to a text file.
23 |
24 | ### [Stop-Transcript](Stop-Transcript.md)
25 | Stops a transcript.
26 |
27 |
--------------------------------------------------------------------------------
/src/Diagnostics/DiagnosticSeverity.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System;
5 | using System.Collections;
6 | using System.Collections.Generic;
7 |
8 | namespace Microsoft.PowerShell.PlatyPS.Model
9 | {
10 | public enum DiagnosticSeverity
11 | {
12 | ///
13 | /// The diagnostic message represents an error.
14 | ///
15 | Error = 0,
16 |
17 | ///
18 | /// The diagnostic message represents a warning.
19 | ///
20 | Warning = 1,
21 |
22 | ///
23 | /// The diagnostic message represents an information message.
24 | ///
25 | Information = 2,
26 |
27 | ///
28 | /// The diagnostic message represents a hint.
29 | ///
30 | Hint = 3
31 | }
32 | }
--------------------------------------------------------------------------------
/test/Pester/assets/Microsoft.PowerShell.Archive.md:
--------------------------------------------------------------------------------
1 | ---
2 | Download Help Link: https://aka.ms/powershell75-help
3 | Help Version: 7.5.0.0
4 | Locale: en-US
5 | Module Guid: eb74e8da-9ae2-482a-a648-e96550fb8733
6 | Module Name: Microsoft.PowerShell.Archive
7 | ms.date: 06/09/2017
8 | schema: 2.0.0
9 | title: Microsoft.PowerShell.Archive
10 | ---
11 |
12 | # Microsoft.PowerShell.Archive Module
13 |
14 | ## Description
15 |
16 | This section contains the help topics for the cmdlets that are installed with the PowerShell Microsoft.PowerShell.Archive module. The Archive module contains cmdlets that let you create and extract archive or ZIP files.
17 |
18 | ## Microsoft.PowerShell.Archive Cmdlets
19 |
20 | ### [Compress-Archive](Compress-Archive.md)
21 | Creates a compressed archive, or zipped file, from specified files and directories.
22 |
23 | ### [Expand-Archive](Expand-Archive.md)
24 | Extracts files from a specified archive (zipped) file.
25 |
26 |
--------------------------------------------------------------------------------
/src/MamlWriter/PipelineInputType.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Xml.Serialization;
3 |
4 | namespace Microsoft.PowerShell.PlatyPS.MAML
5 | {
6 | ///
7 | /// Supported Powershell pipeline input types for Cmdlet parameters.
8 | ///
9 | [Flags]
10 | public enum PipelineInputType
11 | {
12 | ///
13 | /// Parameter does not take its value from the pipeline.
14 | ///
15 | [XmlEnum("false")]
16 | None = 0,
17 |
18 | ///
19 | /// Parameter can take its value from the pipeline.
20 | ///
21 | [XmlEnum("true (ByValue)")]
22 | ByValue = 1,
23 |
24 | ///
25 | /// Parameter can take its value from a property of the same name on objects in the pipeline.
26 | ///
27 | [XmlEnum("true (ByPropertyName)")]
28 | ByPropertyName = 2
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/MamlWriter/SyntaxItem.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System.Collections.Generic;
5 | using System.Xml.Serialization;
6 |
7 | namespace Microsoft.PowerShell.PlatyPS.MAML
8 | {
9 | ///
10 | /// Represents a "command:syntaxItem" element in a Powershell MAML help document.
11 | ///
12 | public class SyntaxItem
13 | {
14 | ///
15 | /// The command name for this syntax.
16 | ///
17 | [XmlElement("name", Namespace = Constants.XmlNamespace.MAML, Order = 0)]
18 | public string CommandName { get; set; } = string.Empty;
19 |
20 | ///
21 | /// The command parameters associated with this syntax.
22 | ///
23 | [XmlElement("parameter", Namespace = Constants.XmlNamespace.Command, Order = 1)]
24 | public List Parameters = new List();
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/MamlWriter/ParameterValue.cs:
--------------------------------------------------------------------------------
1 | using System.Xml.Serialization;
2 |
3 | namespace Microsoft.PowerShell.PlatyPS.MAML
4 | {
5 | ///
6 | /// Represents a "parameterValue" element in a Powershell MAML help document.
7 | ///
8 | [XmlRoot("parameterValue", Namespace = Constants.XmlNamespace.Command)]
9 | public class ParameterValue
10 | {
11 | ///
12 | /// The parameter data-type ("#text").
13 | ///
14 | [XmlText]
15 | public string DataType { get; set; } = string.Empty;
16 |
17 | ///
18 | /// Is the parameter mandatory?
19 | ///
20 | [XmlAttribute("required")]
21 | public bool IsMandatory { get; set; }
22 |
23 | ///
24 | /// Is the parameter's data type variable-length?
25 | ///
26 | [XmlAttribute("variableLength")]
27 | public bool IsVariableLength { get; set; }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/YamlWriter/QuotedNullStringEventEmitter.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System.Runtime.Remoting.Metadata.W3cXsd2001;
5 | using YamlDotNet.Core;
6 | using YamlDotNet.Core.Events;
7 | using YamlDotNet.Serialization;
8 | using YamlDotNet.Serialization.EventEmitters;
9 |
10 | public class QuotedNullStringEventEmitter : ChainedEventEmitter
11 | {
12 | public QuotedNullStringEventEmitter(IEventEmitter nextEmitter) : base(nextEmitter)
13 | {
14 | }
15 |
16 | public override void Emit(ScalarEventInfo eventInfo, YamlDotNet.Core.IEmitter emitter)
17 | {
18 | if (eventInfo.Source.Type == typeof(string) && string.Equals(eventInfo.Source.Value?.ToString() , "NULL", System.StringComparison.OrdinalIgnoreCase))
19 | {
20 | emitter.Emit(new Scalar(@"'NULL'"));
21 | }
22 | else
23 | {
24 | // For all other values, use the default emitter
25 | base.Emit(eventInfo, emitter);
26 | }
27 | }
28 | }
--------------------------------------------------------------------------------
/src/MarkdownReader/MarkdownCommandHelpValidationResult.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System;
5 | using System.Collections.Generic;
6 |
7 | namespace Microsoft.PowerShell.PlatyPS
8 | {
9 | public class MarkdownCommandHelpValidationResult
10 | {
11 | public string Path { get; set; }
12 | public bool IsValid { get; set; }
13 | public List Messages { get; set; }
14 | public MarkdownCommandHelpValidationResult()
15 | {
16 | Path = string.Empty;
17 | IsValid = true;
18 | Messages = new List();
19 | }
20 |
21 | public MarkdownCommandHelpValidationResult(string path, bool isValid, List messages)
22 | {
23 | Path = path;
24 | IsValid = isValid;
25 | Messages = messages;
26 | }
27 |
28 | public override string ToString()
29 | {
30 | return $"Path: {Path}, IsValid: {IsValid}";
31 | }
32 |
33 | }
34 | }
--------------------------------------------------------------------------------
/test/Pester/Miscellaneous.Tests.ps1:
--------------------------------------------------------------------------------
1 | # Copyright (c) Microsoft Corporation.
2 | # Licensed under the MIT License.
3 |
4 | Describe "Miscellaneous tests" {
5 | Context "Alias preservation" {
6 | BeforeAll {
7 | $cmdHelpPath = [io.path]::Combine($PSScriptRoot, "assets", "Get-ChildItem.V2.md")
8 | $ch_md = Import-MarkdownCommandHelp $cmdHelpPath
9 | $fPath = $ch_md | Export-YamlCommandHelp -output $TESTDRIVE -Force
10 | $ch_yaml = Import-YamlCommandHelp $fPath
11 | }
12 |
13 | It "Should preserve the aliases" {
14 | $ch_md.Aliases | Should -Not -BeNullOrEmpty
15 | $ch_md.Aliases | Should -Be $ch_yaml.Aliases
16 | }
17 |
18 | It "Should have the correct diagnostic message from the markdown parse" {
19 | $message = $ch_md.Diagnostics.Messages.Where({$_.source -eq "alias" -and $_.Identifier -match "length"})
20 | $message | Should -Not -BeNullOrEmpty
21 | $message.Identifier | Should -Match "118"
22 | }
23 |
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/Transform/TransformModule.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System.Collections.ObjectModel;
5 | using System.Management.Automation;
6 |
7 | using Microsoft.PowerShell.PlatyPS.Model;
8 |
9 | namespace Microsoft.PowerShell.PlatyPS
10 | {
11 | internal class TransformModule : TransformBase
12 | {
13 | public TransformModule(TransformSettings settings) : base(settings)
14 | {
15 | }
16 |
17 | internal override Collection Transform(string[] moduleNames)
18 | {
19 | Collection cmdHelp = new();
20 |
21 | foreach (var module in moduleNames)
22 | {
23 | Collection cmdletInfos = PowerShellAPI.GetCmdletInfoFromModule(module, Settings.Session);
24 |
25 | foreach (var cmdletInfo in cmdletInfos)
26 | {
27 | cmdHelp.Add(ConvertCmdletInfo(cmdletInfo));
28 | }
29 | }
30 |
31 | return cmdHelp;
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/test/Pester/assets/Microsoft.PowerShell.Diagnostics.md:
--------------------------------------------------------------------------------
1 | ---
2 | Download Help Link: https://aka.ms/powershell75-help
3 | Help Version: 7.5.0.0
4 | Locale: en-US
5 | Module Guid: ca046f10-ca64-4740-8ff9-2565dba61a4f
6 | Module Name: Microsoft.PowerShell.Diagnostics
7 | ms.date: 06/09/2017
8 | schema: 2.0.0
9 | title: Microsoft.PowerShell.Diagnostics
10 | ---
11 | # Microsoft.PowerShell.Diagnostics Module
12 |
13 | ## Description
14 |
15 | This section contains the help topics for the cmdlets that are installed with the PowerShell
16 | Microsoft.PowerShell.Diagnostics module, which contains cmdlets that manage data from event logs.
17 |
18 | This module is only available on the Windows platform.
19 |
20 | ## Microsoft.PowerShell.Diagnostics Cmdlets
21 |
22 | ### [Get-Counter](Get-Counter.md)
23 | Gets performance counter data from local and remote computers.
24 |
25 | ### [Get-WinEvent](Get-WinEvent.md)
26 | Gets events from event logs and event tracing log files on local and remote computers.
27 |
28 | ### [New-WinEvent](New-WinEvent.md)
29 | Creates a new Windows event for the specified event provider.
30 |
31 |
--------------------------------------------------------------------------------
/src/MamlWriter/CommandValue.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System.Collections.Generic;
5 | using System.Xml.Serialization;
6 |
7 | namespace Microsoft.PowerShell.PlatyPS.MAML
8 | {
9 | ///
10 | /// Represents a "command:inputType" or "command:returnValue" element in a Powershell MAML help document.
11 | ///
12 | public class CommandValue
13 | {
14 | ///
15 | /// The value data-type.
16 | ///
17 | [XmlElement("type", Namespace = Constants.XmlNamespace.Dev, Order = 0)]
18 | public DataType DataType { get; set; } = new DataType();
19 |
20 | ///
21 | /// The value's detailed description (one or more paragraphs; "maml:description/maml:para").
22 | ///
23 | [XmlArray("description", Namespace = Constants.XmlNamespace.MAML, Order = 1)]
24 | [XmlArrayItem("para", Namespace = Constants.XmlNamespace.MAML)]
25 | public List Description { get; set; } = new List();
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/test/Pester/YamlFormatting.Tests.ps1:
--------------------------------------------------------------------------------
1 | # Copyright (c) Microsoft Corporation.
2 | # Licensed under the MIT License.
3 |
4 | Describe 'Yaml formatting tests' {
5 | It 'Inputs output and notes should have empty array when empty' {
6 | Import-MarkdownCommandHelp -Path 'assets/New-EmptyCommand.md' | Export-YamlCommandHelp -OutputFolder $TestDrive
7 | $yaml = Get-Content "$TestDrive/New-EmptyCommand.yml" -Raw
8 |
9 | $isWinPS = $PSVersionTable.PSVersion.Major -eq 5
10 |
11 | $inputPattern = if ($IsWindows -or $IsWinPS) { 'inputs:\r\n- name: System\.String\r\n description: ''' } else { 'inputs:\n- name: System\.String\n description: ''' }
12 | $outputPattern = if ($IsWindows -or $IsWinPS) { 'outputs:\r\n- name: System\.String\r\n description: ''' } else { 'outputs:\n- name: System\.String\n description: ''' }
13 | $notesPattern = "notes: ''"
14 | $linksPattern = "links: \[\]"
15 |
16 | $yaml | Should -Match $inputPattern
17 | $yaml | Should -Match $outputPattern
18 | $yaml | Should -Match $notesPattern
19 | $yaml | Should -Match $linksPattern
20 | }
21 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 Microsoft Corporation.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in
13 | all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | THE SOFTWARE.
22 |
--------------------------------------------------------------------------------
/test/Pester/assets/CBH_ASSET1.ps1:
--------------------------------------------------------------------------------
1 | <#
2 | .SYNOPSIS
3 | Adds a file name extension to a supplied name.
4 | .DESCRIPTION
5 | Adds a file name extension to a supplied name.
6 | Takes any strings for the file name or extension.
7 |
8 | ```powershell
9 | PS> echo 'code block 1'
10 | ```
11 |
12 | more explanation
13 |
14 | ```powershell
15 | PS> echo 'code block 2'
16 | ```
17 |
18 | even more explanations
19 |
20 | .PARAMETER Second
21 | Second parameter help description
22 | .OUTPUTS
23 | System.String. Add-Extension returns a string with the extension or file name.
24 | .EXAMPLE
25 | PS C:\> Test-PlatyPSFunction "File"
26 | File.txt
27 | .EXAMPLE
28 | PS C:\> Test-PlatyPSFunction "File" -First "doc"
29 | File.doc
30 | .LINK
31 | http://www.fabrikam.com/extension.html
32 | .LINK
33 | Set-Item
34 | #>
35 |
36 | param(
37 | [Parameter(Mandatory=$true)]
38 | [String]$MustHave,
39 | [Switch]$Common,
40 | [Parameter(ParameterSetName="First", HelpMessage = 'First parameter help description')]
41 | [string]$First,
42 | [Parameter(ParameterSetName="Second")]
43 | [string]$Second
44 | )
45 |
46 | Write-Output "Common: $Common - Second: $Second"
47 |
--------------------------------------------------------------------------------
/src/Transform/TransformSettings.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System;
5 | using System.Collections;
6 | using System.Globalization;
7 | using System.Management.Automation.Runspaces;
8 |
9 | namespace Microsoft.PowerShell.PlatyPS
10 | {
11 | public class TransformSettings
12 | {
13 | public string? FwLink { get; set; }
14 | public string? HelpVersion { get; set; }
15 | public CultureInfo Locale { get; set; }
16 | public Hashtable? Metadata { get; set; }
17 | public Guid? ModuleGuid { get; set; }
18 | public string? ModuleName { get; set; }
19 | public string? OnlineVersionUrl { get; set; }
20 | public bool? CreateModulePage { get; set; }
21 | public bool? DoubleDashList { get; set; }
22 | public bool? UseFullTypeName { get; set; }
23 | public PSSession? Session { get; set; }
24 | public bool? ExcludeDontShow { get; set; }
25 |
26 | public TransformSettings()
27 | {
28 | Locale = CultureInfo.CurrentCulture;
29 | }
30 |
31 | public TransformSettings(CultureInfo cultureInfo)
32 | {
33 | Locale = cultureInfo;
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/docs/archive/alias-prototype.md:
--------------------------------------------------------------------------------
1 | ---
2 | external help file: Microsoft.PowerShell.Commands.Management.dll-Help.xml
3 | Locale: en-US
4 | Module Name: Microsoft.PowerShell.Management
5 | ms.date: 12/05/2023
6 | online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.management/get-childitem?view=powershell-7.2&WT.mc_id=ps-gethelp
7 | schema: 2.0.0
8 | title: Get-ChildItem
9 | alias: [dir, gci, ls]
10 | ---
11 | # Get-ChildItem
12 |
13 | ## SYNOPSIS
14 |
15 | Gets the items and child items in one or more specified locations.
16 |
17 | ## ALIASES
18 |
19 | PowerShell includes the following aliases for `Get-ChildItem`:
20 |
21 | - All platforms: `dir`, `gci`
22 | - Windows: `ls`
23 |
24 | ## SYNTAX
25 |
26 | ### Items (Default)
27 |
28 | ```
29 | Get-ChildItem [[-Path] ] [[-Filter] ] [-Include ] [-Exclude ]
30 | [-Recurse] [-Depth ] [-Force] [-Name] [-Attributes ]
31 | [-FollowSymlink] [-Directory] [-File] [-Hidden] [-ReadOnly] [-System] []
32 | ```
33 |
34 | ### LiteralItems
35 |
36 | ```
37 | Get-ChildItem [[-Filter] ] -LiteralPath [-Include ]
38 | [-Exclude ] [-Recurse] [-Depth ] [-Force] [-Name]
39 | [-Attributes ] [-FollowSymlink] [-Directory] [-File] [-Hidden]
40 | [-ReadOnly] [-System] []
41 | ```
42 |
--------------------------------------------------------------------------------
/test/Pester/assets/Get-MPIOSetting.md:
--------------------------------------------------------------------------------
1 | ---
2 | external help file: MPIO_Cmdlets.xml
3 | Module Name: MPIO
4 | online version: https://learn.microsoft.com/powershell/module/mpio/get-mpiosetting?view=windowsserver2012-ps&wt.mc_id=ps-gethelp
5 | schema: 2.0.0
6 | title: Get-MPIOSetting
7 | ---
8 | # Get-MPIOSetting
9 |
10 | ## SYNOPSIS
11 | Gets MPIO settings.
12 |
13 | ## SYNTAX
14 |
15 | ```
16 | Get-MPIOSetting
17 | ```
18 |
19 | ## DESCRIPTION
20 | The **Get-MPIOSetting** cmdlet gets Microsoft Multipath I/O (MPIO) settings.
21 | The settings are as follows:
22 |
23 | - PathVerificationState
24 | - PathVerificationPeriod
25 | - PDORemovePeriod
26 | - RetryCount
27 | - RetryInterval
28 | - UseCustomPathRecoveryTime
29 | - CustomPathRecoveryTime
30 | - DiskTimeoutValue
31 |
32 | You can use the **Set-MPIOSetting** cmdlet to change these values.
33 |
34 | ## EXAMPLES
35 |
36 | ### Example 1: Get MPIO settings
37 | ```
38 | PS C:\>Get-MPIOSetting
39 |
40 | PathVerificationState : Disabled
41 | PathVerificationPeriod : 30
42 | PDORemovePeriod : 20
43 | RetryCount : 3
44 | RetryInterval : 1
45 | UseCustomPathRecoveryTime : Disabled
46 | CustomPathRecoveryTime : 40
47 | DiskTimeoutValue : 120
48 | ```
49 |
50 | This command gets the MPIO settings.
51 |
52 | ## PARAMETERS
53 |
54 | ## INPUTS
55 |
56 | ## OUTPUTS
57 |
58 | ## NOTES
59 |
60 | ## RELATED LINKS
61 |
62 | [Set-MPIOSetting](./Set-MPIOSetting.md)
63 |
--------------------------------------------------------------------------------
/src/Common/StringBuilderPool.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System;
5 | using System.Collections.Concurrent;
6 | using System.Collections.Generic;
7 | using System.Linq;
8 | using System.Text;
9 | using System.Threading.Tasks;
10 |
11 | namespace Microsoft.PowerShell.PlatyPS
12 | {
13 | internal class StringBuilderPool
14 | {
15 | private readonly ConcurrentBag _stringBuilders;
16 |
17 | internal int InitialCapacity { get; set; } = 5000;
18 |
19 | internal int MaximumRetainedCapacity { get; set; } = 3 * 5000;
20 |
21 | public StringBuilderPool()
22 | {
23 | _stringBuilders = new ConcurrentBag();
24 | }
25 |
26 | internal StringBuilder Get()
27 | {
28 | if (_stringBuilders.TryTake(out StringBuilder? sb))
29 | {
30 | return sb;
31 | }
32 | else
33 | {
34 | return new StringBuilder(InitialCapacity);
35 | }
36 | }
37 |
38 | internal bool Return(StringBuilder sb)
39 | {
40 | if(sb.Capacity > MaximumRetainedCapacity)
41 | {
42 | // Too big. Discard this one.
43 | return false;
44 | }
45 |
46 | sb.Clear();
47 |
48 | _stringBuilders.Add(sb);
49 |
50 | return true;
51 | }
52 |
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/test/Pester/InteractiveExperience.Tests.ps1:
--------------------------------------------------------------------------------
1 | # Copyright (c) Microsoft Corporation.
2 | # Licensed under the MIT License.
3 |
4 | Describe "Interactive experience tests" {
5 | Context "Encoding parameter tab completion" {
6 | BeforeAll {
7 | $cmdletsWithEncodingParameter = Get-Command -Module Microsoft.PowerShell.PlatyPS |
8 | Where-Object { $_.Parameters['Encoding'] }
9 | $expectedEncoding = "ansi", "ascii", "bigendianunicode", "bigendianutf32", "unicode", "utf7", "utf8", "utf8BOM", "utf8NoBOM", "utf32"
10 | }
11 |
12 | It "'' has the appropriate attributes on the Encoding parameter" -TestCases $(
13 | $cmdletsWithEncodingParameter | Foreach-Object {
14 | @{ Cmdlet = $_.Name; Parameter = $_.Parameters['Encoding'] }
15 | }
16 | ) {
17 | param ($cmdlet, $parameter)
18 | $parameter.Attributes.Where({$_ -is [System.Management.Automation.ArgumentCompleterAttribute]}) | Should -Not -BeNullOrEmpty
19 | }
20 |
21 | It "tabexpansion for '' completes the Encoding parameter correctly" -TestCases $(
22 | $cmdletsWithEncodingParameter | Foreach-Object {
23 | @{ Cmdlet = $_.Name }
24 | }
25 | ) {
26 | param ($cmdlet)
27 | $cmdString = "$cmdlet -Encoding "
28 | $result = TabExpansion2 $cmdString $cmdString.Length
29 | $result.CompletionMatches.CompletionText | Should -Be $expectedEncoding
30 | }
31 | }
32 | }
--------------------------------------------------------------------------------
/src/Microsoft.PowerShell.PlatyPS.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | PlatyPS
5 | Microsoft Corporation
6 | (c) Microsoft Corporation.
7 |
8 | net472
9 | true
10 | true
11 | latest
12 | true
13 | enable
14 | true
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 | True
27 | True
28 | Microsoft.PowerShell.PlatyPS.Resources.resx
29 |
30 |
31 |
32 |
33 |
34 | ResXFileCodeGenerator
35 | Microsoft.PowerShell.PlatyPS.Resources.Designer.cs
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/tools/releaseBuild/template/publish.yml:
--------------------------------------------------------------------------------
1 | parameters:
2 | stageName: ''
3 | environmentName: ''
4 | feedCredential: ''
5 |
6 | stages:
7 | - stage: ${{ parameters.stageName }}
8 | displayName: Release Microsoft.PowerShell.PlatyPS to '${{ parameters.stageName }}'
9 | condition: and(succeeded(), eq(variables['Build.Reason'], 'Manual'), startsWith(variables['Build.SourceBranch'], 'refs/heads/release'))
10 |
11 | jobs:
12 | - deployment: Publish_${{ parameters.stageName }}
13 | displayName: Release to Feed
14 | pool:
15 | name: 1ES
16 |
17 | environment: ${{ parameters.environmentName }}
18 | strategy:
19 | runOnce:
20 | deploy:
21 | steps:
22 | - download: current
23 | artifact: nuget
24 |
25 | - pwsh: |
26 | $package = (Get-ChildItem "$(Pipeline.Workspace)/nuget/Microsoft.PowerShell.PlatyPS.*.nupkg").FullName
27 | $package
28 | $vstsCommandString = "vso[task.setvariable variable=NugetPkgPath]${package}"
29 | Write-Host "sending " + $vstsCommandString
30 | Write-Host "##$vstsCommandString"
31 | displayName: Capture downloaded artifact
32 |
33 | - task: NuGetAuthenticate@0
34 | condition: ne('${{ parameters.feedUrl }}', '')
35 |
36 | - task: NuGetCommand@2
37 | displayName: 'NuGet push'
38 | inputs:
39 | command: push
40 | packagesToPush: '$(NugetPkgPath)'
41 | nuGetFeedType: external
42 | publishFeedCredentials: ${{ parameters.feedCredential }}
43 | condition: eq('${{ parameters.feedUrl }}', '')
44 |
--------------------------------------------------------------------------------
/docs/archive/platyps_2.0_about_schema.md:
--------------------------------------------------------------------------------
1 | # Schema for About_ files
2 |
3 | The following sections outline schema changes for the About_ file.
4 |
5 | | Heading | Level | Required? | Count | Description |
6 | | ----------------- | ----- | --------- | ----- | ------------------------------------------------------------------------------------------------------------------------- |
7 | | Title | H1 | Y | 1 | - Title should be Sentence Case - About Topic
- Title meta data 'about_' should match the file basename |
8 | | Short Description | H2 | Y | 1 | - Should be Sentence Case |
9 | | Long Description | H2 | Y | 1 | - Should be Sentence case
- Should allow multiple Long description subtopics
- Should support subtopics at H3 or H2 |
10 | | See Also | H2 | Y | 1 | - This is required but may be empty |
11 |
12 | General notes
13 |
14 | - Should be rendered as plain text compatible with `Get-Help`
15 | - `Get-Help` bug:Synopsis
16 | - [Get-Help bug][05]
17 | - Add switch to provide Cabs or Zips. Default: cabs
18 | - Add switch to include markdown Default: off
19 | - About_ schema does not say anything about line wrapping etc.
20 | - If left as text files, then wrap at 80 columns.
21 | - But if converted to schema-based line limit isn't a problem (for the future). Still a problem
22 | for previous versions.
23 |
--------------------------------------------------------------------------------
/src/MamlWriter/CommandDetails.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System.Collections.Generic;
5 | using System.Xml.Serialization;
6 |
7 | namespace Microsoft.PowerShell.PlatyPS.MAML
8 | {
9 | ///
10 | /// Represents the "details" element under a "command" element in a Powershell MAML help document.
11 | ///
12 | [XmlRoot("details", Namespace = Constants.XmlNamespace.Command)]
13 | public class CommandDetails
14 | {
15 | ///
16 | /// The Cmdlet name.
17 | ///
18 | [XmlElement("name", Namespace = Constants.XmlNamespace.Command, Order = 0)]
19 | public string Name { get; set; } = string.Empty;
20 |
21 | ///
22 | /// The command synopsis (one or more paragraphs; "maml:description/maml:para").
23 | ///
24 | [XmlArray("description", Namespace = Constants.XmlNamespace.MAML, Order = 1)]
25 | [XmlArrayItem("para", Namespace = Constants.XmlNamespace.MAML)]
26 | public List Synopsis { get; set; } = new List();
27 |
28 | ///
29 | /// The verb component of the Cmdlet's name.
30 | ///
31 | [XmlElement("verb", Namespace = Constants.XmlNamespace.Command, Order = 2)]
32 | public string Verb { get; set; } = string.Empty;
33 |
34 | ///
35 | /// The noun component of the Cmdlet's name.
36 | ///
37 | [XmlElement("noun", Namespace = Constants.XmlNamespace.Command, Order = 3)]
38 | public string Noun { get; set; } = string.Empty;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/MamlWriter/CommandExample.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System.Collections.Generic;
5 | using System.Xml.Serialization;
6 |
7 | namespace Microsoft.PowerShell.PlatyPS.MAML
8 | {
9 | ///
10 | /// Represents a "command:example" element in a Powershell MAML help document.
11 | ///
12 | public class CommandExample
13 | {
14 | ///
15 | /// The command details.
16 | ///
17 | [XmlElement("title", Namespace = Constants.XmlNamespace.MAML, Order = 0)]
18 | public string Title { get; set; } = string.Empty;
19 |
20 | ///
21 | /// An introduction to the example (one or more paragraphs; "maml:introduction/maml:para").
22 | ///
23 | [XmlArray("introduction", Namespace = Constants.XmlNamespace.MAML, Order = 1)]
24 | [XmlArrayItem("para", Namespace = Constants.XmlNamespace.MAML)]
25 | public List Description { get; set; } = new List();
26 |
27 | ///
28 | /// The example code.
29 | ///
30 | [XmlElement("code", Namespace = Constants.XmlNamespace.Dev, Order = 2)]
31 | public string Code { get; set; } = string.Empty;
32 |
33 | ///
34 | /// An introduction to the example (one or more paragraphs; "dev:remarks/maml:para").
35 | ///
36 | [XmlArray("remarks", Namespace = Constants.XmlNamespace.Dev, Order = 3)]
37 | [XmlArrayItem("para", Namespace = Constants.XmlNamespace.MAML)]
38 | public List Remarks { get; set; } = new List();
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/test/Pester/assets/PSDiagnostics.md:
--------------------------------------------------------------------------------
1 | ---
2 | Download Help Link: https://aka.ms/powershell75-help
3 | Help Version: 7.5.0.0
4 | Locale: en-US
5 | Module Guid: c61d6278-02a3-4618-ae37-a524d40a7f44
6 | Module Name: PSDiagnostics
7 | ms.date: 11/27/2018
8 | schema: 2.0.0
9 | title: PSDiagnostics Module
10 | ---
11 | # PSDiagnostics Module
12 |
13 | ## Description
14 |
15 | The PowerShell Diagnostics Module contains a set of cmdlets that enables the use of ETW
16 | tracing in PowerShell on Windows.
17 |
18 | This module is only available on the Windows platform.
19 |
20 | ## PSDiagnostics Cmdlets
21 |
22 | ### [Disable-PSTrace](Disable-PSTrace.md)
23 | Disables the Microsoft-Windows-PowerShell event provider logs.
24 |
25 | ### [Disable-PSWSManCombinedTrace](Disable-PSWSManCombinedTrace.md)
26 | Stop the logging session started by Enable-PSWSManCombinedTrace.
27 |
28 | ### [Disable-WSManTrace](Disable-WSManTrace.md)
29 | Stop the WSMan logging session started by Enable-WSManTrace.
30 |
31 | ### [Enable-PSTrace](Enable-PSTrace.md)
32 | Enables the Microsoft-Windows-PowerShell event provider logs.
33 |
34 | ### [Enable-PSWSManCombinedTrace](Enable-PSWSManCombinedTrace.md)
35 | Start a logging session with the WSMan and PowerShell providers enabled.
36 |
37 | ### [Enable-WSManTrace](Enable-WSManTrace.md)
38 | Start a logging session with the WSMan providers enabled.
39 |
40 | ### [Get-LogProperties](Get-LogProperties.md)
41 | Retrieves the properties of a Windows event log.
42 |
43 | ### [Set-LogProperties](Set-LogProperties.md)
44 | Changes the properties of a Windows event log.
45 |
46 | ### [Start-Trace](Start-Trace.md)
47 | Start an Event Trace logging session.
48 |
49 | ### [Stop-Trace](Stop-Trace.md)
50 | Stop an Event Trace logging session.
51 |
52 |
--------------------------------------------------------------------------------
/src/Command/ConvertToCommandHelpCommand.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Globalization;
7 | using System.Management.Automation;
8 | using Microsoft.PowerShell.PlatyPS.Model;
9 |
10 | namespace Microsoft.PowerShell.PlatyPS
11 | {
12 | ///
13 | /// Cmdlet to import a markdown file and convert it to a CommandHelp object.
14 | ///
15 | [Cmdlet(VerbsCommon.New, "CommandHelp")]
16 | [OutputType(typeof(Microsoft.PowerShell.PlatyPS.Model.CommandHelp[]))]
17 | public sealed class NewCommandHelpCommand : PSCmdlet
18 | {
19 | #region cmdlet parameters
20 | [Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true)]
21 | [ValidateNotNullOrEmpty]
22 | public CommandInfo[] CommandInfo { get; set; } = new CommandInfo[0];
23 | #endregion
24 |
25 | List? cmdHelpObjs = null;
26 | TransformSettings transformSettings = new();
27 |
28 | protected override void BeginProcessing()
29 | {
30 | transformSettings = new TransformSettings()
31 | {
32 | CreateModulePage = false,
33 | DoubleDashList = false,
34 | ExcludeDontShow = true,
35 | HelpVersion = "3.0.0",
36 | Locale = CultureInfo.GetCultureInfo("en-US"),
37 | UseFullTypeName = true
38 | };
39 | }
40 |
41 | protected override void ProcessRecord()
42 | {
43 | cmdHelpObjs = new TransformCommand(transformSettings).Transform(CommandInfo);
44 | foreach (var cHelp in cmdHelpObjs)
45 | {
46 | WriteObject(cHelp);
47 | }
48 | }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/test/Pester/assets/New-EmptyCommand.md:
--------------------------------------------------------------------------------
1 | ---
2 | document type: cmdlet
3 | external help file: New-EmptyCommand-Help.xml
4 | HelpUri: ''
5 | Locale: en-US
6 | Module Name: ''
7 | ms.date: 03/04/2025
8 | PlatyPS schema version: 2024-05-01
9 | title: New-EmptyCommand
10 | ---
11 |
12 | # New-EmptyCommand
13 |
14 | ## SYNOPSIS
15 |
16 | {{ Fill in the Synopsis }}
17 |
18 | ## SYNTAX
19 |
20 | ### __AllParameterSets
21 |
22 | ```
23 | New-EmptyCommand [[-InputString] ] []
24 | ```
25 |
26 | ## ALIASES
27 |
28 | This cmdlet has the following aliases,
29 | {{Insert list of aliases}}
30 |
31 | ## DESCRIPTION
32 |
33 | {{ Fill in the Description }}
34 |
35 | ## EXAMPLES
36 |
37 | ### Example 1
38 |
39 | {{ Add example description here }}
40 |
41 | ## PARAMETERS
42 |
43 | ### -InputString
44 |
45 | {{ Fill InputString Description }}
46 |
47 | ```yaml
48 | Type: System.String
49 | DefaultValue: ''
50 | SupportsWildcards: false
51 | ParameterValue: []
52 | Aliases:
53 | - InputObject
54 | - InputParameter
55 | ParameterSets:
56 | - Name: (All)
57 | Position: 0
58 | IsRequired: false
59 | ValueFromPipeline: true
60 | ValueFromPipelineByPropertyName: false
61 | ValueFromRemainingArguments: false
62 | DontShow: false
63 | AcceptedValues: []
64 | HelpMessage: ''
65 | ```
66 |
67 | ### CommonParameters
68 |
69 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable,
70 | -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable,
71 | -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see
72 | [about_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216).
73 |
74 | ## INPUTS
75 |
76 | ### System.String
77 |
78 | ## OUTPUTS
79 |
80 | ### System.String
81 |
82 | ## NOTES
83 |
84 | ## RELATED LINKS
85 |
--------------------------------------------------------------------------------
/test/Pester/MeasurePlatyPSMarkdown.Tests.ps1:
--------------------------------------------------------------------------------
1 | # Copyright (c) Microsoft Corporation.
2 | # Licensed under the MIT License.
3 |
4 | Describe "Export-MarkdownModuleFile" {
5 | BeforeAll {
6 | $files = Get-ChildItem $PSScriptRoot/assets -filter *.md
7 | $idents = $files.FullName | Measure-PlatyPSMarkdown
8 | $goodFile1 = $idents.Where({$_.FilePath -match "get-date.md$"})
9 | $goodFile2 = $idents.Where({$_.FilePath -match "Compare-CommandHelp.md$"})
10 | $mfPath = Import-MarkdownModuleFile $PSScriptRoot/assets/Microsoft.PowerShell.Archive.md |
11 | Export-MarkdownModuleFile -outputFolder $TESTDRIVE
12 | }
13 |
14 | It "Should identify all the '' assets" -TestCases @(
15 | @{ fileType = "unknown"; expectedCount = 2 }
16 | @{ fileType = "CommandHelp"; expectedCount = 42 }
17 | @{ fileType = "ModuleFile"; expectedCount = 16 }
18 | @{ fileType = "V1Schema"; expectedCount = 53 }
19 | @{ fileType = "V2Schema"; expectedCount = 5 }
20 | ) {
21 | param ($fileType, $expectedCount)
22 | $idents.Where({($_.FileType -band $fileType) -eq $fileType}).Count | Should -Be $expectedCount
23 | }
24 |
25 | It "Should have proper diagnostics for get-date.md" {
26 | $goodFile1.DiagnosticMessages.Count | Should -Be 4
27 | $goodFile1.FileType | Should -match "v1schema"
28 | $goodFile1.DiagnosticMessages[-1].Message | Should -Match "PlatyPS.*schema.*marking as v1"
29 | }
30 |
31 | It "Should have proper diagnostics for Compare-CommandHelp.md" {
32 | $goodFile2.DiagnosticMessages.Count | Should -Be 2
33 | ($goodFile2.FileType -band "v2schema") -eq "v2schema" | Should -Be $true
34 | $goodFile2.DiagnosticMessages[-1].Message | Should -Be "document type found: cmdlet"
35 | }
36 |
37 | It "Should recognise a V2 module file" {
38 | $v2ModuleFile = Measure-PlatyPSMarkdown -Path $mfPath.Fullname
39 | $v2ModuleFile.Filetype | Should -Be "ModuleFile, V2Schema"
40 | }
41 |
42 | }
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Microsoft Open Source Code of Conduct
2 |
3 | This project has adopted the [Microsoft Open Source Code of Conduct][02].
4 |
5 | We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and
6 | healthy community.
7 |
8 | ## Our Standards
9 |
10 | Examples of behavior that contributes to a positive environment for our community include:
11 |
12 | - Demonstrating empathy and kindness toward other people
13 | - Being respectful of differing opinions, viewpoints, and experiences
14 | - Giving and gracefully accepting constructive feedback
15 | - Accepting responsibility and apologizing to those affected by our mistakes, and learning from the
16 | experience
17 | - Focusing on what's best not just for us as individuals, but for the overall community
18 |
19 | Examples of unacceptable behavior include:
20 |
21 | - Disruptive behavior
22 | - Submitting spam comments, issues, or pull requests
23 | - Defacing or vandalizing the project, repository, content, or documentation
24 | - Intentionally introducing security vulnerabilities
25 | - Disrespectful behavior
26 | - Trolling, insulting or derogatory comments, and personal or political attacks
27 | - Public or private harassment
28 | - Publishing others' private information, such as a physical or email address, without their
29 | explicit permission
30 | - The use of sexualized language or imagery, and sexual attention or advances of any kind
31 | - Other conduct that could reasonably be considered inappropriate in a professional setting
32 |
33 | ## Resources
34 |
35 | - [Microsoft Open Source Code of Conduct][02]
36 | - [Microsoft Code of Conduct FAQ][03]
37 | - Contact [opencode@microsoft.com][04] with questions or concerns
38 | - Employees can reach out at [aka.ms/opensource/moderation-support][01]
39 |
40 |
41 | [01]: https://aka.ms/opensource/moderation-support
42 | [02]: https://opensource.microsoft.com/codeofconduct/
43 | [03]: https://opensource.microsoft.com/codeofconduct/faq/
44 | [04]: mailto:opencode@microsoft.com
45 |
--------------------------------------------------------------------------------
/src/Transform/TransformCommand.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System.Collections.ObjectModel;
5 | using System.Collections.Generic;
6 | using System.Management.Automation;
7 | using Microsoft.PowerShell.PlatyPS.Model;
8 |
9 | namespace Microsoft.PowerShell.PlatyPS
10 | {
11 | internal class TransformCommand : TransformBase
12 | {
13 | public TransformCommand(TransformSettings settings) : base(settings)
14 | {
15 | }
16 |
17 | internal List Transform(IEnumerable command)
18 | {
19 | List cmdHelpList = new();
20 | foreach(var cmd in command)
21 | {
22 | cmdHelpList.Add(Transform(cmd));
23 | }
24 | return cmdHelpList;
25 | }
26 |
27 | internal CommandHelp Transform(CommandInfo command)
28 | {
29 | return ConvertCmdletInfo(command);
30 | }
31 |
32 | internal Collection Transform(string command)
33 | {
34 | Collection cmdHelp = new();
35 | Collection cmdletInfos = PowerShellAPI.GetCommandInfo(command, Settings.Session);
36 |
37 | foreach(var cmdletInfo in cmdletInfos)
38 | {
39 | cmdHelp.Add(ConvertCmdletInfo(cmdletInfo));
40 | }
41 |
42 | return cmdHelp;
43 | }
44 |
45 | internal override Collection Transform(string[] commandNames)
46 | {
47 | Collection cmdHelp = new();
48 |
49 | foreach (var command in commandNames)
50 | {
51 | Collection cmdletInfos = PowerShellAPI.GetCommandInfo(command, Settings.Session);
52 |
53 | foreach (var cmdletInfo in cmdletInfos)
54 | {
55 | cmdHelp.Add(ConvertCmdletInfo(cmdletInfo));
56 | }
57 | }
58 |
59 | return cmdHelp;
60 | }
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/test/Pester/assets/Exit-PSHostProcess.md:
--------------------------------------------------------------------------------
1 | ---
2 | external help file: System.Management.Automation.dll-Help.xml
3 | Locale: en-US
4 | Module Name: Microsoft.PowerShell.Core
5 | ms.date: 11/06/2020
6 | online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/exit-pshostprocess?view=powershell-7.4&WT.mc_id=ps-gethelp
7 | schema: 2.0.0
8 | title: Exit-PSHostProcess
9 | ---
10 | # Exit-PSHostProcess
11 |
12 | ## SYNOPSIS
13 | Closes an interactive session with a local process.
14 |
15 | ## SYNTAX
16 |
17 | ```
18 | Exit-PSHostProcess []
19 | ```
20 |
21 | ## DESCRIPTION
22 |
23 | The `Exit-PSHostProcess` cmdlet closes an interactive session with a local process that you have
24 | opened by running the `Enter-PSHostProcess` cmdlet. You run the `Exit-PSHostProcess` cmdlet from
25 | within the process, when you are finished debugging or troubleshooting a script that is running
26 | within a process. Beginning in PowerShell 6.2, this cmdlet is supported on non-Windows platforms.
27 |
28 | ## EXAMPLES
29 |
30 | ### Example 1: Exit a process
31 |
32 | ```
33 | [Process:1520]: PS> Exit-PSHostProcess
34 | PS>
35 | ```
36 |
37 | In this example, you have been working in an active process to debug a script running in a runspace
38 | in the process, as described in `Enter-PSHostProcess`. After you type the `exit` command to exit the
39 | debugger, run the `Exit-PSHostProcess` cmdlet to close your interactive session with the process.
40 | The cmdlet closes your session in the process, and returns you to the `PS C:\>` prompt.
41 |
42 | ## PARAMETERS
43 |
44 | ### CommonParameters
45 |
46 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable,
47 | -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose,
48 | -WarningAction, and -WarningVariable. For more information, see
49 | [about_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216).
50 |
51 | ## INPUTS
52 |
53 | ## OUTPUTS
54 |
55 | ## NOTES
56 |
57 | ## RELATED LINKS
58 |
59 | [Enter-PSHostProcess](Enter-PSHostProcess.md)
60 |
61 |
--------------------------------------------------------------------------------
/src/Common/YamlLayoutSerializer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using YamlDotNet.Core;
4 | using YamlDotNet.Core.Events;
5 | using YamlDotNet.Serialization;
6 |
7 | namespace Microsoft.PowerShell.PlatyPS
8 | {
9 | public class LayoutSequenceStyle : IYamlTypeConverter
10 | {
11 | public bool Accepts(Type type)
12 | {
13 | bool fromString = typeof(IEnumerable).IsAssignableFrom(type);
14 | bool fromObject = typeof(IEnumerable