more work on argparse
parent
7dc19efbaa
commit
96e5343d02
|
@ -1,6 +1,6 @@
|
||||||
cmake_minimum_required(VERSION 3.20)
|
cmake_minimum_required(VERSION 3.20)
|
||||||
include(cmake/color.cmake)
|
include(cmake/color.cmake)
|
||||||
set(BLT_VERSION 4.0.12)
|
set(BLT_VERSION 4.0.13)
|
||||||
|
|
||||||
set(BLT_TARGET BLT)
|
set(BLT_TARGET BLT)
|
||||||
|
|
||||||
|
|
|
@ -375,11 +375,27 @@ namespace blt::argparse
|
||||||
storage.m_data.insert({dest, detail::arg_string_converter_t<T>::convert(value)});
|
storage.m_data.insert({dest, detail::arg_string_converter_t<T>::convert(value)});
|
||||||
};
|
};
|
||||||
m_dest_vec_func = [](const std::string_view dest, argument_storage_t& storage, const std::vector<std::string_view>& values)
|
m_dest_vec_func = [](const std::string_view dest, argument_storage_t& storage, const std::vector<std::string_view>& values)
|
||||||
|
{
|
||||||
|
if (storage.m_data.contains(dest))
|
||||||
|
{
|
||||||
|
auto& data = storage.m_data[dest];
|
||||||
|
if (!std::holds_alternative<std::vector<T>>(data))
|
||||||
|
{
|
||||||
|
std::cerr << "Invalid type conversion. Trying to add type " << blt::type_string<T>() <<
|
||||||
|
" but this does not match existing type index '" << data.index() << "'!" << std::endl;
|
||||||
|
std::exit(1);
|
||||||
|
}
|
||||||
|
std::vector<T>& converted_values = std::get<std::vector<T>>(data);
|
||||||
|
for (const auto& value : values)
|
||||||
|
converted_values.push_back(detail::arg_string_converter_t<T>::convert(value));
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
std::vector<T> converted_values;
|
std::vector<T> converted_values;
|
||||||
for (const auto& value : values)
|
for (const auto& value : values)
|
||||||
converted_values.push_back(detail::arg_string_converter_t<T>::convert(value));
|
converted_values.push_back(detail::arg_string_converter_t<T>::convert(value));
|
||||||
storage.m_data.insert({dest, converted_values});
|
storage.m_data.insert({dest, converted_values});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -313,6 +313,7 @@ namespace blt::argparse
|
||||||
}
|
}
|
||||||
if (argc == 0)
|
if (argc == 0)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (argc == 1)
|
else if (argc == 1)
|
||||||
{
|
{
|
||||||
|
@ -323,14 +324,12 @@ namespace blt::argparse
|
||||||
break;
|
break;
|
||||||
case action_t::APPEND:
|
case action_t::APPEND:
|
||||||
case action_t::EXTEND:
|
case action_t::EXTEND:
|
||||||
{
|
flag->m_dest_vec_func(dest, parsed_args, args);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
case action_t::APPEND_CONST:
|
case action_t::APPEND_CONST:
|
||||||
if (flag->m_const_value)
|
if (flag->m_const_value)
|
||||||
{
|
{
|
||||||
std::cerr << "Append const chosen as an action but const value not provided for flag '" << arg << '\'' <<
|
std::cerr << "Append const chosen as an action but const value not provided for argument '" << arg << '\'' <<
|
||||||
std::endl;
|
std::endl;
|
||||||
std::exit(1);
|
std::exit(1);
|
||||||
}
|
}
|
||||||
|
@ -340,7 +339,7 @@ namespace blt::argparse
|
||||||
auto visitor = detail::arg_meta_type_helper_t::make_visitor(
|
auto visitor = detail::arg_meta_type_helper_t::make_visitor(
|
||||||
[arg](auto& primitive)
|
[arg](auto& primitive)
|
||||||
{
|
{
|
||||||
std::cerr << "Invalid type - '" << arg << "' expected list type, found '"
|
std::cerr << "Invalid type for argument '" << arg << "' expected list type, found '"
|
||||||
<< blt::type_string<decltype(primitive)>() << "' with value " << primitive << std::endl;
|
<< blt::type_string<decltype(primitive)>() << "' with value " << primitive << std::endl;
|
||||||
std::exit(1);
|
std::exit(1);
|
||||||
},
|
},
|
||||||
|
@ -349,7 +348,7 @@ namespace blt::argparse
|
||||||
using type = typename meta::remove_cvref_t<decltype(vec)>::value_type;
|
using type = typename meta::remove_cvref_t<decltype(vec)>::value_type;
|
||||||
if (!std::holds_alternative<type>(*flag->m_const_value))
|
if (!std::holds_alternative<type>(*flag->m_const_value))
|
||||||
{
|
{
|
||||||
std::cerr << "Constant value for flag '" << arg <<
|
std::cerr << "Constant value for argument '" << arg <<
|
||||||
"' type doesn't match values already present! Expected to be of type '" <<
|
"' type doesn't match values already present! Expected to be of type '" <<
|
||||||
blt::type_string<type>() << "'!" << std::endl;
|
blt::type_string<type>() << "'!" << std::endl;
|
||||||
std::exit(1);
|
std::exit(1);
|
||||||
|
@ -397,7 +396,8 @@ namespace blt::argparse
|
||||||
if constexpr (std::is_convertible_v<decltype(args.size()), type>)
|
if constexpr (std::is_convertible_v<decltype(args.size()), type>)
|
||||||
{
|
{
|
||||||
return primitive + static_cast<type>(args.size());
|
return primitive + static_cast<type>(args.size());
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
std::cerr << "Error: count called but stored type is " << blt::type_string<type>() << std::endl;
|
std::cerr << "Error: count called but stored type is " << blt::type_string<type>() << std::endl;
|
||||||
std::exit(1);
|
std::exit(1);
|
||||||
|
@ -405,7 +405,8 @@ namespace blt::argparse
|
||||||
},
|
},
|
||||||
[](auto&) -> detail::arg_data_t
|
[](auto&) -> detail::arg_data_t
|
||||||
{
|
{
|
||||||
std::cerr << "List present on count. This condition doesn't make any sense! (How did we get here, please report this!)";
|
std::cerr <<
|
||||||
|
"List present on count. This condition doesn't make any sense! (How did we get here, please report this!)";
|
||||||
std::exit(1);
|
std::exit(1);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue