diff --git a/docs/Get-Demo.md b/docs/Get-Demo.md index f77516b..ae70f0f 100644 --- a/docs/Get-Demo.md +++ b/docs/Get-Demo.md @@ -1,106 +1,87 @@ -Get-Demo --------- +### - - -### Synopsis -Gets Demos - - - ---- - - -### Description - -Gets PowerShell Demos. -Demos located in ShowDemo and all modules that tag ShowDemo will be automatically discovered. - - - ---- - - -### Related Links -* [Import-Demo](Import-Demo.md) - - - - - ---- - - -### Examples -#### EXAMPLE 1 ```PowerShell -Get-Demo +function Get-Demo +{ + <# + .SYNOPSIS + Gets Demos + .DESCRIPTION + Gets PowerShell Demos. + + Demos located in ShowDemo and all modules that tag ShowDemo will be automatically discovered. + .LINK + Import-Demo + .EXAMPLE + Get-Demo + #> + [CmdletBinding(DefaultParameterSetName='LoadedDemos')] + param( + # The name of the demo + [Parameter(ValueFromPipelineByPropertyName,ParameterSetName='LoadedDemos')] + [string] + $DemoName, ``` +```PowerShell +# The path to the demo file. + [Parameter(Mandatory,ValueFromPipelineByPropertyName,ParameterSetName='DemoFile')] + [Alias('FullName', 'DemoFile', 'File', 'Source')] + $DemoPath, +``` +```PowerShell +# A Demo Script block. + [Parameter(Mandatory,ValueFromPipeline,ParameterSetName='DemoScript')] + [scriptblock] + $DemoScript + ) +``` ---- - - -### Parameters -#### **DemoName** - -The name of the demo - - - - - - -|Type |Required|Position|PipelineInput | -|----------|--------|--------|---------------------| -|`[String]`|false |named |true (ByPropertyName)| - - - -#### **DemoPath** - -The path to the demo file. - - - - - - -|Type |Required|Position|PipelineInput |Aliases | -|----------|--------|--------|---------------------|-----------------------------------------| -|`[Object]`|true |named |true (ByPropertyName)|FullName
DemoFile
File
Source| - - - -#### **DemoScript** - -A Demo Script block. - - - - - - -|Type |Required|Position|PipelineInput | -|---------------|--------|--------|--------------| -|`[ScriptBlock]`|true |named |true (ByValue)| - - - - - ---- +```PowerShell +begin { + $myModule = $MyInvocation.MyCommand.ScriptBlock.Module + } +``` +```PowerShell +process { + if ($PSCmdlet.ParameterSetName -in 'DemoFile', 'DemoScript') { + Import-Demo @psboundParameters + return + } +``` -### Syntax ```PowerShell -Get-Demo [-DemoName ] [] +$filePaths = + @( + $pwd + if ($myModule) { + $moduleRelationships = [ModuleRelationships()]$myModule + foreach ($relationship in $moduleRelationships) { + $relationship.RelatedModule | Split-Path + } + } else { + $PSScriptRoot + } + ) ``` + + + ```PowerShell -Get-Demo -DemoPath [] +$allDemoFiles = + all scripts in $filePaths that { + $_.Name -match '^(?>demo|walkthru)\.ps1$' -or + $_.Name -match '\.(?>demo|walkthru)\.ps1$' + } are demofiles ``` + ```PowerShell -Get-Demo -DemoScript [] +$allDemoFiles | + Where-Object Name -like "*$demoName*" | + Import-Demo + } +} ```