From 257ff100e3a790d70425d6904e88e2a8f8340896 Mon Sep 17 00:00:00 2001 From: lohhiiccc <96543753+lohhiiccc@users.noreply.github.com> Date: Sun, 1 Mar 2026 13:56:07 +0100 Subject: [PATCH] feat: implement help command handlers --- src/cli/handlers/handle_help.c | 45 ++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/src/cli/handlers/handle_help.c b/src/cli/handlers/handle_help.c index 02efcf4..c3beaa7 100644 --- a/src/cli/handlers/handle_help.c +++ b/src/cli/handlers/handle_help.c @@ -1,9 +1,50 @@ +#include "cli.h" #include "ft_ping.h" +#include +#include +#include + +/* Forward declarations */ +static const char * option_arg_type_to_str(t_option_arg_type type); +/* -------------------- */ int cli_handle_help(const char *arg, t_ping_config *config) { - (void)arg; (void)config; - return 1; + (void)arg; + + 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 < g_options_len; ++i) + { + const t_option_descriptor *opt = &g_options[i]; + const char *argstr = option_arg_type_to_str(opt->arg_type); + + printf(" -%c, --%-10s %-8s %s\n", + opt->short_opt, + opt->long_opt, + argstr[0] ? argstr : "", + opt->description + ); + } + return -1; +} + +static const char * +option_arg_type_to_str(t_option_arg_type 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_STRING: return ""; + default: return ""; + } }