diff options
author | Ali Mohammad Pur <ali.mpfard@gmail.com> | 2022-03-23 17:57:54 +0430 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2022-03-26 21:34:56 +0430 |
commit | ef5523231cdacbb314862913b77f2ebea3a663ff (patch) | |
tree | 5a379130e26fc35e5dbd9be04bb1d542cab466db /Userland/Libraries/LibCore/ArgsParser.cpp | |
parent | d995be428a0853323c04cf8431046987992e4f56 (diff) | |
download | serenity-ef5523231cdacbb314862913b77f2ebea3a663ff.zip |
Shell+LibCore: Provide argument help strings as display trivia
Diffstat (limited to 'Userland/Libraries/LibCore/ArgsParser.cpp')
-rw-r--r-- | Userland/Libraries/LibCore/ArgsParser.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/Userland/Libraries/LibCore/ArgsParser.cpp b/Userland/Libraries/LibCore/ArgsParser.cpp index a4f56bba20..c60b8a37d4 100644 --- a/Userland/Libraries/LibCore/ArgsParser.cpp +++ b/Userland/Libraries/LibCore/ArgsParser.cpp @@ -716,11 +716,13 @@ void ArgsParser::autocomplete(FILE* file, StringView program_name, Span<char con if (!completing_option) return; - auto write_completion = [&](auto format, auto... args) { + auto write_completion = [&](auto format, auto& option, auto... args) { JsonObject object; object.set("completion", String::formatted(format, args...)); object.set("static_offset", 0); object.set("invariant_offset", option_to_complete.length()); + object.set("display_trivia", option.help_string); + object.set("trailing_trivia", option.requires_argument ? " " : ""); outln(file, "{}", object.to_string()); }; @@ -730,7 +732,7 @@ void ArgsParser::autocomplete(FILE* file, StringView program_name, Span<char con for (auto& option : m_options) { StringView option_string = option.long_name; if (option_string.starts_with(option_pattern)) { - write_completion("--{}", option_string); + write_completion("--{}", option, option_string); } } } else { @@ -739,7 +741,7 @@ void ArgsParser::autocomplete(FILE* file, StringView program_name, Span<char con if (option.short_name == 0) continue; - write_completion("-{}", option.short_name); + write_completion("-{}", option, option.short_name); } } } |