Teach `gargoyle_digest_argv` to report errors intelligently

This commit is contained in:
Nick Chambers 2022-07-01 15:03:07 -05:00
parent 47332f3777
commit b39bc46b50
1 changed files with 6 additions and 5 deletions

View File

@ -3,7 +3,6 @@
#include <gargoyle/sleuth.h> #include <gargoyle/sleuth.h>
#include <gargoyle/twine.h> #include <gargoyle/twine.h>
#include <stddef.h> #include <stddef.h>
#include <stdio.h>
#include <string.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) { 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; flags |= GARGOYLE_FLG_ICASE;
} }
GARGOYLE_NEW_ERR(err);
for(; **envh; *envh += 1) { for(; **envh; *envh += 1) {
const char *var = **envh; 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(!opt) {
if(flags & GARGOYLE_FLG_STRCT) { if(flags & GARGOYLE_FLG_STRCT) {
err->code = GARGOYLE_ERR_UNKNOWN_OPT;
char *eql = index(brand, '='); char *eql = index(brand, '=');
snprintf(err->msg, GARGOYLE_MAX_ERR_SZ, "unknown option %.*s", (int) (eql - brand), brand); GARGOYLE_MK_ERR(err, GARGOYLE_ERR_UNKNOWN_OPT, "unknown variable '%.*s'", (int) (eql - brand), brand);
return GARGOYLE_ERR_UNKNOWN_OPT; return err->code;
} else { } else {
continue; continue;
} }
@ -167,7 +167,8 @@ uint8_t gargoyle_digest_envh(uint16_t optc, struct gargoyle_opt *optv, const cha
} }
if(res) { 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;
} }
} }