util: Add ArgsManager::GetPathArg() function

Co-authored-by: Ryan Ofsky <ryan@ofsky.org>
This commit is contained in:
Hennadii Stepanov
2022-02-04 17:57:51 +02:00
parent 5e8e0b3d7f
commit 540ca5111f
3 changed files with 109 additions and 0 deletions

View File

@@ -399,6 +399,13 @@ std::optional<unsigned int> ArgsManager::GetArgFlags(const std::string& name) co
return std::nullopt;
}
fs::path ArgsManager::GetPathArg(std::string pathlike_arg) const
{
auto result = fs::PathFromString(GetArg(pathlike_arg, "")).lexically_normal();
// Remove trailing slash, if present.
return result.has_filename() ? result : result.parent_path();
}
const fs::path& ArgsManager::GetBlocksDirPath() const
{
LOCK(cs_args);