summaryrefslogtreecommitdiff
path: root/src/setup.c
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2022-05-25 19:25:19 -0700
committerVito Caputo <vcaputo@pengaru.com>2022-05-25 19:25:19 -0700
commit72ef8c3d6dc48b108c81e2d4ff6176fff579db5c (patch)
tree76767aea5c6bd97a4adaae1d98d3d6801e22dd78 /src/setup.c
parentd6d0dc1f30ab21a4b1ed2c76ef6c42602b1d5be6 (diff)
setup: return the desc for failed setting on error
This commit improves the error printed when cli-supplied args fail, adding at least the key name to what used to be just a stringified errno: ``` $ src/rototiller --module=shapes,scale=99 Shape type: 0: circle 1: pinwheel 2: rhombus 3: star Enter a value 0-3 [1 (pinwheel)]: Fatal error: unable to use args for setting "scale": Invalid argument $ ```
Diffstat (limited to 'src/setup.c')
-rw-r--r--src/setup.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/setup.c b/src/setup.c
index a5b1c70..e4c22f3 100644
--- a/src/setup.c
+++ b/src/setup.c
@@ -1,6 +1,7 @@
#include <assert.h>
#include <stdio.h>
+#include "setup.h"
#include "til_settings.h"
#include "til_setup.h"
#include "til_util.h"
@@ -22,7 +23,7 @@ static int add_value(til_settings_t *settings, const char *key, const char *valu
/* returns negative on error, otherwise number of additions made to settings */
-int setup_interactively(til_settings_t *settings, int (*setup_func)(til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, til_setup_t **res_setup), int defaults, til_setup_t **res_setup)
+int setup_interactively(til_settings_t *settings, int (*setup_func)(til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, til_setup_t **res_setup), int defaults, til_setup_t **res_setup, const til_setting_desc_t **res_failed_desc)
{
unsigned additions = 0;
char buf[256] = "\n";
@@ -44,8 +45,12 @@ int setup_interactively(til_settings_t *settings, int (*setup_func)(til_settings
if (setting && !setting->desc) {
/* XXX FIXME: this key as value exception is janky, make a helper to access the value or stop doing that. */
r = til_setting_desc_check(desc, setting->value ? : setting->key);
- if (r < 0)
+ if (r < 0) {
+ /* TODO: send back desc to caller, caller must free. */
+ *res_failed_desc = desc;
+
return r;
+ }
/* XXX FIXME everything's constified necessitating this fuckery, revisit and cleanup later, prolly another til_settings helper */
((til_setting_t *)setting)->desc = desc;
© All Rights Reserved