Luna/utils/cat.cpp
apio 140910763e
All checks were successful
Build and test / build (push) Successful in 1m56s
all: Reorder directory structure
Why are command-line utilities stored in "apps"?
And why are apps like "editor" or "terminal" top-level directories?
Command-line utilities now go in "utils".
GUI stuff now goes in "gui".
This includes: libui -> gui/libui, wind -> gui/wind, GUI apps -> gui/apps, editor&terminal -> gui/apps...
System services go in "system".
2024-07-21 13:24:46 +02:00

38 lines
813 B
C++

#include <luna/String.h>
#include <os/ArgumentParser.h>
#include <os/File.h>
using os::File;
static Result<void> do_cat(StringView path)
{
SharedPtr<File> f = TRY(File::open_input_file(path));
auto out = File::standard_output();
auto buf = TRY(Buffer::create_sized(4096));
while (1)
{
TRY(f->read(buf, 4096));
if (buf.is_empty()) break;
out->write(buf);
}
return {};
}
Result<int> luna_main(int argc, char** argv)
{
Vector<StringView> files;
os::ArgumentParser parser;
parser.add_description("Concatenate files to standard output."_sv);
parser.add_system_program_info("cat"_sv);
parser.set_vector_argument(files, "files"_sv, "-"_sv);
TRY(parser.parse(argc, argv));
for (auto file : files) TRY(do_cat(file));
return 0;
}