-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathArgsToObj.ahk
49 lines (45 loc) · 1.01 KB
/
ArgsToObj.ahk
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
; Link: https://gist.github.com/tmplinshi/d995be35f98cdf57f5648388613246f5
; Author: tmplinshi
; Date:
; for: AHK_L
/*
ArgsToObj - Convert command line parameters to object
Example:
---------------------------------------------------------------------
Command line parameters:
-from gbk /to utf-8 /a /b --delete-top 2 --delete-end=5 in.txt out.txt
Return:
{
"$" : [
"in.txt",
"out.txt"
],
"a" : 1,
"b" : 1,
"delete-end" : 5,
"delete-top" : 2,
"from" : "gbk",
"to" : "utf-8"
}
---------------------------------------------------------------------
*/
ArgsToObj(StrName := "$", NoValueArgs*) {
obj := { (StrName):[] }
KeyOnly := {}
for i, k in NoValueArgs
KeyOnly[k] := true
for i, arg in A_Args
{
if KeyOnly[arg]
obj[arg] := true
else if RegExMatch(arg, "^--(.*?)=(.*)", m)
obj[m1] := m2
else if RegExMatch(arg, "^(?:/|--|-)\K.*", m)
obj[m] := true, key := m
else if (key != "")
obj[key] := arg, key := ""
else
obj[StrName].push(arg)
}
return obj
}