-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkickstart.ps1
147 lines (130 loc) · 4.61 KB
/
kickstart.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/usr/bin/env pwsh
<#
.SYNOPSIS
A script for setting up new projects and development environments.
#>
param (
# The command to run
# Supported commands:
# latex: Manage LaTeX projects
[ValidateNotNullOrEmpty()]
[ValidateSet('latex')]
[string] $command,
# Install all supported tools
[switch] $install = $false,
# Uninstall all supported tools
[switch] $uninstall = $false,
# Show the Kickstart help message
[switch] $help = $false
)
#===============================================================================
# Error handling
#===============================================================================
$ErrorActionPreference = 'Stop'
Set-StrictMode -v Latest
#===============================================================================
# Global variables
#===============================================================================
# A hashtable for storing Kickstart global variables
[hashtable]$KS = @{
ROOT_DIR = $PSScriptRoot
}
#===============================================================================
# Load modules
#===============================================================================
# Load all configuration files and the log module
(Join-Path $KS.ROOT_DIR 'config/*.ps1') | ForEach-Object {
. $_
}
. (Join-Path $KS.ROOT_DIR 'src/log.ps1')
#===============================================================================
# Functions
#===============================================================================
function ProcessArguments {
<#
.SYNOPSIS
Execute the appropriate command for the provided arguments
.OUTPUTS
The output of the executed command.
If no arguments are provided to the script, an unsupported operation or
command is provided, or conflicting operations are provided, an error is
displayed.
#>
[CmdletBinding()]
param (
# A hashtable of the bound parameters
[hashtable]$KSParameters,
# An array of arguments passed to the script
[System.Object[]]$KSArgs
)
# Check for conflicting operations
if ($install -and $uninstall) {
Write-Error 'Conflicting operations provided: -install and -uninstall' `
-Category InvalidArgument `
-ErrorId 255 `
-RecommendedAction 'Use either -install or -uninstall, not both.'
}
$KSParameters.Remove('command') | Out-Null
switch ($command) {
'latex' {
. (Join-Path $KS.ROOT_DIR 'LaTeX\mod.ps1') @KSParameters @KSArgs
exit $LASTEXITCODE
}
}
# The below is only reached if the 'command' parameter is not set
if ($help) {
Get-Help $PSCommandPath -Detailed
exit 0
}
if ($install) {
Info 'Installing all supported tools…'
. (Join-Path $KS.ROOT_DIR 'latex\mod.ps1') @KSParameters @KSArgs
exit $LASTEXITCODE
}
if ($uninstall) {
Info 'Uninstalling all supported tools…'
. (Join-Path $KS.ROOT_DIR 'latex\mod.ps1') @KSParameters @KSArgs
exit $LASTEXITCODE
}
if ($KSArgs.Count -eq 0) {
Write-Error 'No operation or commands provided.' `
-Category InvalidArgument `
-ErrorId 254 `
-RecommendedAction `
'Use `-help` to see the available operations, commands and options.'
} else {
Write-Error "Unsupported operation(s) or command(s): ${KSArgs})" `
-Category InvalidArgument `
-ErrorId 253 `
-RecommendedAction `
'Use `-help` to see the available options and commands.'
}
}
function Main {
<#
.SYNOPSIS
Execute the appropriate command for the provided arguments, taking into
account the specified level of verbosity.
.OUTPUTS
The output of the executed commands if the verbose flag is set.
Otherwise, the output of non-progress messages is suppressed.
#>
[CmdletBinding()]
param (
# A hashtable of the bound parameters
[hashtable]$KSParameters,
# An array of arguments passed to the script
[System.Object[]]$KSArgs
)
# TODO: Implement verbose output
# if ($KSArgs.Contains('-verbose') -or $KSArgs.Contains('-v')) {
# ProcessArguments $KSParameters $KSArgs | Write-Verbose -Verbose
# } else {
# ProcessArguments $KSParameters $KSArgs | Write-Verbose
# }
ProcessArguments $KSParameters $KSArgs
}
#===============================================================================
# Entry point
#===============================================================================
Main $PSBoundParameters $args