From b75f2964e5cbca6441fffeaedaff88518e55cbc8 Mon Sep 17 00:00:00 2001 From: lohhiiccc Date: Mon, 27 Apr 2026 14:57:35 +0200 Subject: [PATCH] fix: use build in libcli print help function --- src/ping/Makefile.am | 1 - src/ping/cli/handlers/handle_help.c | 30 +++++++++++++++++-- src/ping/cli/messages/help.c | 46 ----------------------------- 3 files changed, 28 insertions(+), 49 deletions(-) delete mode 100644 src/ping/cli/messages/help.c diff --git a/src/ping/Makefile.am b/src/ping/Makefile.am index 6506e55..08daaad 100644 --- a/src/ping/Makefile.am +++ b/src/ping/Makefile.am @@ -62,7 +62,6 @@ libping_core_la_SOURCES = \ cli/parse_utils/parse_inet_addr.c \ cli/parse_utils/parse_destinations.c \ cli/config_free.c \ - cli/messages/help.c \ cli/messages/version.c \ cli/messages/error.c \ core/ping.c \ diff --git a/src/ping/cli/handlers/handle_help.c b/src/ping/cli/handlers/handle_help.c index 3c4a28d..40bcc00 100644 --- a/src/ping/cli/handlers/handle_help.c +++ b/src/ping/cli/handlers/handle_help.c @@ -1,11 +1,37 @@ +#include +#include "cli.h" #include "compiler.h" +#include "internal/cli/options.h" +#include "internal/ping/cli_handlers.h" #include "ping/cli.h" -#include "internal/cli/messages.h" + +/* Forward declarations */ +static inline const char * option_arg_type_to_str(int type); +/* -------------------- */ int cli_handle_help(__unused const char *arg, __unused void *config_void) { - print_help(); + printf("ft_ping - Send ICMP ECHO_REQUEST to network hosts\n"); + printf("Usage: ft_ping [options] \n\n"); + cli_print_options(g_options, PING_OPT_LEN, option_arg_type_to_str); return CLI_EXIT_SUCCESS; } + +static inline const char * +option_arg_type_to_str(int type) +{ + switch (type) + { + case OPT_ARG_NONE: return ""; + case OPT_ARG_INT: return ""; + case OPT_ARG_UINT: return ""; + case OPT_ARG_SECONDS: return ""; + case OPT_ARG_BYTES: return ""; + case OPT_ARG_TTL: return ""; + case OPT_ARG_PATTERN: return ""; + case OPT_ARG_STRING: return ""; + default: return ""; + } +} diff --git a/src/ping/cli/messages/help.c b/src/ping/cli/messages/help.c deleted file mode 100644 index 49d8bb9..0000000 --- a/src/ping/cli/messages/help.c +++ /dev/null @@ -1,46 +0,0 @@ -#include - -#include "internal/ping/cli_handlers.h" -#include "internal/cli/options.h" - -/* Forward declarations */ -static inline const char * option_arg_type_to_str(int type); -/* -------------------- */ - -void -print_help(void) -{ - printf("ft_ping - Send ICMP ECHO_REQUEST to network hosts\n"); - printf("Usage: ft_ping [options] \n\n"); - printf("Options:\n"); - - for (size_t i = 0; i < PING_OPT_LEN; ++i) - { - const struct option_descriptor *opt = &g_options[i]; - const char *argstr = option_arg_type_to_str(opt->arg_type); - - printf(" -%c, --%-15s %-8s %s\n", - opt->short_opt, - opt->long_opt, - argstr[0] ? argstr : "", - opt->description - ); - } -} - -static inline const char * -option_arg_type_to_str(int type) -{ - switch (type) - { - case OPT_ARG_NONE: return ""; - case OPT_ARG_INT: return ""; - case OPT_ARG_UINT: return ""; - case OPT_ARG_SECONDS: return ""; - case OPT_ARG_BYTES: return ""; - case OPT_ARG_TTL: return ""; - case OPT_ARG_PATTERN: return ""; - case OPT_ARG_STRING: return ""; - default: return ""; - } -}