-
Notifications
You must be signed in to change notification settings - Fork 0
/
matches.v
40 lines (34 loc) · 843 Bytes
/
matches.v
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
module clip
pub struct Matches {
before string
mut:
argument string
flags map[string]bool
opts map[string][]string
matched_subcmd string
subcommand &Matches = voidptr(0)
}
fn (m Matches) is_empty() bool {
return is_empty(m.argument) && is_empty(m.flags) && is_empty(m.opts) && is_empty(m.matched_subcmd)
}
pub fn (m Matches) argument() string {
return m.argument
}
pub fn (m Matches) flag(name string) ?bool {
if name in m.flags {
return m.flags[name]
}
return error('does not exist')
}
pub fn (m Matches) option(name string) ?[]string {
if name in m.opts {
return m.opts[name]
}
return error('does not exist')
}
pub fn (m Matches) subcommand() ?(string, Matches) {
if m.matched_subcmd != '' {
return m.matched_subcmd, *m.subcommand
}
return error('does not matched any subcommand')
}