mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:17:44 +00:00
markdown-check: Use Core::ArgsParser
This commit is contained in:
parent
de7d333d43
commit
7d87f0d56d
1 changed files with 6 additions and 9 deletions
|
@ -18,6 +18,7 @@
|
||||||
#include <AK/RecursionDecision.h>
|
#include <AK/RecursionDecision.h>
|
||||||
#include <AK/URL.h>
|
#include <AK/URL.h>
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
|
#include <LibCore/ArgsParser.h>
|
||||||
#include <LibCore/File.h>
|
#include <LibCore/File.h>
|
||||||
#include <LibMain/Main.h>
|
#include <LibMain/Main.h>
|
||||||
#include <LibMarkdown/Document.h>
|
#include <LibMarkdown/Document.h>
|
||||||
|
@ -224,18 +225,14 @@ RecursionDecision MarkdownLinkage::visit(Markdown::Text::LinkNode const& link_no
|
||||||
|
|
||||||
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
{
|
{
|
||||||
if (arguments.strings.size() < 2) {
|
Core::ArgsParser args_parser;
|
||||||
// Technically it is valid to call this program with zero markdown files: When there are
|
Vector<StringView> file_paths;
|
||||||
// no files, there are no dead links. However, any such usage is probably erroneous.
|
args_parser.add_positional_argument(file_paths, "Path to markdown files to read and parse", "paths", Core::ArgsParser::Required::Yes);
|
||||||
warnln("Usage: {} Foo.md Bar.md ...", arguments.strings[0]);
|
args_parser.parse(arguments);
|
||||||
// E.g.: find AK/ Base/ Documentation/ Kernel/ Meta/ Ports/ Tests/ Userland/ -name '*.md' -print0 | xargs -0 ./MarkdownCheck
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
outln("Reading and parsing Markdown files ...");
|
outln("Reading and parsing Markdown files ...");
|
||||||
HashMap<String, MarkdownLinkage> files;
|
HashMap<String, MarkdownLinkage> files;
|
||||||
for (size_t i = 1; i < arguments.strings.size(); ++i) {
|
for (auto path : file_paths) {
|
||||||
auto path = arguments.strings[i];
|
|
||||||
auto file_or_error = Core::File::open(path, Core::OpenMode::ReadOnly);
|
auto file_or_error = Core::File::open(path, Core::OpenMode::ReadOnly);
|
||||||
if (file_or_error.is_error()) {
|
if (file_or_error.is_error()) {
|
||||||
warnln("Failed to read {}: {}", path, file_or_error.error());
|
warnln("Failed to read {}: {}", path, file_or_error.error());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue