Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dependencies/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
## Author Francois Michaut
##
## Started on Wed Jul 10 10:27:39 2024 Francois Michaut
## Last update Sun Aug 24 12:51:51 2025 Francois Michaut
## Last update Sun Aug 24 20:00:59 2025 Francois Michaut
##
## CMakeLists.txt : CMake to fetch and build the dependecies of the FileShare executable
##
Expand Down Expand Up @@ -40,7 +40,7 @@ FetchContent_Declare(
FetchContent_Declare(
fsp
GIT_REPOSITORY https://github.com/FileShare-Project/libfsp.git
GIT_TAG e36512b59f700abcc5cb379d77ee18aa8b6757fb
GIT_TAG c3170e51e79d013763faca3e8deb618f47fefec9
)

FetchContent_MakeAvailable(fsp argparse SFML sqlite_orm tgui)
10 changes: 6 additions & 4 deletions source/cli/interactive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,30 @@
** Author Francois Michaut
**
** Started on Wed Jul 23 13:49:52 2025 Francois Michaut
** Last update Sat Aug 23 00:13:51 2025 Francois Michaut
** Last update Sun Aug 24 19:57:35 2025 Francois Michaut
**
** interactive.cpp : Interractive Mode logic
*/

#include "FileShare/Config/ServerConfig.hpp"
#include "FileShare/Protocol/Definitions.hpp"
#include "FileShareVersion.hpp"

#include <CppSockets/IPv4.hpp>
#include <FileShare/Config/ServerConfig.hpp>
#include <FileShare/Protocol/Definitions.hpp>
#include <FileShare/Server.hpp>
#include <FileShare/Utils/Poll.hpp>
#include <FileShare/Utils/Strings.hpp>
#include <FileShare/Utils/Path.hpp>

#include <CppSockets/IPv4.hpp>

#include <algorithm>
#include <charconv>
#include <csignal>
#include <cstddef>
#include <iostream>
#include <sstream>
#include <system_error>
#include <unistd.h>

extern bool server_run;
void signal_handler(int sig);
Expand Down
34 changes: 30 additions & 4 deletions source/cli/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
** Author Francois Michaut
**
** Started on Sat Nov 11 11:06:03 2023 Francois Michaut
** Last update Fri Aug 22 17:19:40 2025 Francois Michaut
** Last update Sun Aug 24 20:04:30 2025 Francois Michaut
**
** main.cpp : Main entry point of FileShare CLI
*/
Expand All @@ -29,6 +29,8 @@
#define EXECUTE_ARG "--execute"
#define CONFIG_ARG "--config"
#define SERVER_CONFIG_ARG "--server-config"
#define DEFAULT_CONFIG_ARG "--default-config"
#define DEFAULT_SERVER_CONFIG_ARG "--default-server-config"

void interactive_mode(FileShare::Server &server);

Expand All @@ -49,6 +51,14 @@ static auto setup_args() -> std::shared_ptr<argparse::ArgumentParser> {
.default_value("")
.help("Speficy the path to the peer config file.");

parser->add_argument(DEFAULT_SERVER_CONFIG_ARG)
.flag()
.help("Use the default server config.");

parser->add_argument(DEFAULT_CONFIG_ARG)
.flag()
.help("Use the default peer config.");

parser->add_argument("-c", CONNECT_ARG)
.nargs(1, 2)
.help("Connect to an external server. Format '-c ip [port]'. Required to execute commands.");
Expand Down Expand Up @@ -124,13 +134,29 @@ static void run_server(FileShare::Server &server) {
}
}

static void run(std::shared_ptr<argparse::ArgumentParser> &parser) {
static auto get_server_config(std::shared_ptr<argparse::ArgumentParser> &parser) -> FileShare::ServerConfig {
auto server_config_path = parser->get<std::string>(SERVER_CONFIG_ARG);

if (parser->get<bool>(DEFAULT_SERVER_CONFIG_ARG)) {
return FileShare::Server::default_config();
}
return FileShare::ServerConfig::load(server_config_path);
}

static auto get_default_peer_config(std::shared_ptr<argparse::ArgumentParser> &parser) -> FileShare::Config {
auto config_path = parser->get<std::string>(CONFIG_ARG);

if (parser->get<bool>(DEFAULT_CONFIG_ARG)) {
return FileShare::Server::default_peer_config();
}
return FileShare::Config::load(config_path);
}

static void run(std::shared_ptr<argparse::ArgumentParser> &parser) {
auto cmds = parser->get<std::vector<std::string>>(EXECUTE_ARG);

FileShare::ServerConfig config = FileShare::ServerConfig::load(server_config_path);
FileShare::Config peer_config = FileShare::Config::load(config_path);
FileShare::ServerConfig config = get_server_config(parser);
FileShare::Config peer_config = get_default_peer_config(parser);

config.set_server_disabled(!parser->get<bool>(SERVER_ARG));
FileShare::Server server(config, peer_config);
Expand Down
Loading