1
0

refactor: add result wrapper for env vars and args

This commit is contained in:
2025-12-12 13:45:13 +08:00
parent 8cd125a4b9
commit 19086f44e2
5 changed files with 40 additions and 30 deletions

View File

@@ -177,7 +177,10 @@ namespace yycc::carton::clap::parser {
}
TYPES::ClapResult<Parser> Parser::from_system(const APPLICATION::Application& app) {
auto args = ENV::get_args();
auto rv_args = ENV::get_args();
if (!rv_args.has_value()) return std::unexpected(TYPES::ClapError::Others);
auto args = std::move(rv_args.value());
auto rv = capture(app, args | std::views::transform([](const auto& s) {
return std::u8string_view(s);
}));

View File

@@ -54,7 +54,10 @@ namespace yycc::carton::clap::resolver {
}
TYPES::ClapResult<Resolver> Resolver::from_system(const APPLICATION::Application& app) {
auto vars = ENV::get_vars();
auto rv_vars = ENV::get_vars();
if (!rv_vars.has_value()) return std::unexpected(TYPES::ClapError::Others);
auto vars = std::move(rv_vars.value());
auto rv = capture(app, vars | std::views::transform([](const auto& p) {
return std::make_pair<std::u8string_view, std::u8string_view>(p.first, p.second);
}));

View File

@@ -11,7 +11,8 @@ namespace yycc::carton::clap::types {
UnexpectedValue, ///< When parsing commandline argument, reach associated value unexpected.
LostValue, ///< When parsing commandline argument, fail to find associated value.
NotCaptured, ///< When fetching option or variable, given option or variable is not captured.
BadCast ///< When fetching option or variable, the content of given option or variable can not be cast into expected type.
BadCast, ///< When fetching option or variable, the content of given option or variable can not be cast into expected type.
Others, ///< Any other errors.
};
/// @brief The result type used in this module.