summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFélix Baylac-Jacqué <felix@alternativebit.fr>2020-08-31 22:26:21 +0200
committerlouiz’ <louiz@louiz.org>2020-09-23 23:55:50 +0200
commit0bb4f144fcded6b5753b5de7493b7b10474c9a1f (patch)
tree11b3d1fbdd86c9ff68147f3cca5934b9e834b285 /src
parent579d46f78ae5cf6a5e3e56772f7767d796765740 (diff)
downloadbiboumi-0bb4f144fcded6b5753b5de7493b7b10474c9a1f.tar.gz
biboumi-0bb4f144fcded6b5753b5de7493b7b10474c9a1f.tar.bz2
biboumi-0bb4f144fcded6b5753b5de7493b7b10474c9a1f.tar.xz
biboumi-0bb4f144fcded6b5753b5de7493b7b10474c9a1f.zip
CLI: Add a test config flag
Adding a -t configuration flag that will make biboumi check the configuration file syntax. Such a syntax check is handy for some deployment tools. It helps the tooling to statically analyse the configuration file and prevent unecessesary deployments when the configuration file is clearly incorrect. Updating the synopsis with this new flag.
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 2448197..21d0df8 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -38,7 +38,7 @@ int config_help(const std::string& missing_option)
int display_help()
{
- std::cout << "Usage: biboumi [configuration_file]" << std::endl;
+ std::cout << "Usage: biboumi [-ht] [configuration_file]" << std::endl;
return 0;
}
@@ -194,13 +194,19 @@ static int main_loop(std::string hostname, std::string password)
int main(int ac, char** av)
{
+ std::string cli_conf_filename;
+ bool test_conf = false;
if (ac > 1)
{
- const std::string arg = av[1];
- if (arg.size() >= 2 && arg[0] == '-' && arg[1] == '-')
+ for (int i = 1; i < ac; i++)
{
- if (arg == "--help")
+ const std::string arg = av[i];
+ if ((arg == "-h") || (arg == "--help"))
return display_help();
+ else if ((arg == "-t") || (arg == "--test-config"))
+ test_conf = true;
+ else if (i + 1 == ac)
+ cli_conf_filename = arg;
else
{
std::cerr << "Unknow command line option: " << arg
@@ -210,7 +216,7 @@ int main(int ac, char** av)
}
}
const std::string conf_filename =
- ac > 1 ? av[1]: xdg_config_path("biboumi.cfg");
+ cli_conf_filename.empty() ? xdg_config_path("biboumi.cfg"): cli_conf_filename;
std::cout << "Using configuration file: " << conf_filename << std::endl;
if (!Config::read_conf(conf_filename))
@@ -222,6 +228,12 @@ int main(int ac, char** av)
const std::string hostname = Config::get("hostname", "");
if (hostname.empty())
return config_help("hostname");
+ if (test_conf)
+ {
+ std::cout << "biboumi: the configuration file " << conf_filename
+ << " syntax is ok" << std::endl;
+ return 0;
+ }
#ifdef USE_DATABASE
try