Skip to content

Commit

Permalink
Raise an exception when = is used with short option
Browse files Browse the repository at this point in the history
It prevents silently skipping  the change in behavior between DNF4
and DNF5 Where `-x=dnf` excluded `dnf` but in DNF5 it excludes `=dnf`.
Without the exception it would be hard to detect that something might
work differently then expected.

Closes: rpm-software-management#1353
  • Loading branch information
j-mracek committed Apr 24, 2024
1 parent 077c7b1 commit 220c3b9
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions libdnf5-cli/argument_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -553,15 +553,18 @@ int ArgumentParser::NamedArg::parse_short(const char * option, int argc, const c
const char * arg_value;
int consumed_args;
if (has_value) {
if (option[1] != '\0') {
arg_value = option + 1;
consumed_args = 1;
} else {
if (option[1] == '\0') {
if (argc < 2) {
throw ArgumentParserNamedArgMissingValueError(M_("Missing value for named argument \"-{}\""), *option);
}
arg_value = argv[1];
consumed_args = 2;
} else if (option[1] == '=') {
throw ArgumentParserInvalidValueError(
M_("'=' is not supported delimiter for short option \"-{}\""), std::string(option));
} else {
arg_value = option + 1;
consumed_args = 1;
}
} else {
arg_value = const_val.c_str();
Expand Down

0 comments on commit 220c3b9

Please sign in to comment.