Luna/apps/edit.cpp

29 lines
591 B
C++
Raw Normal View History

#include <os/ArgumentParser.h>
#include <os/File.h>
2023-03-23 23:52:26 +00:00
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
2023-04-13 15:04:59 +00:00
Result<int> luna_main(int argc, char** argv)
2023-03-23 23:52:26 +00:00
{
StringView pathname;
2023-03-23 23:52:26 +00:00
os::ArgumentParser parser;
parser.add_positional_argument(pathname, "path"_sv, true);
parser.parse(argc, argv);
2023-03-23 23:52:26 +00:00
2023-04-13 15:04:59 +00:00
auto file = TRY(os::File::open_or_create(pathname, os::File::WriteOnly));
2023-03-23 23:52:26 +00:00
char buffer[4096];
while (1)
{
char* rc = fgets(buffer, sizeof(buffer), stdin);
if (rc == 0) break;
2023-04-13 15:04:59 +00:00
TRY(file->write(StringView { buffer }));
2023-03-23 23:52:26 +00:00
}
return 0;
}