Made a basic arg parser and shell implementation of the Server class

This commit is contained in:
iherman-
2026-05-06 18:07:17 +02:00
parent d2e02440b3
commit b47c7dc9b8
5 changed files with 142 additions and 8 deletions

49
main.cpp Normal file
View File

@@ -0,0 +1,49 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: iherman- <iherman-@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/05/06 17:57:53 by iherman- #+# #+# */
/* Updated: 2026/05/06 17:57:58 by iherman- ### ########.fr */
/* */
/* ************************************************************************** */
#include "Server/Server.hpp"
int get_port(const char* arg)
{
std::stringstream input(arg);
int port;
if (!(input >> port))
throw std::runtime_error("Invalid port");
if (input.peek() != EOF)
throw std::runtime_error("Malformed port");
return port;
}
int main(int argc, char *argv[])
{
if (argc != 3)
{
std::cerr << "Usage: ./ircserv <port> <password>" << std::endl;
return 1;
}
try
{
int port = get_port(argv[1]);
Server server(port, argv[2]);
}
catch (std::exception& e)
{
std::cerr << e.what() << std::endl;
return 1;
}
// run server
}