Skip to content

Commit e9e68e9

Browse files
authored
Fix Default Config (#14)
1 parent 02143c1 commit e9e68e9

File tree

3 files changed

+38
-10
lines changed

3 files changed

+38
-10
lines changed

dependencies/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
## Author Francois Michaut
55
##
66
## Started on Wed Jul 10 10:27:39 2024 Francois Michaut
7-
## Last update Sun Aug 24 12:51:51 2025 Francois Michaut
7+
## Last update Sun Aug 24 20:00:59 2025 Francois Michaut
88
##
99
## CMakeLists.txt : CMake to fetch and build the dependecies of the FileShare executable
1010
##
@@ -40,7 +40,7 @@ FetchContent_Declare(
4040
FetchContent_Declare(
4141
fsp
4242
GIT_REPOSITORY https://github.com/FileShare-Project/libfsp.git
43-
GIT_TAG e36512b59f700abcc5cb379d77ee18aa8b6757fb
43+
GIT_TAG c3170e51e79d013763faca3e8deb618f47fefec9
4444
)
4545

4646
FetchContent_MakeAvailable(fsp argparse SFML sqlite_orm tgui)

source/cli/interactive.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,30 @@
44
** Author Francois Michaut
55
**
66
** Started on Wed Jul 23 13:49:52 2025 Francois Michaut
7-
** Last update Sat Aug 23 00:13:51 2025 Francois Michaut
7+
** Last update Sun Aug 24 19:57:35 2025 Francois Michaut
88
**
99
** interactive.cpp : Interractive Mode logic
1010
*/
1111

12-
#include "FileShare/Config/ServerConfig.hpp"
13-
#include "FileShare/Protocol/Definitions.hpp"
1412
#include "FileShareVersion.hpp"
1513

16-
#include <CppSockets/IPv4.hpp>
14+
#include <FileShare/Config/ServerConfig.hpp>
15+
#include <FileShare/Protocol/Definitions.hpp>
1716
#include <FileShare/Server.hpp>
1817
#include <FileShare/Utils/Poll.hpp>
1918
#include <FileShare/Utils/Strings.hpp>
2019
#include <FileShare/Utils/Path.hpp>
2120

21+
#include <CppSockets/IPv4.hpp>
22+
2223
#include <algorithm>
2324
#include <charconv>
2425
#include <csignal>
2526
#include <cstddef>
2627
#include <iostream>
2728
#include <sstream>
2829
#include <system_error>
30+
#include <unistd.h>
2931

3032
extern bool server_run;
3133
void signal_handler(int sig);

source/cli/main.cpp

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
** Author Francois Michaut
55
**
66
** Started on Sat Nov 11 11:06:03 2023 Francois Michaut
7-
** Last update Fri Aug 22 17:19:40 2025 Francois Michaut
7+
** Last update Sun Aug 24 20:04:30 2025 Francois Michaut
88
**
99
** main.cpp : Main entry point of FileShare CLI
1010
*/
@@ -29,6 +29,8 @@
2929
#define EXECUTE_ARG "--execute"
3030
#define CONFIG_ARG "--config"
3131
#define SERVER_CONFIG_ARG "--server-config"
32+
#define DEFAULT_CONFIG_ARG "--default-config"
33+
#define DEFAULT_SERVER_CONFIG_ARG "--default-server-config"
3234

3335
void interactive_mode(FileShare::Server &server);
3436

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

54+
parser->add_argument(DEFAULT_SERVER_CONFIG_ARG)
55+
.flag()
56+
.help("Use the default server config.");
57+
58+
parser->add_argument(DEFAULT_CONFIG_ARG)
59+
.flag()
60+
.help("Use the default peer config.");
61+
5262
parser->add_argument("-c", CONNECT_ARG)
5363
.nargs(1, 2)
5464
.help("Connect to an external server. Format '-c ip [port]'. Required to execute commands.");
@@ -124,13 +134,29 @@ static void run_server(FileShare::Server &server) {
124134
}
125135
}
126136

127-
static void run(std::shared_ptr<argparse::ArgumentParser> &parser) {
137+
static auto get_server_config(std::shared_ptr<argparse::ArgumentParser> &parser) -> FileShare::ServerConfig {
128138
auto server_config_path = parser->get<std::string>(SERVER_CONFIG_ARG);
139+
140+
if (parser->get<bool>(DEFAULT_SERVER_CONFIG_ARG)) {
141+
return FileShare::Server::default_config();
142+
}
143+
return FileShare::ServerConfig::load(server_config_path);
144+
}
145+
146+
static auto get_default_peer_config(std::shared_ptr<argparse::ArgumentParser> &parser) -> FileShare::Config {
129147
auto config_path = parser->get<std::string>(CONFIG_ARG);
148+
149+
if (parser->get<bool>(DEFAULT_CONFIG_ARG)) {
150+
return FileShare::Server::default_peer_config();
151+
}
152+
return FileShare::Config::load(config_path);
153+
}
154+
155+
static void run(std::shared_ptr<argparse::ArgumentParser> &parser) {
130156
auto cmds = parser->get<std::vector<std::string>>(EXECUTE_ARG);
131157

132-
FileShare::ServerConfig config = FileShare::ServerConfig::load(server_config_path);
133-
FileShare::Config peer_config = FileShare::Config::load(config_path);
158+
FileShare::ServerConfig config = get_server_config(parser);
159+
FileShare::Config peer_config = get_default_peer_config(parser);
134160

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

0 commit comments

Comments
 (0)