Skip to content

Commit 05b5db2

Browse files
authored
Merge pull request #45 from vexx32/dev
Convert koan that has super slow performance into a simple help tip!
2 parents a04ee39 + 47b38b6 commit 05b5db2

File tree

1 file changed

+45
-49
lines changed

1 file changed

+45
-49
lines changed

PSKoans/Koans/Cmdlets 1/AboutDiscovery.Koans.ps1

Lines changed: 45 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,12 @@ Describe 'Get-Help' {
5252
$ParameterInfo = Get-Help 'Get-Help' -Parameter Path
5353
$ParameterInfo.PipelineInput | Should -Be __
5454
}
55-
# Remember: if 'Get-Help Cmdlet-Name' doesn't show you all you need, try -Full. You'll need it.
55+
<#
56+
Remember: if 'Get-Help Cmdlet-Name' doesn't show you all you need, try -Full.
57+
You can also search for commands with a certain parameter using Get-Help:
5658
57-
It 'can search for commands by parameter names' {
58-
$RemoteCommands = Get-Help -Name * -Parameter ComputerName |
59-
Select-Object -ExpandProperty Name
60-
61-
$RemoteCommands.Count | Should -Be __
62-
63-
$RemoteCommands[4] | Should -Be __
64-
}
59+
Get-Help -Name * -Parameter ComputerName
60+
#>
6561
}
6662
}
6763

@@ -74,14 +70,14 @@ Describe 'Get-Member' {
7470
name of an object, as well as all available methods and properties that can be
7571
accessed for that object.
7672
#>
77-
Context 'Members and methods of objects' {
73+
Context 'Members and methods of objects' {
7874

79-
It 'can help you find useful properties' {
80-
$String = 'Hello!'
75+
It 'can help you find useful properties' {
76+
$String = 'Hello!'
8177

82-
# If you try to access a property that doesn't exist, PowerShell returns $null for it.
83-
$String.ThisDoesntExist | Should -Be $null
84-
<#
78+
# If you try to access a property that doesn't exist, PowerShell returns $null for it.
79+
$String.ThisDoesntExist | Should -Be $null
80+
<#
8581
To use Get-Member, pipe an object into it like so:
8682
"Hello!" | Get-Member
8783
@@ -92,16 +88,16 @@ Describe 'Get-Member' {
9288
9389
Which property of the above string has the expected value?
9490
#>
95-
$PropertyName = '__'
96-
$String.$PropertyName | Should -Be 6
97-
}
91+
$PropertyName = '__'
92+
$String.$PropertyName | Should -Be 6
93+
}
9894

99-
It 'can also find useful methods' {
100-
$String = "Methods are handy!"
95+
It 'can also find useful methods' {
96+
$String = "Methods are handy!"
10197

102-
# Methods can be accessed just like properties, but have parentheses and often parameters!
103-
$String.EndsWith('__') | Should -BeTrue
104-
<#
98+
# Methods can be accessed just like properties, but have parentheses and often parameters!
99+
$String.EndsWith('__') | Should -BeTrue
100+
<#
105101
If you have trouble figuring out which parameters a method requires, you can check the
106102
OverloadDefinitions by calling the method name without the parentheses. For the above
107103
method, these look like this:
@@ -119,41 +115,41 @@ Describe 'Get-Member' {
119115
be used at a time, and usually the number of arguments and type of the arguments
120116
determine the overload that PowerShell will apply when calling the method.
121117
#>
122-
$MethodName = '__'
123-
$MethodArguments = @('__', '__')
124-
# The ForEach-Object cmdlet can be used to call methods as well.
125-
'7', '8', '9', '10' |
126-
ForEach-Object -MemberName $MethodName -ArgumentList $MethodArguments |
127-
Should -Be @('000007', '000008', '000009', '000010')
118+
$MethodName = '__'
119+
$MethodArguments = @('__', '__')
120+
# The ForEach-Object cmdlet can be used to call methods as well.
121+
'7', '8', '9', '10' |
122+
ForEach-Object -MemberName $MethodName -ArgumentList $MethodArguments |
123+
Should -Be @('000007', '000008', '000009', '000010')
124+
}
128125
}
129-
}
130126

131-
Context 'Members of objects returned from cmdlets' {
127+
Context 'Members of objects returned from cmdlets' {
132128

133-
It 'can help you discover information about unfamiliar objects' {
134-
# Cmdlets also return objects! This cmdlet creates an empty .tmp file in a random
135-
# location, and returns the object representing this file.
136-
$TempFile = New-TemporaryFile
137-
Test-Path -Path $TempFile.FullName | Should -BeTrue
129+
It 'can help you discover information about unfamiliar objects' {
130+
# Cmdlets also return objects! This cmdlet creates an empty .tmp file in a random
131+
# location, and returns the object representing this file.
132+
$TempFile = New-TemporaryFile
133+
Test-Path -Path $TempFile.FullName | Should -BeTrue
138134

139-
$TempFiles = 1..10 | ForEach-Object {
140-
New-TemporaryFile
141-
}
135+
$TempFiles = 1..10 | ForEach-Object {
136+
New-TemporaryFile
137+
}
142138

143-
# Which method can be used to remove these files?
144-
$MethodName = '__'
145-
$TempFiles | ForEach-Object $MethodName
139+
# Which method can be used to remove these files?
140+
$MethodName = '__'
141+
$TempFiles | ForEach-Object $MethodName
146142

147-
$TempFiles | Test-Path | Should -BeFalse
148-
}
143+
$TempFiles | Test-Path | Should -BeFalse
144+
}
149145

150-
It 'actually returns objects itself' {
151-
$MemberData = 'string' | Get-Member
152-
# We can all betray our own selves.
153-
$MemberData | Should -BeOfType __
146+
It 'actually returns objects itself' {
147+
$MemberData = 'string' | Get-Member
148+
# We can all betray our own selves.
149+
$MemberData | Should -BeOfType __
150+
}
154151
}
155152
}
156-
}
157153

158154
Describe 'Get-Command' {
159155
<#

0 commit comments

Comments
 (0)