2021-08-26 08:24:14 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, the SerenityOS developers.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <LibConfig/Client.h>
|
|
|
|
#include <LibCore/ArgsParser.h>
|
|
|
|
#include <LibCore/EventLoop.h>
|
2021-11-27 20:02:54 +00:00
|
|
|
#include <LibMain/Main.h>
|
2021-08-26 08:24:14 +00:00
|
|
|
|
2021-11-27 20:02:54 +00:00
|
|
|
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
2021-08-26 08:24:14 +00:00
|
|
|
{
|
|
|
|
Core::EventLoop loop;
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString domain;
|
|
|
|
DeprecatedString group;
|
|
|
|
DeprecatedString key;
|
|
|
|
DeprecatedString value_to_write;
|
2022-09-23 13:54:06 +00:00
|
|
|
bool remove = false;
|
2021-08-26 08:24:14 +00:00
|
|
|
|
|
|
|
Core::ArgsParser args_parser;
|
|
|
|
args_parser.set_general_help("Show or modify values in the configuration files through ConfigServer.");
|
2022-09-23 13:54:06 +00:00
|
|
|
args_parser.add_option(remove, "Remove group or key", "remove", 'r');
|
2021-08-26 08:24:14 +00:00
|
|
|
args_parser.add_positional_argument(domain, "Config domain", "domain");
|
|
|
|
args_parser.add_positional_argument(group, "Group name", "group");
|
2022-09-23 13:54:06 +00:00
|
|
|
args_parser.add_positional_argument(key, "Key name", "key", Core::ArgsParser::Required::No);
|
2021-08-26 08:24:14 +00:00
|
|
|
args_parser.add_positional_argument(value_to_write, "Value to write", "value", Core::ArgsParser::Required::No);
|
2021-11-27 20:02:54 +00:00
|
|
|
args_parser.parse(arguments);
|
2021-08-26 08:24:14 +00:00
|
|
|
|
2022-09-23 13:54:06 +00:00
|
|
|
if (remove) {
|
|
|
|
if (!key.is_null())
|
|
|
|
Config::remove_key(domain, group, key);
|
|
|
|
else
|
|
|
|
Config::remove_group(domain, group);
|
2021-11-13 14:05:53 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-09-23 13:54:06 +00:00
|
|
|
if (key.is_null() && value_to_write.is_null()) {
|
|
|
|
Config::add_group(domain, group);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!key.is_null() && !value_to_write.is_null()) {
|
2021-08-26 08:24:14 +00:00
|
|
|
Config::write_string(domain, group, key, value_to_write);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-08-28 14:10:41 +00:00
|
|
|
auto value_or_error = Config::Client::the().read_string_value(domain, group, key);
|
|
|
|
if (!value_or_error.has_value())
|
|
|
|
return 1;
|
|
|
|
outln("{}", value_or_error.value());
|
2021-08-26 08:24:14 +00:00
|
|
|
return 0;
|
|
|
|
}
|