-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathscripts_egsave.ps1
More file actions
executable file
·68 lines (59 loc) · 1.7 KB
/
Copy pathscripts_egsave.ps1
File metadata and controls
executable file
·68 lines (59 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/pwsh -nop
#Requires -PSEdition Core -Version 7.3
<#
.SYNOPSIS
Generate example scripts from the current repository.
.PARAMETER Path
The path to the script file to save as an example.
.PARAMETER Force
Force ovewriting target file if exists.
.PARAMETER WriteOutput
Write output to the success [1] stream instead of the information [6] one.
.EXAMPLE
# :save all missing script examples from the scripts directory and its subdirectories
./scripts_egsave.ps1
# :force saveing all script examples from the scripts directory and its subdirectories
./scripts_egsave.ps1 -Force
#>
[CmdletBinding()]
param (
[Parameter(Position = 0)]
[ValidateScript({ Test-Path $_ }, ErrorMessage = "'{0}' is not a valid path.")]
[string]$Path,
[switch]$Force,
[switch]$WriteOutput
)
begin {
$ErrorActionPreference = 'Stop'
# set location to workspace folder
Push-Location $PSScriptRoot
# check if the Invoke-ExampleScriptSave function is available, otherwise import do-common module
try {
Get-Command Invoke-ExampleScriptSave -CommandType Function | Out-Null
} catch {
Import-Module (Resolve-Path './modules/do-common')
}
# rewrite PSBoundParameters to the param variable
$param = $PSBoundParameters
$param.FolderFromBase = $true
}
process {
if ($param.Path) {
Invoke-ExampleScriptSave @param
} else {
# specify directories to save examples from
$folders = @(
'wsl'
'.assets/provision'
'.assets/scripts'
'.assets/tools'
)
foreach ($folder in $folders) {
$param.Path = $folder
Invoke-ExampleScriptSave @param
}
}
}
clean {
Pop-Location
}