-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCurl.hx
48 lines (43 loc) · 1.85 KB
/
Curl.hx
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
/*
* SPDX-FileCopyrightText: © Sebastian Thomschke and contributors
* SPDX-FileContributor: Sebastian Thomschke
* SPDX-License-Identifier: MIT
* SPDX-ArtifactOfProjectHomePage: https://github.com/sebthom/more-clink-completions
*/
package more_clink_completions.completions;
import clink.api.ArgMatcher;
import clink.api.Clink;
import clink.util.Suggest;
import more_clink_completions.util.Utils;
using clink.util.Strings;
/**
* Clink command line completions for "curl" command (C:\Windows\system32\curl.exe).
*/
class Curl {
public static function register() {
if (Clink.getArgMatcher("curl") == null)
Clink.argMatcher("curl").setDelayedInitializer(registerNow);
}
static function registerNow(parser:ArgMatcher, commandWord:String) {
for (line in Utils.exec("curl --help all")) {
final optionShort = line.findMatch("%s([-][%a%d]),?%s.*");
final optionLong = line.findMatch("%s([-][-][%a%d][%a-%d]+)%s.*");
final optionArg = line.findMatch("%s(%b<>)%s");
switch (optionArg) {
case "<file>", "<filename>", "<file name>", "<path>":
if (optionShort != null) parser.addFlag(optionShort, Suggest.files);
if (optionLong != null) parser.addFlag(optionLong, Suggest.files);
case "<dir>":
if (optionShort != null) parser.addFlag(optionShort, Suggest.dirs);
if (optionLong != null) parser.addFlag(optionLong, Suggest.dirs);
case null: // flag
if (optionShort != null) parser.addFlag(optionShort);
if (optionLong != null) parser.addFlag(optionLong);
default: // option with unknown argument type
if (optionShort != null) parser.addFlag(optionShort, "");
if (optionLong != null) parser.addFlag(optionLong, "");
}
}
parser.noFiles();
}
}