net-tools/src/ping/cli/messages/help.c

45 lines
1.1 KiB
C

#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(enum option_arg_type 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, --%-10s %-8s %s\n",
opt->short_opt,
opt->long_opt,
argstr[0] ? argstr : "",
opt->description
);
}
}
static inline const char *
option_arg_type_to_str(enum option_arg_type 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_STRING: return "<STR>";
default: return "<ARG>";
}
}