-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauto-dot-source.ps1
More file actions
53 lines (47 loc) · 1.26 KB
/
auto-dot-source.ps1
File metadata and controls
53 lines (47 loc) · 1.26 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
# Automatically dot-sources files by adding their names.
# Halts if any file does not exist.
# Sets the search path to the script's calling location, but
# you can change the $ScriptSourcePath variable.
# Method 1: File List #
# Easiest to read and update, leaves the file names in a variable
# that lives as long as the script.
begin
{
$ScriptSourcePath = $PSScriptRoot
$SupportingScripts = @(
'require-dot-sourced.ps1',
'missing-will-halt.ps1',
'also-missing-but-already-halted.ps1'
)
foreach ($SupportingScript in $SupportingScripts)
{
if (Test-Path -Path "$ScriptSourcePath\$SupportingScript")
{
. "$ScriptSourcePath\$SupportingScript"
}
else
{
Write-Error -Message "Required supporting script '$SupportingScript' not found in $ScriptSourcePath" -ErrorAction Stop
}
}
}
# Method 2: All in one #
# Bit tougher to read and filenames buried, but no permanent variable.
begin
{
$ScriptSourcePath = $PSScriptRoot
@(
'require-dot-sourced.ps1',
'missing-will-halt.ps1',
'also-missing-but-already-halted.ps1'
) | Foreach-Object -Process {
if (Test-Path -Path "$ScriptSourcePath\$_")
{
. "$ScriptSourcePath\$_"
}
else
{
Write-Error -Message "Required supporting script '$_' not found in $ScriptSourcePath" -ErrorAction Stop
}
}
}