From 7d87f0d56df5765111e13263af3a15245031c7c7 Mon Sep 17 00:00:00 2001 From: Kenneth Myhra Date: Mon, 28 Mar 2022 21:12:18 +0200 Subject: [PATCH] markdown-check: Use Core::ArgsParser --- Userland/Utilities/markdown-check.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/Userland/Utilities/markdown-check.cpp b/Userland/Utilities/markdown-check.cpp index 7a9c17cf16..843c7ed5f1 100644 --- a/Userland/Utilities/markdown-check.cpp +++ b/Userland/Utilities/markdown-check.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -224,18 +225,14 @@ RecursionDecision MarkdownLinkage::visit(Markdown::Text::LinkNode const& link_no ErrorOr serenity_main(Main::Arguments arguments) { - if (arguments.strings.size() < 2) { - // Technically it is valid to call this program with zero markdown files: When there are - // no files, there are no dead links. However, any such usage is probably erroneous. - warnln("Usage: {} Foo.md Bar.md ...", arguments.strings[0]); - // E.g.: find AK/ Base/ Documentation/ Kernel/ Meta/ Ports/ Tests/ Userland/ -name '*.md' -print0 | xargs -0 ./MarkdownCheck - return 1; - } + Core::ArgsParser args_parser; + Vector file_paths; + args_parser.add_positional_argument(file_paths, "Path to markdown files to read and parse", "paths", Core::ArgsParser::Required::Yes); + args_parser.parse(arguments); outln("Reading and parsing Markdown files ..."); HashMap files; - for (size_t i = 1; i < arguments.strings.size(); ++i) { - auto path = arguments.strings[i]; + for (auto path : file_paths) { auto file_or_error = Core::File::open(path, Core::OpenMode::ReadOnly); if (file_or_error.is_error()) { warnln("Failed to read {}: {}", path, file_or_error.error());