fix: fix clap parser resolver build issue
This commit is contained in:
@ -63,7 +63,7 @@ namespace yycc::carton::clap::parser {
|
|||||||
|
|
||||||
/// @brief Core capture function.
|
/// @brief Core capture function.
|
||||||
template<std::ranges::viewable_range V>
|
template<std::ranges::viewable_range V>
|
||||||
static TYPES::ClapResult<std::map<TYPES::Token, std::optional<std::u8string>>> capture(const APPLICATION::Application& app, V args) {
|
static TYPES::ClapResult<std::map<TYPES::Token, std::optional<std::u8string>>> capture(const APPLICATION::Application& app, V&& args) {
|
||||||
// Create context.
|
// Create context.
|
||||||
ParserContext ctx(app);
|
ParserContext ctx(app);
|
||||||
|
|
||||||
@ -172,13 +172,14 @@ namespace yycc::carton::clap::parser {
|
|||||||
#pragma region Parser Class
|
#pragma region Parser Class
|
||||||
|
|
||||||
TYPES::ClapResult<Parser> Parser::from_user(const APPLICATION::Application& app, const std::vector<std::u8string_view>& args) {
|
TYPES::ClapResult<Parser> Parser::from_user(const APPLICATION::Application& app, const std::vector<std::u8string_view>& args) {
|
||||||
auto rv = capture(app, args);
|
auto rv = capture(app, std::views::all(args));
|
||||||
if (rv.has_value()) return Parser(std::move(rv.value()));
|
if (rv.has_value()) return Parser(std::move(rv.value()));
|
||||||
else return std::unexpected(rv.error());
|
else return std::unexpected(rv.error());
|
||||||
}
|
}
|
||||||
|
|
||||||
TYPES::ClapResult<Parser> Parser::from_system(const APPLICATION::Application& app) {
|
TYPES::ClapResult<Parser> Parser::from_system(const APPLICATION::Application& app) {
|
||||||
auto rv = capture(app, ENV::get_args() | std::views::transform([](auto s) {
|
auto args = ENV::get_args();
|
||||||
|
auto rv = capture(app, args | std::views::transform([](const auto& s) {
|
||||||
return std::u8string_view(s);
|
return std::u8string_view(s);
|
||||||
}));
|
}));
|
||||||
if (rv.has_value()) return Parser(std::move(rv.value()));
|
if (rv.has_value()) return Parser(std::move(rv.value()));
|
||||||
|
|||||||
@ -53,7 +53,7 @@ namespace yycc::carton::clap::parser {
|
|||||||
if (value.has_value()) return value.value();
|
if (value.has_value()) return value.value();
|
||||||
else return std::unexpected(NS_YYCC_CLAP_TYPES::ClapError::BadCast);
|
else return std::unexpected(NS_YYCC_CLAP_TYPES::ClapError::BadCast);
|
||||||
} else {
|
} else {
|
||||||
return std::unexpected(raw_value.error())
|
return std::unexpected(raw_value.error());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -13,7 +13,7 @@ namespace yycc::carton::clap::resolver {
|
|||||||
|
|
||||||
/// @brief Core capture function
|
/// @brief Core capture function
|
||||||
template<std::ranges::viewable_range V>
|
template<std::ranges::viewable_range V>
|
||||||
static TYPES::ClapResult<std::map<TYPES::Token, std::optional<std::u8string>>> capture(const APPLICATION::Application& app, V vars) {
|
static TYPES::ClapResult<std::map<TYPES::Token, std::optional<std::u8string>>> capture(const APPLICATION::Application& app, V&& vars) {
|
||||||
std::map<TYPES::Token, std::optional<std::u8string>> values;
|
std::map<TYPES::Token, std::optional<std::u8string>> values;
|
||||||
const auto& variables = app.get_variables();
|
const auto& variables = app.get_variables();
|
||||||
|
|
||||||
@ -48,13 +48,14 @@ namespace yycc::carton::clap::resolver {
|
|||||||
|
|
||||||
TYPES::ClapResult<Resolver> Resolver::from_user(const APPLICATION::Application& app,
|
TYPES::ClapResult<Resolver> Resolver::from_user(const APPLICATION::Application& app,
|
||||||
const std::vector<std::pair<std::u8string_view, std::u8string_view>>& vars) {
|
const std::vector<std::pair<std::u8string_view, std::u8string_view>>& vars) {
|
||||||
auto rv = capture(app, vars);
|
auto rv = capture(app, std::views::all(vars));
|
||||||
if (rv.has_value()) return Resolver(std::move(rv.value()));
|
if (rv.has_value()) return Resolver(std::move(rv.value()));
|
||||||
else return std::unexpected(rv.error());
|
else return std::unexpected(rv.error());
|
||||||
}
|
}
|
||||||
|
|
||||||
TYPES::ClapResult<Resolver> Resolver::from_system(const APPLICATION::Application& app) {
|
TYPES::ClapResult<Resolver> Resolver::from_system(const APPLICATION::Application& app) {
|
||||||
auto rv = capture(app, ENV::get_vars() | std::views::transform([](auto p) {
|
auto vars = ENV::get_vars();
|
||||||
|
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);
|
return std::make_pair<std::u8string_view, std::u8string_view>(p.first, p.second);
|
||||||
}));
|
}));
|
||||||
if (rv.has_value()) return Resolver(std::move(rv.value()));
|
if (rv.has_value()) return Resolver(std::move(rv.value()));
|
||||||
|
|||||||
@ -53,7 +53,7 @@ namespace yycc::carton::clap::resolver {
|
|||||||
if (value.has_value()) return value.value();
|
if (value.has_value()) return value.value();
|
||||||
else return std::unexpected(NS_YYCC_CLAP_TYPES::ClapError::BadCast);
|
else return std::unexpected(NS_YYCC_CLAP_TYPES::ClapError::BadCast);
|
||||||
} else {
|
} else {
|
||||||
return std::unexpected(raw_value.error())
|
return std::unexpected(raw_value.error());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -230,7 +230,7 @@ namespace yycc::env {
|
|||||||
|
|
||||||
#pragma region Environment Argument
|
#pragma region Environment Argument
|
||||||
|
|
||||||
ArgResult<std::vector<std::u8string>> get_args() {
|
std::vector<std::u8string> get_args() {
|
||||||
// TODO: finish this function according to Rust implementation.
|
// TODO: finish this function according to Rust implementation.
|
||||||
// Considering whether use iterator as return value.
|
// Considering whether use iterator as return value.
|
||||||
throw std::logic_error("not implemented");
|
throw std::logic_error("not implemented");
|
||||||
|
|||||||
Reference in New Issue
Block a user