-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharguments.odin
More file actions
69 lines (60 loc) · 1.4 KB
/
arguments.odin
File metadata and controls
69 lines (60 loc) · 1.4 KB
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
package eitr
import "core:fmt"
// import "core:strings"
// odinfmt: disable
Argument_Kind :: enum {
Invalid,
Command_Help, // -h, --help
Verbose, // -v, --verbose
Configuration, // -c, --config
Output, // -o, --output
Set, // -s, --set
Scope_Directory, // -d, --directory
Profile, // -p, --profile
}
// odinfmt: enable
contains_arg :: proc(
args: []string,
arg: Argument_Kind,
log_invalid := true,
) -> (
found: bool,
index: int,
) {
for a, idx in args {
actual_value, err := find_arg(a, log_invalid)
if err == .Unknown_Argument {continue}
if actual_value == arg {return true, idx}
}
return false, -1
}
find_arg :: proc(
text: string,
log_invalid := true,
) -> (
arg: Argument_Kind,
err: Eitr_Errors,
) {
if len(text) == 0 {return .Invalid, .Empty_Input}
switch text {
case "-h", "--help":
return .Command_Help, .None
case "-v", "--verbose":
return .Verbose, .None
case "-c", "--config":
return .Configuration, .None
case "-o", "--output":
return .Output, .None
case "-s", "--set":
return .Set, .None
case "-d", "--directory":
return .Scope_Directory, .None
case "-p", "--profile":
return .Profile, .None
case:
if (log_invalid) {
fmt.eprintf("[eitr] ERROR: Unknown argument found - %v\n", text)
}
return .Invalid, .Unknown_Argument
}
}