mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 09:51:57 -05:00
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 {}.
This commit is contained in:
parent
fd68e9f1ac
commit
876f00e635
1 changed files with 17 additions and 2 deletions
|
@ -1,9 +1,24 @@
|
|||
#include <AK/Format.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <LibCore/ArgsParser.h>
|
||||
#include <LibCore/System.h>
|
||||
#include <LibMain/Main.h>
|
||||
|
||||
ErrorOr<int> serenity_main(Main::Arguments)
|
||||
ErrorOr<int> 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;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue