规范命名

This commit is contained in:
陈浩南 2024-06-10 19:31:59 +08:00
parent 2b88a1e32c
commit 076a267ba4
5 changed files with 18 additions and 18 deletions

View File

@ -74,9 +74,9 @@ namespace biu
{
template <bool DirectStdout, bool DirectStderr> struct ExecResult
{
int exit_code;
std::conditional_t<DirectStdout, Empty, std::string> std_out;
std::conditional_t<DirectStderr, Empty, std::string> std_err;
int ExitCode;
std::conditional_t<DirectStdout, Empty, std::string> Stdout;
std::conditional_t<DirectStderr, Empty, std::string> Stderr;
operator bool() const;
};
struct ExecInput { bool DirectStdin = false, DirectStdout = false, DirectStderr = false, SearchPath = false; };

View File

@ -20,7 +20,7 @@ namespace biu
template <bool DirectStdout, bool DirectStderr>
detail_::ExecResult<DirectStdout, DirectStderr>::operator bool() const
{ return exit_code == 0; }
{ return ExitCode == 0; }
# define BIU_EXECRESULT_PRED(r, state) BOOST_PP_NOT_EQUAL(state, 4)
# define BIU_EXECRESULT_OP(r, state) BOOST_PP_INC(state)
# define BIU_EXECRESULT_MACRO(r, state) \
@ -60,13 +60,13 @@ namespace biu
process->wait();
return
{
.exit_code = process->exit_code(),
.std_out = [&]
.ExitCode = process->exit_code(),
.Stdout = [&]
{
if constexpr (Input.DirectStdout) return Empty{};
else return std::string{std::istreambuf_iterator<char>{stdout_stream.rdbuf()}, {}};
}(),
.std_err = [&]
.Stderr = [&]
{
if constexpr (Input.DirectStderr) return Empty{};
else return std::string{std::istreambuf_iterator<char>{stderr_stream.rdbuf()}, {}};

View File

@ -71,8 +71,8 @@ namespace hpcstat::disk
else
{
std::smatch match;
if (!std::regex_search(result.std_out, match, std::regex(R"((\d+))")))
{ std::cerr << fmt::format("failed to parse {}\n", result.std_out); return std::nullopt; }
if (!std::regex_search(result.Stdout, match, std::regex(R"((\d+))")))
{ std::cerr << fmt::format("failed to parse {}\n", result.Stdout); return std::nullopt; }
return std::stod(match[1]) / 1024 / 1024 / 1024;
}
};
@ -98,8 +98,8 @@ namespace hpcstat::disk
{
std::smatch match;
// search string like 2024-06-08 13:45:19
if (!std::regex_search(result.std_out, match, std::regex(R"((\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}))")))
{ std::cerr << fmt::format("failed to parse {}\n", result.std_out); return {}; }
if (!std::regex_search(result.Stdout, match, std::regex(R"((\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}))")))
{ std::cerr << fmt::format("failed to parse {}\n", result.Stdout); return {}; }
return match[1];
}
};

View File

@ -33,11 +33,11 @@ namespace hpcstat::lfs
// Job <462270> is submitted to queue <normal_1day>.
std::regex re(R"r(Job <(\d+)> is submitted to queue <(\w+)>.)r");
std::smatch match;
if (std::regex_search(result.std_out, match, re))
if (std::regex_search(result.Stdout, match, re))
return std::make_pair(std::stoi(match[1]), match[2]);
else
{
std::cerr << fmt::format("Failed to parse job id from output: {}\n", result.std_out);
std::cerr << fmt::format("Failed to parse job id from output: {}\n", result.Stdout);
return std::nullopt;
}
}
@ -59,7 +59,7 @@ namespace hpcstat::lfs
else
{
nlohmann::json j;
try { j = nlohmann::json::parse(result.std_out); }
try { j = nlohmann::json::parse(result.Stdout); }
catch (nlohmann::json::parse_error& e)
{
std::cerr << fmt::format("Failed to parse bjobs output: {}\n", e.what());
@ -93,6 +93,6 @@ namespace hpcstat::lfs
!result
)
return std::nullopt;
else return result.std_out;
else return result.Stdout;
}
}

View File

@ -23,12 +23,12 @@ namespace hpcstat::ssh
for
(
auto i = std::sregex_iterator
(output.std_out.begin(), output.std_out.end(), pattern);
(output.Stdout.begin(), output.Stdout.end(), pattern);
i != std::sregex_iterator();
++i
)
if (Keys.contains(i->str(1))) return i->str(1);
std::cerr << fmt::format("No valid fingerprint found in:\n{}\n", output.std_out);
std::cerr << fmt::format("No valid fingerprint found in:\n{}\n", output.Stdout);
return std::nullopt;
}
}
@ -53,7 +53,7 @@ namespace hpcstat::ssh
!output
)
{ std::cerr << fmt::format("Failed to sign message: {}\n", message); return std::nullopt; }
else return output.std_out;
else return output.Stdout;
}
bool verify(std::string message, std::string signature, std::string fingerprint)
{