30 lines
702 B
C++
30 lines
702 B
C++
#include <luna/String.h>
|
|
#include <os/ArgumentParser.h>
|
|
#include <os/File.h>
|
|
|
|
using os::File;
|
|
|
|
Result<int> luna_main(int argc, char** argv)
|
|
{
|
|
StringView pathname;
|
|
|
|
os::ArgumentParser parser;
|
|
parser.add_description("Edit a file using basic line-based shell editing."_sv);
|
|
parser.add_system_program_info("edit"_sv);
|
|
parser.add_positional_argument(pathname, "path"_sv, true);
|
|
parser.parse(argc, argv);
|
|
|
|
auto file = TRY(File::open_or_create(pathname, File::WriteOnly));
|
|
|
|
auto input = File::standard_input();
|
|
|
|
while (1)
|
|
{
|
|
String line = TRY(input->read_line());
|
|
if (line.is_empty()) break;
|
|
TRY(file->write(line.view()));
|
|
}
|
|
|
|
return 0;
|
|
}
|