refactor: add result wrapper for env vars and args
This commit is contained in:
@@ -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);
|
||||
}));
|
||||
|
||||
@@ -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);
|
||||
}));
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user