Skip to content

Commit

Permalink
Fix short option error
Browse files Browse the repository at this point in the history
  • Loading branch information
jonmeow committed Jan 13, 2025
1 parent 3a44b65 commit 9afadf3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
9 changes: 5 additions & 4 deletions common/command_line.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1035,11 +1035,12 @@ auto Parser::ParseShortOptionSeq(llvm::StringRef unparsed_arg)
unparsed_arg));
}

for (unsigned char c : unparsed_arg) {
auto* arg_entry =
(c < short_option_table_.size()) ? short_option_table_[c] : nullptr;
for (char c : unparsed_arg) {
auto* arg_entry = (c < static_cast<ssize_t>(short_option_table_.size()))
? short_option_table_[c]
: nullptr;
if (!arg_entry) {
return Error(llvm::formatv("unknown short option `{0}`", c));
return Error(llvm::formatv("unknown short option `-{0}`", c));
}
// Mark this argument as parsed.
arg_entry->setInt(true);
Expand Down
3 changes: 3 additions & 0 deletions common/command_line_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ TEST(ArgParserTest, ShortArgs) {
EXPECT_THAT(integer_option, Eq(123));

TestRawOstream os;

EXPECT_THAT(parse({"-v"}, os), IsError(StrEq("unknown short option `-v`")));

EXPECT_THAT(
parse({"-xzf"}, os),
IsError(StrEq("option `-z` (short for `--option2`) requires a value to "
Expand Down

0 comments on commit 9afadf3

Please sign in to comment.