-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.v
71 lines (65 loc) · 1.92 KB
/
config.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
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
70
71
module vargus
// CommandConfig is the default cli command custom configurations
struct CommandConfig {
mut:
use_custom_help bool
custom_help fn (string, string, []HelpSubcommands, []FlagArgs, []FlagArgs)
errors ErrorConfig
validators ValidatorsConfig
}
// ErrorConfig is the custom configurations for error messages
struct ErrorConfig {
mut:
use_custom_required bool
use_custom_value bool
use_custom_blank bool
use_custom_unknown bool
use_custom_command bool
required ErrorFuncImp
value ErrorFuncImp
blank ErrorFuncDef
unknown ErrorFuncDef
command ErrorFuncDef
}
// ValidatorsConfig is the custom configurations for flag validators
struct ValidatorsConfig {
mut:
use_custom_integer bool
use_custom_string_var bool
use_custom_float bool
use_custom_boolean bool
integer ValidatorFunc
string_var ValidatorFunc
float ValidatorFunc
boolean ValidatorFunc
}
// set_help sets a custom help function for the app
pub fn (mut c Commander) set_help(f fn (string, string, []HelpSubcommands, []FlagArgs, []FlagArgs)) {
c.config.custom_help = f
c.config.use_custom_help = true
}
pub struct CFlagValidatorConfig {
flag_type FlagDataType [required]
function ValidatorFunc [required]
}
// set_validator sets a custom validators for a specific flag type
pub fn (mut c Commander) set_validator(cf CFlagValidatorConfig) {
match cf.flag_type {
.integer {
c.config.validators.use_custom_integer = true
c.config.validators.integer = cf.function
}
.string_var {
c.config.validators.use_custom_string_var = true
c.config.validators.string_var = cf.function
}
.float {
c.config.validators.use_custom_float = true
c.config.validators.float = cf.function
}
.boolean {
c.config.validators.use_custom_boolean = true
c.config.validators.boolean = cf.function
}
}
}