1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 08:34:57 +00:00

tree: Port to LibMain

This commit is contained in:
Names4Noobs 2022-01-24 20:18:18 -05:00 committed by Brian Gianforcaro
parent 790274d4a5
commit a4495bdcba
2 changed files with 8 additions and 7 deletions

View file

@ -1,5 +1,6 @@
/*
* Copyright (c) 2020, Stijn De Ridder <stijn.deridder@hotmail.com>
* Copyright (c) 2022, the SerenityOS developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -11,6 +12,8 @@
#include <AK/Vector.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/DirIterator.h>
#include <LibCore/System.h>
#include <LibMain/Main.h>
#include <errno.h>
#include <limits.h>
#include <stdio.h>
@ -99,12 +102,9 @@ static void print_directory_tree(const String& root_path, int depth, const Strin
}
}
int main(int argc, char** argv)
ErrorOr<int> serenity_main(Main::Arguments arguments)
{
if (pledge("stdio rpath tty", nullptr) < 0) {
perror("pledge");
return 1;
}
TRY(Core::System::pledge("stdio rpath tty"));
Vector<const char*> directories;
@ -113,10 +113,10 @@ int main(int argc, char** argv)
args_parser.add_option(flag_show_only_directories, "Show only directories", "only-directories", 'd');
args_parser.add_option(max_depth, "Maximum depth of the tree", "maximum-depth", 'L', "level");
args_parser.add_positional_argument(directories, "Directories to print", "directories", Core::ArgsParser::Required::No);
args_parser.parse(argc, argv);
args_parser.parse(arguments);
if (max_depth < 1) {
warnln("{}: Invalid level, must be greater than 0.", argv[0]);
warnln("{}: Invalid level, must be greater than 0.", arguments.argv[0]);
return 1;
}