Merge pull request #7804 from PJungkamp/fix-completions

Infer short completion descriptions for commandline flags
This commit is contained in:
Eelco Dolstra 2023-02-13 11:26:38 +01:00 committed by GitHub
commit 2037f8a3ee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -29,7 +29,15 @@ void Args::removeFlag(const std::string & longName)
void Completions::add(std::string completion, std::string description) void Completions::add(std::string completion, std::string description)
{ {
assert(description.find('\n') == std::string::npos); description = trim(description);
// ellipsize overflowing content on the back of the description
auto end_index = description.find_first_of(".\n");
if (end_index != std::string::npos) {
auto needs_ellipsis = end_index != description.size() - 1;
description.resize(end_index);
if (needs_ellipsis)
description.append(" [...]");
}
insert(Completion { insert(Completion {
.completion = completion, .completion = completion,
.description = description .description = description