From aedf16d3f912e0669759b9505e2834cd749d0f55 Mon Sep 17 00:00:00 2001 From: Ken Matsui <26405363+ken-matsui@users.noreply.github.com> Date: Wed, 20 Dec 2023 14:42:13 -0800 Subject: [PATCH] new handling --- src/Cmd/New.cc | 7 ++++++- srcOld/Util/File.hpp | 27 --------------------------- 2 files changed, 6 insertions(+), 28 deletions(-) delete mode 100644 srcOld/Util/File.hpp diff --git a/src/Cmd/New.cc b/src/Cmd/New.cc index a10e1785b..c03568f98 100644 --- a/src/Cmd/New.cc +++ b/src/Cmd/New.cc @@ -5,6 +5,7 @@ #include #include +#include static inline constexpr StringRef mainCc = "#include \n\n" @@ -41,6 +42,10 @@ static void writeToFile(std::ofstream& ofs, const Path& fpath, StringRef text) { ofs << text; } ofs.close(); + + if (!ofs) { + throw std::runtime_error("writing `" + fpath.string() + "` failed"); + } ofs.clear(); } @@ -70,7 +75,7 @@ static void createTemplateFiles(const bool isBin, const Path& projectName) { } } -bool verifyPackageName(StringRef name) { +bool verifyPackageName(StringRef name) noexcept { // Empty if (name.empty()) { Logger::error("missing package name"); diff --git a/srcOld/Util/File.hpp b/srcOld/Util/File.hpp deleted file mode 100644 index 8d0d73379..000000000 --- a/srcOld/Util/File.hpp +++ /dev/null @@ -1,27 +0,0 @@ -module; - -// std -#include - -export module poac.util.file; - -import poac.util.result; -import poac.util.rustify; - -namespace poac::util::file { - -using WriteFileFailed = Error<"writing `{}` failed", String>; - -export auto write_file(const Path& p, StringRef content) -> Result { - std::ofstream ofs(p); - ofs << content; - ofs.close(); - - if (!ofs) { - return Err(p.string()); - } - - return Ok(); -} - -} // namespace poac::util::file