2023-04-13 15:31:21 +00:00
|
|
|
#include <luna/String.h>
|
2023-03-29 16:27:02 +00:00
|
|
|
#include <os/ArgumentParser.h>
|
2023-04-12 19:46:10 +00:00
|
|
|
#include <os/File.h>
|
2023-03-29 16:27:02 +00:00
|
|
|
|
2023-04-13 15:31:21 +00:00
|
|
|
using os::File;
|
2023-03-23 23:52:26 +00:00
|
|
|
|
2023-04-13 15:04:59 +00:00
|
|
|
Result<int> luna_main(int argc, char** argv)
|
2023-03-23 23:52:26 +00:00
|
|
|
{
|
2023-03-29 16:27:02 +00:00
|
|
|
StringView pathname;
|
2023-03-23 23:52:26 +00:00
|
|
|
|
2023-04-07 08:40:46 +00:00
|
|
|
os::ArgumentParser parser;
|
2023-04-19 17:16:45 +00:00
|
|
|
parser.add_description("Edit a file using basic line-based shell editing."_sv);
|
2023-04-12 19:46:10 +00:00
|
|
|
parser.add_positional_argument(pathname, "path"_sv, true);
|
2023-03-29 16:27:02 +00:00
|
|
|
parser.parse(argc, argv);
|
2023-03-23 23:52:26 +00:00
|
|
|
|
2023-04-13 15:31:21 +00:00
|
|
|
auto file = TRY(File::open_or_create(pathname, File::WriteOnly));
|
2023-03-23 23:52:26 +00:00
|
|
|
|
2023-04-13 15:31:21 +00:00
|
|
|
auto input = File::standard_input();
|
2023-03-23 23:52:26 +00:00
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
2023-04-13 15:31:21 +00:00
|
|
|
String line = TRY(input->read_line());
|
|
|
|
if (line.is_empty()) break;
|
|
|
|
TRY(file->write(line.view()));
|
2023-03-23 23:52:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|