From 876f00e63515ff382bf8a63b1f05f57afbc92cbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?kleines=20Filmr=C3=B6llchen?= Date: Tue, 7 Mar 2023 23:16:42 +0100 Subject: [PATCH] Base: Demonstrate ArgsParser and format strings in cli project template This demonstrates both an option and an optional positional argument, as well as some simple format string printing with {}. --- Base/res/devel/templates/cpp-basic/main.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/Base/res/devel/templates/cpp-basic/main.cpp b/Base/res/devel/templates/cpp-basic/main.cpp index 95efa135c0..0d35edce28 100644 --- a/Base/res/devel/templates/cpp-basic/main.cpp +++ b/Base/res/devel/templates/cpp-basic/main.cpp @@ -1,9 +1,24 @@ #include +#include +#include #include #include -ErrorOr serenity_main(Main::Arguments) +ErrorOr serenity_main(Main::Arguments arguments) { - outln("Hello friends!"); + int hello_count = 1; + StringView epilog; + + Core::ArgsParser parser; + parser.add_option(hello_count, "How often to print \"Hello friends!\"", "count", 'c', "hello-count"); + parser.add_positional_argument(epilog, "What to print at the end", "epilog", Core::ArgsParser::Required::No); + parser.parse(arguments); + + for (auto i = 0; i < hello_count; ++i) + outln("Hello friends!"); + + if (!epilog.is_empty()) + outln("And finally: {}", epilog); + return 0; }