Serenity Operating System
at master 38 lines 1.1 kB view raw
1/* 2 * Copyright (c) 2020, Sergey Bugaev <bugaevc@serenityos.org> 3 * Copyright (c) 2020, Linus Groh <linusg@serenityos.org> 4 * 5 * SPDX-License-Identifier: BSD-2-Clause 6 */ 7 8#include <AK/URL.h> 9#include <AK/Vector.h> 10#include <LibCore/ArgsParser.h> 11#include <LibCore/DeprecatedFile.h> 12#include <LibCore/EventLoop.h> 13#include <LibDesktop/Launcher.h> 14#include <LibMain/Main.h> 15 16ErrorOr<int> serenity_main(Main::Arguments arguments) 17{ 18 Core::EventLoop loop; 19 Vector<StringView> urls_or_paths; 20 Core::ArgsParser parser; 21 parser.set_general_help("Open a file or URL by executing the appropriate program."); 22 parser.add_positional_argument(urls_or_paths, "URL or file path to open", "url-or-path"); 23 parser.parse(arguments); 24 25 bool all_ok = true; 26 27 for (auto& url_or_path : urls_or_paths) { 28 auto path = Core::DeprecatedFile::real_path_for(url_or_path); 29 auto url = URL::create_with_url_or_path(path.is_null() ? url_or_path : path.view()); 30 31 if (!Desktop::Launcher::open(url)) { 32 warnln("Failed to open '{}'", url); 33 all_ok = false; 34 } 35 } 36 37 return all_ok ? 0 : 1; 38}