1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:07:35 +00:00

df: Port to LibMain

This commit is contained in:
Kenneth Myhra 2021-12-07 20:13:45 +01:00 committed by Brian Gianforcaro
parent 156899a63f
commit cd8bd27835
2 changed files with 6 additions and 10 deletions

View file

@ -80,6 +80,7 @@ target_link_libraries(cut LibMain)
target_link_libraries(date LibMain) target_link_libraries(date LibMain)
target_link_libraries(dd LibMain) target_link_libraries(dd LibMain)
target_link_libraries(ddate LibMain) target_link_libraries(ddate LibMain)
target_link_libraries(df LibMain)
target_link_libraries(diff LibDiff) target_link_libraries(diff LibDiff)
target_link_libraries(disasm LibX86) target_link_libraries(disasm LibX86)
target_link_libraries(dmesg LibMain) target_link_libraries(dmesg LibMain)

View file

@ -4,14 +4,13 @@
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
#include <AK/Assertions.h>
#include <AK/ByteBuffer.h>
#include <AK/JsonArray.h> #include <AK/JsonArray.h>
#include <AK/JsonObject.h> #include <AK/JsonObject.h>
#include <AK/NumberFormat.h> #include <AK/NumberFormat.h>
#include <AK/String.h> #include <AK/String.h>
#include <LibCore/ArgsParser.h> #include <LibCore/ArgsParser.h>
#include <LibCore/File.h> #include <LibCore/File.h>
#include <LibMain/Main.h>
#include <inttypes.h> #include <inttypes.h>
#include <stdlib.h> #include <stdlib.h>
@ -27,18 +26,14 @@ struct FileSystem {
String mount_point; String mount_point;
}; };
int main(int argc, char** argv) ErrorOr<int> serenity_main(Main::Arguments arguments)
{ {
Core::ArgsParser args_parser; Core::ArgsParser args_parser;
args_parser.set_general_help("Display free disk space of each partition."); args_parser.set_general_help("Display free disk space of each partition.");
args_parser.add_option(flag_human_readable, "Print human-readable sizes", "human-readable", 'h'); args_parser.add_option(flag_human_readable, "Print human-readable sizes", "human-readable", 'h');
args_parser.parse(argc, argv); args_parser.parse(arguments);
auto file = Core::File::construct("/proc/df"); auto file = TRY(Core::File::open("/proc/df", Core::OpenMode::ReadOnly));
if (!file->open(Core::OpenMode::ReadOnly)) {
warnln("Failed to open {}: {}", file->name(), file->error_string());
return 1;
}
if (flag_human_readable) { if (flag_human_readable) {
outln("Filesystem Size Used Available Mount point"); outln("Filesystem Size Used Available Mount point");
@ -47,7 +42,7 @@ int main(int argc, char** argv)
} }
auto file_contents = file->read_all(); auto file_contents = file->read_all();
auto json_result = JsonValue::from_string(file_contents).release_value_but_fixme_should_propagate_errors(); auto json_result = TRY(JsonValue::from_string(file_contents));
auto const& json = json_result.as_array(); auto const& json = json_result.as_array();
json.for_each([](auto& value) { json.for_each([](auto& value) {
auto& fs_object = value.as_object(); auto& fs_object = value.as_object();