Skip to content

Instantly share code, notes, and snippets.

@igrr
Created February 27, 2023 22:30
Show Gist options
  • Save igrr/42ced595140f91c7d5dfd8f98a91a8ab to your computer and use it in GitHub Desktop.
Save igrr/42ced595140f91c7d5dfd8f98a91a8ab to your computer and use it in GitHub Desktop.
#include <argtable3.h>
int main(int argc, char **argv)
{
static struct {
struct arg_str *key;
struct arg_str *value;
struct arg_end *end;
} setArgs;
setArgs.key = arg_str1(NULL, NULL, "<key>", "Key to update");
setArgs.value = arg_str1(NULL, NULL, "<value>", "Value to set");
setArgs.end = arg_end(2);
int nerrors = arg_parse(argc, argv, (void**)&setArgs);
if (nerrors > 0) {
arg_print_errors(stdout, setArgs.end, argv[0]);
return 1;
}
if (setArgs.key->count > 0 && setArgs.value->count > 0) {
printf("key: %s value: %s\n", setArgs.key->sval[0], setArgs.value->sval[0]);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment