diff options
author | Ben Wiederhake <BenWiederhake.GitHub@gmx.de> | 2020-12-05 15:54:27 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-12-06 00:06:53 +0100 |
commit | 52a80620847e5ff934c7a385c106d098d60a8a6c (patch) | |
tree | 26addd5624216f120cc69526b89ab012b123ce44 /Libraries/LibCore | |
parent | 886b43e999cbc7b20a9792c9d610267b76930c05 (diff) | |
download | serenity-52a80620847e5ff934c7a385c106d098d60a8a6c.zip |
LibCore: Offer to display a general description
Diffstat (limited to 'Libraries/LibCore')
-rw-r--r-- | Libraries/LibCore/ArgsParser.cpp | 5 | ||||
-rw-r--r-- | Libraries/LibCore/ArgsParser.h | 3 |
2 files changed, 8 insertions, 0 deletions
diff --git a/Libraries/LibCore/ArgsParser.cpp b/Libraries/LibCore/ArgsParser.cpp index bef5515420..16583b9012 100644 --- a/Libraries/LibCore/ArgsParser.cpp +++ b/Libraries/LibCore/ArgsParser.cpp @@ -206,6 +206,11 @@ void ArgsParser::print_usage(FILE* file, const char* argv0) } outln(file); + if (m_general_help != nullptr && m_general_help[0] != '\0') { + outln(file, "\nDescription:"); + outln(file, m_general_help); + } + if (!m_options.is_empty()) outln(file, "\nOptions:"); for (auto& opt : m_options) { diff --git a/Libraries/LibCore/ArgsParser.h b/Libraries/LibCore/ArgsParser.h index 59362cc013..2f7b923a9d 100644 --- a/Libraries/LibCore/ArgsParser.h +++ b/Libraries/LibCore/ArgsParser.h @@ -67,6 +67,8 @@ public: }; bool parse(int argc, char** argv, bool exit_on_failure = true); + // *Without* trailing newline! + void set_general_help(const char* help_string) { m_general_help = help_string; }; void print_usage(FILE*, const char* argv0); void add_option(Option&&); @@ -86,6 +88,7 @@ private: Vector<Arg> m_positional_args; bool m_show_help { false }; + const char* m_general_help { nullptr }; }; } |