feat: implement help command handlers
This commit is contained in:
parent
b786e79287
commit
257ff100e3
1 changed files with 43 additions and 2 deletions
|
|
@ -1,9 +1,50 @@
|
||||||
|
#include "cli.h"
|
||||||
#include "ft_ping.h"
|
#include "ft_ping.h"
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <getopt.h>
|
||||||
|
|
||||||
|
/* Forward declarations */
|
||||||
|
static const char * option_arg_type_to_str(t_option_arg_type type);
|
||||||
|
/* -------------------- */
|
||||||
|
|
||||||
int
|
int
|
||||||
cli_handle_help(const char *arg, t_ping_config *config)
|
cli_handle_help(const char *arg, t_ping_config *config)
|
||||||
{
|
{
|
||||||
(void)arg;
|
|
||||||
(void)config;
|
(void)config;
|
||||||
return 1;
|
(void)arg;
|
||||||
|
|
||||||
|
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 < 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 "<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>";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue