-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4-nest.ps1
74 lines (61 loc) · 1.28 KB
/
4-nest.ps1
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
69
70
71
72
73
74
<#
.SYNOPSIS
An example of how to next commands.
.DESCRIPTION
USAGE
.\4-nest.ps1 <command>
COMMANDS
speak speak some text
logs view logs
#>
param(
[Parameter(Position=0)]
[ValidateSet("speak", "logs")]
[string]$Command,
[Parameter(Position=1, ValueFromRemainingArguments=$true)]
$Rest
)
if (!$Command) {
Get-Help $PSCommandPath
exit
}
function Command-Speak {
param (
[Parameter(Position=0, Mandatory=$True)]
[string]$Text
)
if (!$IsWindows) {
Write-Error "Sorry, the 'speak' command is only supported on Windows"
exit
}
Write-Host "Speaking the text: '$Text'"
$sp = New-Object -ComObject SAPI.SpVoice
$sp.Speak($Text) | Out-Null
}
function Command-Logs {
<#
.SYNOPSIS
Show logs for an application.
.DESCRIPTION
USAGE
.\4-nest.ps1 logs <command>
COMMANDS
app-one show logs for app-one
app-two show logs for app-two
#>
param(
[Parameter(Position=0)]
[ValidateSet("", "app-one", "app-two")]
[string]$App
)
if (!$App) {
Get-Help Command-Logs
exit
}
Write-Host "Showing logs for " -N
Write-Host $App -F Green
}
switch ($Command) {
"speak" { Command-Speak $Rest }
"logs" { Command-Logs $Rest }
}