From cf1a40c2fea52c55c1de79c0e063d7eecc50d086 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Ortega=20Froysa?= Date: Thu, 19 Sep 2024 18:36:43 +0200 Subject: [PATCH] Move print helper functions to arg_parse.h These functions have more to do with commands, and it will be more helpful to have the print_help function especially in the same file as the actual commands structure. --- src/arg_parse.h | 21 +++++++++++++++++++++ src/main.c | 18 ------------------ 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/arg_parse.h b/src/arg_parse.h index b7f0fbf..33ae751 100644 --- a/src/arg_parse.h +++ b/src/arg_parse.h @@ -17,6 +17,8 @@ */ #pragma once +#include + enum cmd_id { CMD_UNKNOWN = 0, CMD_HELP, @@ -33,4 +35,23 @@ static const struct cmd commands[] = { { CMD_VERSION, {"version", "-v", "--version"} }, }; +static inline void print_version(void) { + printf("menu-helper v%s\n\n", VERSION); +} + +static inline void print_usage(void) { + printf("USAGE: menu-helper [options]\n\n"); +} + +static inline void print_help(void) { + print_version(); + print_usage(); + + printf("COMMANDS:\n" + "\thelp, -h, --help Show this help information.\n" + "\tversion, -v, --version Show version information.\n" + "\n"); +} + + enum cmd_id parse_args(const char *cmd); diff --git a/src/main.c b/src/main.c index 262ce78..32c1a5c 100644 --- a/src/main.c +++ b/src/main.c @@ -20,24 +20,6 @@ #include "arg_parse.h" -void print_version(void) { - printf("menu-helper v%s\n\n", VERSION); -} - -void print_usage(void) { - printf("USAGE: menu-helper [options]\n\n"); -} - -void print_help(void) { - print_version(); - print_usage(); - - printf("COMMANDS:\n" - "\thelp, -h, --help Show this help information.\n" - "\tversion, -v, --version Show version information.\n" - "\n"); -} - int main(int argc, char *argv[]) { enum cmd_id id;