diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2023-02-13 11:26:38 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-13 11:26:38 +0100 |
commit | 2037f8a3ee55406e743d81b4d09fed24fe846082 (patch) | |
tree | be647f85698e6fc268e91b6a715882d029668dd5 /src | |
parent | c18456604601dd233be4ad2462474488ef8f87e3 (diff) | |
parent | 30edd7af532bb893f76d5d4e7ec0fadfcdc941c6 (diff) |
Merge pull request #7804 from PJungkamp/fix-completions
Infer short completion descriptions for commandline flags
Diffstat (limited to 'src')
-rw-r--r-- | src/libutil/args.cc | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/libutil/args.cc b/src/libutil/args.cc index 2930913d6..35686a8aa 100644 --- a/src/libutil/args.cc +++ b/src/libutil/args.cc @@ -29,7 +29,15 @@ void Args::removeFlag(const std::string & longName) 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 { .completion = completion, .description = description |