Skip to content

Commit 322697f

Browse files
committed
Ignore unknown installer arguments and add flexible flag parsing to install.ps1
- allow params be passed in any order. ignore not supported params. don't support positional params.
1 parent 487fe17 commit 322697f

2 files changed

Lines changed: 30 additions & 6 deletions

File tree

‎install.ps1‎

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,32 @@
1-
param(
2-
[string]$editor = "",
3-
[string]$lang = "en",
4-
[string]$tag = ""
5-
)
1+
$editor = ""
2+
$lang = "en"
3+
$tag = ""
4+
5+
$i = 0
6+
while ($i -lt $args.Count) {
7+
$arg = $args[$i]
8+
if ($arg -match "^--?editor$") {
9+
if ($i + 1 -lt $args.Count) { $editor = $args[$i + 1] }
10+
$i += 2
11+
} elseif ($arg -match "^--?editor[:=](.*)$") {
12+
$editor = $matches[1]
13+
$i++
14+
} elseif ($arg -match "^--?lang$") {
15+
if ($i + 1 -lt $args.Count) { $lang = $args[$i + 1] }
16+
$i += 2
17+
} elseif ($arg -match "^--?lang[:=](.*)$") {
18+
$lang = $matches[1]
19+
$i++
20+
} elseif ($arg -match "^--?tag$") {
21+
if ($i + 1 -lt $args.Count) { $tag = $args[$i + 1] }
22+
$i += 2
23+
} elseif ($arg -match "^--?tag[:=](.*)$") {
24+
$tag = $matches[1]
25+
$i++
26+
} else {
27+
$i++
28+
}
29+
}
630

731
$ErrorActionPreference = "Stop"
832
$ProgressPreference = "SilentlyContinue"

‎install.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ while [[ "$#" -gt 0 ]]; do
1010
--editor) TARGET_SCHEME="$2"; shift 2 ;;
1111
--lang) LANGUAGE="$2"; shift 2 ;;
1212
--tag) TAG_NAME="$2"; shift 2 ;;
13-
*) echo "Unknown parameter passed: $1"; exit 1 ;;
13+
*) shift ;;
1414
esac
1515
done
1616

0 commit comments

Comments
 (0)