fix: use build in libcli print help function

This commit is contained in:
lohhiiccc 2026-04-27 14:57:35 +02:00
parent dccdca8114
commit b75f2964e5
3 changed files with 28 additions and 49 deletions

View file

@ -62,7 +62,6 @@ libping_core_la_SOURCES = \
cli/parse_utils/parse_inet_addr.c \ cli/parse_utils/parse_inet_addr.c \
cli/parse_utils/parse_destinations.c \ cli/parse_utils/parse_destinations.c \
cli/config_free.c \ cli/config_free.c \
cli/messages/help.c \
cli/messages/version.c \ cli/messages/version.c \
cli/messages/error.c \ cli/messages/error.c \
core/ping.c \ core/ping.c \

View file

@ -1,11 +1,37 @@
#include <stdio.h>
#include "cli.h"
#include "compiler.h" #include "compiler.h"
#include "internal/cli/options.h"
#include "internal/ping/cli_handlers.h"
#include "ping/cli.h" #include "ping/cli.h"
#include "internal/cli/messages.h"
/* Forward declarations */
static inline const char * option_arg_type_to_str(int type);
/* -------------------- */
int int
cli_handle_help(__unused const char *arg, __unused void *config_void) 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] <destination>\n\n");
cli_print_options(g_options, PING_OPT_LEN, option_arg_type_to_str);
return CLI_EXIT_SUCCESS; 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 "<NUM>";
case OPT_ARG_UINT: return "<NUM>";
case OPT_ARG_SECONDS: return "<SEC>";
case OPT_ARG_BYTES: return "<SIZE>";
case OPT_ARG_TTL: return "<TTL>";
case OPT_ARG_PATTERN: return "<HEX>";
case OPT_ARG_STRING: return "<STR>";
default: return "<ARG>";
}
}

View file

@ -1,46 +0,0 @@
#include <stdio.h>
#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] <destination>\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 "<NUM>";
case OPT_ARG_UINT: return "<NUM>";
case OPT_ARG_SECONDS: return "<SEC>";
case OPT_ARG_BYTES: return "<SIZE>";
case OPT_ARG_TTL: return "<TTL>";
case OPT_ARG_PATTERN: return "<HEX>";
case OPT_ARG_STRING: return "<STR>";
default: return "<ARG>";
}
}