Teach `gargoyle_digest_argv` to report errors intelligently
This commit is contained in:
parent
47332f3777
commit
b39bc46b50
|
@ -3,7 +3,6 @@
|
|||
#include <gargoyle/sleuth.h>
|
||||
#include <gargoyle/twine.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
uint8_t gargoyle_digest_argv(uint16_t optc, struct gargoyle_opt *optv, int *argc, char ***argv, struct gargoyle_err *err, gargoyle_flag_type flags) {
|
||||
|
@ -137,6 +136,8 @@ uint8_t gargoyle_digest_envh(uint16_t optc, struct gargoyle_opt *optv, const cha
|
|||
flags |= GARGOYLE_FLG_ICASE;
|
||||
}
|
||||
|
||||
GARGOYLE_NEW_ERR(err);
|
||||
|
||||
for(; **envh; *envh += 1) {
|
||||
const char *var = **envh;
|
||||
|
||||
|
@ -149,10 +150,9 @@ uint8_t gargoyle_digest_envh(uint16_t optc, struct gargoyle_opt *optv, const cha
|
|||
|
||||
if(!opt) {
|
||||
if(flags & GARGOYLE_FLG_STRCT) {
|
||||
err->code = GARGOYLE_ERR_UNKNOWN_OPT;
|
||||
char *eql = index(brand, '=');
|
||||
snprintf(err->msg, GARGOYLE_MAX_ERR_SZ, "unknown option %.*s", (int) (eql - brand), brand);
|
||||
return GARGOYLE_ERR_UNKNOWN_OPT;
|
||||
GARGOYLE_MK_ERR(err, GARGOYLE_ERR_UNKNOWN_OPT, "unknown variable '%.*s'", (int) (eql - brand), brand);
|
||||
return err->code;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
@ -167,7 +167,8 @@ uint8_t gargoyle_digest_envh(uint16_t optc, struct gargoyle_opt *optv, const cha
|
|||
}
|
||||
|
||||
if(res) {
|
||||
return res;
|
||||
GARGOYLE_MK_ERR(err, res, "invalid value '%s' for variable '%.*s'", brand + opt->brand_sz + 1, opt->brand_sz, opt->brand);
|
||||
return err->code;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue