From e879a947d823219252e93f72acac5f839dc4d8a0 Mon Sep 17 00:00:00 2001 From: Nathan Singer Date: Fri, 28 Feb 2025 00:59:56 -0500 Subject: [PATCH] fixed argp cehckign for right commands --- src/main.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main.c b/src/main.c index 486154e..42e91e6 100644 --- a/src/main.c +++ b/src/main.c @@ -7,6 +7,7 @@ #include "include/json.h" struct flags { + char* isbn; bool json, db, print; }; @@ -17,8 +18,8 @@ const char* argp_program_bug_address = "supernovaa41@gmx.com"; static char doc[] = "Lookup details of a book from the ISBN. Using OpenLibrary API."; static char args_doc[] = ""; static struct argp_option options[] = { - {0, 'j', "json", 0, "output to json", 0}, - {0, 'd', "db", 0, "output to sqlite3 database", 0}, + {"json", 'j', 0, 0, "output to json", 0}, + {"db", 'd', 0, 0, "output to sqlite3 database", 0}, {0, 'p', 0, 0, "print the full json response", 0}, {0} }; @@ -44,7 +45,12 @@ static error_t parse_opt(int key, char* arg, struct argp_state* state) case 'p': flags->print = true; break; + case ARGP_KEY_ARG: + flags->isbn = arg; + break; case ARGP_KEY_END: + if (state->arg_num < 1) + argp_usage(state); break; default: return ARGP_ERR_UNKNOWN; @@ -63,7 +69,8 @@ int main(int argc, char* argv[]) init_flags(&flags); argp_parse(&argp, argc, argv, 0, 0, &flags); - book_api_call("9780762437818", &resp); + //book_api_call("9780762437818", &resp); + book_api_call(flags.isbn, &resp); if (flags.print) puts(resp.buf);