Skip to content

Commit 36acb43

Browse files
committed
Fix powershell script
1 parent c4f4ce3 commit 36acb43

File tree

1 file changed

+39
-9
lines changed

1 file changed

+39
-9
lines changed

tools/docker/run.ps1

+39-9
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,54 @@
11
# This is an example of how to run the docker container.
22
# This script is not part of the container, it is meant to be run on the host machine.
3-
# Usage: ./run.ps1 <path_to_arduino_esp32>
3+
# Usage: .\run.ps1 <path_to_arduino_esp32>
44

5-
if (-not (Test-Path -Path (Get-Command docker).Source)) {
6-
Write-Host "ERROR: Docker is not installed! Please install docker first."
5+
# Exit on error
6+
$ErrorActionPreference = "stop"
7+
8+
# https://devblogs.microsoft.com/scripting/use-a-powershell-function-to-see-if-a-command-exists/
9+
# Check if command exists
10+
Function Test-CommandExists
11+
{
12+
Param ($command)
13+
try {
14+
if (Get-Command $command) {
15+
RETURN $true
16+
}
17+
}
18+
catch {
19+
RETURN $false
20+
}
21+
}
22+
23+
# Check if path exists
24+
Function Test-PathExists
25+
{
26+
Param ($path)
27+
try {
28+
if (Test-Path -Path $path) {
29+
RETURN $true
30+
}
31+
}
32+
catch {
33+
RETURN $false
34+
}
35+
}
36+
37+
if (-not (Test-CommandExists docker)) {
38+
Write-Host "ERROR: Docker is not installed! Please install docker first." -ForegroundColor red
739
exit 1
840
}
941

1042
if ($args.Count -gt 0) {
11-
$ARDUINO_DIR = $args[0] -replace '\\', '/'
12-
} else {
13-
$ARDUINO_DIR = ''
43+
$ARDUINO_DIR = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($args[0])
1444
}
1545

1646
$DOCKER_ARGS = @()
1747
$DOCKER_ARGS += '-it'
1848
$DOCKER_ARGS += '-e', 'TERM=xterm-256color'
1949

20-
if ((Test-Path $ARDUINO_DIR)) {
21-
$DOCKER_ARGS += '-v', "$ARDUINO_DIR:/arduino-esp32"
50+
if ((Test-PathExists $ARDUINO_DIR)) {
51+
$DOCKER_ARGS += '-v', "${ARDUINO_DIR}:/arduino-esp32"
2252
} else {
2353
Write-Output "Warning: Invalid arduino directory: '$ARDUINO_DIR'. Ignoring it."
2454
}
@@ -28,4 +58,4 @@ if ($env:LIBBUILDER_GIT_SAFE_DIR) {
2858
}
2959

3060
Write-Output "Running: docker run $($DOCKER_ARGS -join ' ') lucassvaz/esp32-arduino-lib-builder"
31-
#docker run @($DOCKER_ARGS) lucassvaz/esp32-arduino-lib-builder
61+
docker run @($DOCKER_ARGS) lucassvaz/esp32-arduino-lib-builder

0 commit comments

Comments
 (0)