Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e3cef1e

Browse files
move recurse call into a separate function
1 parent 3692197 commit e3cef1e

File tree

3 files changed

+32
-17
lines changed

3 files changed

+32
-17
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
function Invoke-RecurseSTF {
2+
[CmdletBinding()]
3+
param(
4+
[Parameter(Mandatory = $true)]
5+
[string]$fullInputPath
6+
)
7+
8+
# Step 1: Parse the input path into parent and leaf
9+
# store the result in a path obj
10+
$fullInputPathObj =
11+
Split-FilePath -inputPath $fullInputPath
12+
13+
# Step 2: Feed them back into Set-TouchFile, recurse
14+
Set-TouchFile `
15+
-Filename $fullInputPathObj.Filename `
16+
-Location $fullInputPathObj.FileFolder
17+
18+
# Step 3: after recurse call, program ends
19+
}

‎Project_Set-TouchFile/Set-TouchFile.ps1

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,17 @@ function Set-TouchFile {
3535

3636
# Before accepting pipeline input, initialize an array to collect filenames
3737
begin {
38-
$filenameArray =
39-
New-Object System.Collections.Generic.List[string]
38+
if (-not $PSBoundParameters.ContainsKey('fullInputPath')) {
39+
$filenameArray =
40+
New-Object System.Collections.Generic.List[string]
41+
}
4042
}
4143

4244
# Process the pipeline input
4345
process {
44-
$filenameArray.Add($filename)
46+
if (-not $PSBoundParameters.ContainsKey('fullInputPath')) {
47+
$filenameArray.Add($filename)
48+
}
4549
}
4650

4751
# After collecting all pipeline input, process the array
@@ -51,18 +55,7 @@ function Set-TouchFile {
5155
# Touch mode selection, determine by checking the input argument
5256
if ($PSBoundParameters.ContainsKey("fullInputPath")) {
5357
# If quick access mode selected
54-
55-
# Step 1: Parse the input path into parent and leaf
56-
# store the result in a path obj
57-
$fullInputPathObj =
58-
Split-FilePath -inputPath $fullInputPath
59-
60-
# Step 2: Feed them back into Set-TouchFile, recurse
61-
Set-TouchFile `
62-
-Filename $fullInputPathObj.Filename `
63-
-Location $fullInputPathObj.FileFolder
64-
65-
# Step 3: after recurse call, program ends
58+
Invoke-RecurseSTF -fullInputPath $fullInputPath
6659
return
6760
}
6861
else {
@@ -111,16 +104,19 @@ function Set-TouchFile {
111104
}
112105
else {
113106
# If program cannot proceed, program terminates
114-
Write-Host "Program terminates."
107+
Write-Host "Program terminates." `
108+
-ForegroundColor Red
115109
return
116110
}
111+
117112
}
118113
# End of try block
119114
}
115+
120116
catch {
121117
# Improved error handling
122118
Write-Error "Unexpected Error"
123-
Write-Error "$($_.Exception.Message)"
119+
Write-Error $_
124120
Write-Error "Action unsuccessful. Please check the input and try again."
125121

126122
# End of catch block

‎Project_Set-TouchFile/Tests/testfolder/test.c

Whitespace-only changes.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /