Made a basic arg parser and shell implementation of the Server class
This commit is contained in:
49
main.cpp
Normal file
49
main.cpp
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user