Skip to content

Commit

Permalink
main.cc: simplify (#1119)
Browse files Browse the repository at this point in the history
  • Loading branch information
ken-matsui authored Jan 23, 2025
1 parent 6d100b0 commit 4974f68
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
14 changes: 9 additions & 5 deletions src/Cabin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "Algos.hpp"
#include "Cli.hpp"
#include "Cmd.hpp"
#include "Logger.hpp"
#include "Rustify/Result.hpp"
#include "TermColor.hpp"

Expand All @@ -12,6 +13,7 @@
#include <span>
#include <string>
#include <string_view>
#include <utility>
#include <vector>

namespace cabin {
Expand Down Expand Up @@ -120,11 +122,13 @@ colorizeAnyhowError(std::string s) {
return s;
}

Result<void, std::string>
cliMain(const std::span<char* const> args) noexcept {
return parseArgs(args).map_err([](const auto& e) {
return colorizeAnyhowError(e->what());
});
Result<void, void>
cliMain(int argc, char* argv[]) noexcept { // NOLINT(*-avoid-c-arrays)
// Drop the first argument (program name)
const std::span<char* const> args(argv + 1, argv + argc);
return parseArgs(args)
.map_err([](const auto& e) { return colorizeAnyhowError(e->what()); })
.map_err([](std::string e) { logger::error("{}", std::move(e)); });
}

} // namespace cabin
6 changes: 2 additions & 4 deletions src/Cabin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

#include "Rustify/Result.hpp"

#include <span>
#include <string>

namespace cabin {

Result<void, std::string> cliMain(std::span<char* const> args) noexcept;
// NOLINTNEXTLINE(*-avoid-c-arrays)
Result<void, void> cliMain(int argc, char* argv[]) noexcept;

} // namespace cabin
7 changes: 1 addition & 6 deletions src/main.cc
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
#include "Cabin.hpp"
#include "Logger.hpp"

#include <span>

int
main(int argc, char* argv[]) {
return cabin::cliMain(std::span<char* const>(argv + 1, argv + argc))
.map_err([](const auto& e) { cabin::logger::error("{}", e); })
.is_err();
return cabin::cliMain(argc, argv).is_err();
}

0 comments on commit 4974f68

Please sign in to comment.