feat(parsing/sources): adding the exception if no args provided

This commit is contained in:
Raphael 2026-03-28 15:44:50 +01:00
parent 144637684f
commit 5944b16609
No known key found for this signature in database

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */ /* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2026/03/23 14:49:36 by rparodi #+# #+# */ /* Created: 2026/03/23 14:49:36 by rparodi #+# #+# */
/* Updated: 2026/03/28 15:26:13 by rparodi ### ########.fr */ /* Updated: 2026/03/28 15:43:45 by rparodi ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -60,6 +60,10 @@ static struct option *_t_args_to_getopt_long(const size_t size) {
void parsing_args(int argc, char **argv, t_flags *flags) void parsing_args(int argc, char **argv, t_flags *flags)
{ {
if (argc == 1) {
dprintf(2, "%s: missing host operand \n Try 'ping --help' or 'ping --usage' for more information.", argv[0]);
exit(64);
}
const size_t size = args_size(); const size_t size = args_size();
size_t j = 0; size_t j = 0;
char args[2 * size + 1]; char args[2 * size + 1];
@ -127,6 +131,14 @@ void parsing_args(int argc, char **argv, t_flags *flags)
default: default:
if (strcmp(options[optind - 1].name, "usage")) if (strcmp(options[optind - 1].name, "usage"))
print_usage(size); print_usage(size);
else {
if (isprint(optopt)) {
char invalid_option[2] = {optopt, 0};
WARN_LOG(invalid_option);
}
dprintf(2, "Try 'ping --help' or 'ping --usage' for more information.\n");
exit(64);
}
} }
} }
free(options); free(options);