diff --git a/Base/usr/share/man/man1/config.md b/Base/usr/share/man/man1/config.md index ed24379ba9..7917e79c0c 100644 --- a/Base/usr/share/man/man1/config.md +++ b/Base/usr/share/man/man1/config.md @@ -5,7 +5,7 @@ config ## Synopsis ```sh -$ config [--remove] [value] +$ config [--remove] [key] [value] ``` ## Description @@ -14,7 +14,7 @@ Show or modify values in the configuration files through ConfigServer. ## Options: -* `-r`, `--remove`: Remove key +* `-r`, `--remove`: Remove group or key ## Arguments: diff --git a/Userland/Utilities/config.cpp b/Userland/Utilities/config.cpp index d0ed97d897..b96d60b5e1 100644 --- a/Userland/Utilities/config.cpp +++ b/Userland/Utilities/config.cpp @@ -16,23 +16,31 @@ ErrorOr serenity_main(Main::Arguments arguments) String group; String key; String value_to_write; - bool remove_key = false; + bool remove = false; Core::ArgsParser args_parser; args_parser.set_general_help("Show or modify values in the configuration files through ConfigServer."); - args_parser.add_option(remove_key, "Remove key", "remove", 'r'); + args_parser.add_option(remove, "Remove group or key", "remove", 'r'); args_parser.add_positional_argument(domain, "Config domain", "domain"); args_parser.add_positional_argument(group, "Group name", "group"); - args_parser.add_positional_argument(key, "Key name", "key"); + args_parser.add_positional_argument(key, "Key name", "key", Core::ArgsParser::Required::No); args_parser.add_positional_argument(value_to_write, "Value to write", "value", Core::ArgsParser::Required::No); args_parser.parse(arguments); - if (remove_key) { - Config::remove_key(domain, group, key); + if (remove) { + if (!key.is_null()) + Config::remove_key(domain, group, key); + else + Config::remove_group(domain, group); return 0; } - if (!value_to_write.is_null()) { + 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()) { Config::write_string(domain, group, key, value_to_write); return 0; }