Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a list of supported types to clean command description #1100

Merged
merged 1 commit into from
Dec 15, 2023
Merged
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
24 changes: 13 additions & 11 deletions dnf5/commands/clean/clean.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,25 @@ void CleanCommand::set_argument_parser() {
auto & cmd = *get_argument_parser_command();
cmd.set_description("Remove or expire cached data");

std::string known_types;
bool first = true;
for (const auto & type : CACHE_TYPES) {
if (!first) {
known_types.append(", ");
}
known_types.append(type.name);
first = false;
}

auto cache_types =
parser.add_new_positional_arg("cache_types", ArgumentParser::PositionalArg::AT_LEAST_ONE, nullptr, nullptr);
cache_types->set_description("List of cache types to clean up");
cache_types->set_description(
libdnf5::utils::sformat(_("List of cache types to clean up. Supported types: {0}"), known_types));

cache_types->set_parse_hook_func(
// Parses arguments and sets the appropriate bits in the required_actions.
// An exception is thrown if an unknown argument is found.
[this]([[maybe_unused]] ArgumentParser::PositionalArg * arg, int argc, const char * const argv[]) {
[this, known_types]([[maybe_unused]] ArgumentParser::PositionalArg * arg, int argc, const char * const argv[]) {
for (int i = 0; i < argc; ++i) {
const std::string_view cache_type{argv[i]};
bool found{false};
Expand All @@ -89,15 +100,6 @@ void CleanCommand::set_argument_parser() {
}
}
if (!found) {
std::string known_types;
bool first = true;
for (const auto & type : CACHE_TYPES) {
if (!first) {
known_types.append(", ");
}
known_types.append(type.name);
first = false;
}
throw libdnf5::cli::ArgumentParserUnknownArgumentError(
M_("Unknown cache type \"{0}\". Supported types: {1}"), std::string(argv[i]), known_types);
}
Expand Down
Loading