🏗️」 wip: Added help msg

This commit is contained in:
2025-04-10 14:19:30 +02:00
parent 4a2bd9fe21
commit 8dff506caf
6 changed files with 103 additions and 7 deletions

View File

@ -38,6 +38,14 @@ ifeq ($(VERBOSE),true)
FLAGS += -D VERBOSE FLAGS += -D VERBOSE
endif endif
ifeq ($(TTY),true)
FLAGS += -D TTY
endif
ifeq ($(PKGS),true)
FLAGS += -D PKGS
endif
all: $(NAME) all: $(NAME)
$(NAME): $(OBJS) $(NAME): $(OBJS)

9
exemples/default.toml Normal file
View File

@ -0,0 +1,9 @@
[server]
host = "localhost"
port = 8080
[server.location./]
methods = { "GET" }
root = "/var/www/html"
dirlist = true
client_max_body_size = "10M"

16
includes/help.hpp Normal file
View File

@ -0,0 +1,16 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* help.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/10 13:43:54 by adjoly #+# #+# */
/* Updated: 2025/04/10 13:58:52 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#pragma once
#define SAMPLE_CONF_PATH "./sample.conf"
#define WEBSRV_VERSION "v0.1"

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/20 09:28:27 by adjoly #+# #+# */ /* Created: 2025/03/20 09:28:27 by adjoly #+# #+# */
/* Updated: 2025/03/25 17:50:45 by adjoly ### ########.fr */ /* Updated: 2025/04/10 13:56:33 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -29,10 +29,7 @@ class Logger {
_ttyOnly = false; _ttyOnly = false;
} }
if (!_file.is_open() && !_ttyOnly) { if (!_file.is_open() && !_ttyOnly) {
throw std::runtime_error( warn("could not open logfile, going tty only");
"could not open fileeee"); // TODO change that shit but i dont
// know what to put other than a
// htrow
} }
} }
@ -97,7 +94,8 @@ class Logger {
const std::string &what, const std::string &what,
const std::string &msg) { const std::string &msg) {
std::stringstream os; std::stringstream os;
#ifdef tty #ifdef TTY
(void)emoji;
if (what.empty()) if (what.empty())
os << type << ":" << msg; os << type << ":" << msg;
else else

View File

@ -6,7 +6,7 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */ /* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/11 13:29:21 by mmoussou #+# #+# */ /* Created: 2025/02/11 13:29:21 by mmoussou #+# #+# */
/* Updated: 2025/02/12 00:11:41 by mmoussou ### ########.fr */ /* Updated: 2025/04/10 13:58:56 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

65
src/help.cpp Normal file
View File

@ -0,0 +1,65 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* help.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/10 13:08:36 by adjoly #+# #+# */
/* Updated: 2025/04/10 14:19:20 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "log.hpp"
#include <fstream>
#include <help.hpp>
#include <sys/stat.h>
#include <unistd.h>
#include <webserv.hpp>
void _printHelp(void) {
std::cout << "-------------- WEBSERV --------------" << std::endl;
std::cout << "- --help : Print this message" << std::endl;
std::cout << "- --generate : Generate a sample config" << std::endl;
std::cout << "- --version : Gives you the version of the server"
<< std::endl;
std::cout << "-------------------------------------" << std::endl;
}
void _generateConf(void) {
webserv::Logger _log("");
if (access("./sample.conf", F_OK) == 0) {
_log.warn(std::string(SAMPLE_CONF_PATH) + " already exist, aborting");
} else {
_log.info("generating config into ./sample.conf...");
std::ofstream file("./sample.conf");
if (file.is_open()) {
file << "[server]\nhost = \"localhost\"\nport = "
"8080\n\n[server.location./]\nmethods = { \"GET\" }\nroot "
"= \"/var/www/html\"\ndirlist = true\nclient_max_body_size "
"= \"10M\"";
file.close();
_log.info("config file successfully generated");
} else {
_log.warn("could not generate, sample config file");
}
}
}
void _printVersion(void) {
std::cout << "You are running : Webserv " << WEBSRV_VERSION << std::endl;
}
void help(int ac, char **av) {
if (ac < 2) {
_printHelp();
return;
}
std::string option = av[1];
if (option == "--help")
_printHelp();
else if (option == "--generate" || option == "-g")
_generateConf();
else if (option == "--version" || option == "-v")
_printVersion();
}