Skip to content

Commit

Permalink
🧹 move generic arch-chroot into gucc
Browse files Browse the repository at this point in the history
  • Loading branch information
vnepogodin committed Jun 26, 2024
1 parent 0dec883 commit 0623232
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
1 change: 1 addition & 0 deletions gucc/include/gucc/io_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace gucc::utils {
auto safe_getenv(const char* env_name) noexcept -> std::string_view;
void exec(const std::vector<std::string>& vec) noexcept;
auto exec(std::string_view command, bool interactive = false) noexcept -> std::string;
void arch_chroot(std::string_view command, std::string_view mountpoint, bool interactive = false) noexcept;

} // namespace gucc::utils

Expand Down
12 changes: 12 additions & 0 deletions gucc/src/io_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <algorithm> // for transform
#include <fstream> // for ofstream

#include <fmt/compile.h>
#include <fmt/ranges.h>
#include <spdlog/spdlog.h>

Expand Down Expand Up @@ -88,4 +89,15 @@ auto exec(std::string_view command, bool interactive) noexcept -> std::string {
return result;
}

void arch_chroot(std::string_view command, std::string_view mountpoint, bool interactive) noexcept {

Check failure on line 92 in gucc/src/io_utils.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

/gucc/src/io_utils.cpp:92:18 [bugprone-easily-swappable-parameters

2 adjacent parameters of 'arch_chroot' of similar type ('std::string_view') are easily swapped by mistake
// TODO(vnepogodin): refactor to move output into variable and print into log
const auto& cmd_formatted = fmt::format(FMT_COMPILE("arch-chroot {} {} 2>>/tmp/cachyos-install.log 2>&1"), mountpoint, command);

#ifdef NDEVENV
gucc::utils::exec(cmd_formatted, interactive);
#else
spdlog::info("Running with arch-chroot(interactive='{}'): '{}'", interactive, cmd_formatted);
#endif
}

} // namespace gucc::utils
20 changes: 8 additions & 12 deletions src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,21 +125,17 @@ void arch_chroot(const std::string_view& command, bool follow) noexcept {
auto& config_data = config_instance->data();

const auto& mountpoint = std::get<std::string>(config_data["MOUNTPOINT"]);
const auto& cmd_formatted = fmt::format(FMT_COMPILE("arch-chroot {} {} 2>>/tmp/cachyos-install.log 2>&1"), mountpoint, command);
const auto& headless_mode = std::get<std::int32_t>(config_data["HEADLESS_MODE"]);

const bool follow_headless = follow && headless_mode;

Check failure on line 130 in src/utils.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

/src/utils.cpp:130:44 [readability-implicit-bool-conversion

implicit conversion 'int' -> bool
if (!follow || follow_headless) {
gucc::utils::arch_chroot(command, mountpoint, follow_headless);
}
#ifdef NDEVENV
if (follow) {
const auto& headless_mode = std::get<std::int32_t>(config_data["HEADLESS_MODE"]);
if (headless_mode) {
gucc::utils::exec(cmd_formatted, true);
} else {
tui::detail::follow_process_log_widget({"/bin/sh", "-c", cmd_formatted});
}
return;
else {
const auto& cmd_formatted = fmt::format(FMT_COMPILE("arch-chroot {} {} 2>>/tmp/cachyos-install.log 2>&1"), mountpoint, command);
tui::detail::follow_process_log_widget({"/bin/sh", "-c", cmd_formatted});
}
gucc::utils::exec(cmd_formatted);
#else
spdlog::info("Running with arch-chroot(follow='{}'): '{}'", follow, cmd_formatted);
#endif
}

Expand Down

0 comments on commit 0623232

Please sign in to comment.