-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ambiguous help, short name duplicates #16
Comments
I've been wondering for awhile how to solve this - being able to provide short names, help descriptions etc. Using it as part of the |
I like this idea. Custom help strings can be added to individual arguments this way too. |
I would like to +1 this idea. Any idea if it will get implemented? |
You should check out my fork of I added the capability of adding metadata to any struct member being visited. This can technically allow things such as : struct my_type {
int a = 666;
float b = 42.0f;
std::string c;
};
struct arg_opt {
std::optional<std::string> help;
int priority = 0;
};
struct arg_special {
bool is_valid = false;
};
VISITABLE_STRUCT_METADATA(my_type,
METADATA(a, arg_opt { .help = "help message for A", .priority = 1 }),
METADATA(b, arg_opt { .help = "help message for B", .priority = 2 }),
METADATA(c, arg_special { .is_valid = true }));
struct debug_printer {
template <typename T>
void operator()(const char* name, const T& value, const arg_opt& ao) {
std::cerr << name << ": " << value << " [ desc=" << ao.help.value_or("<none>")
<< ", priority=" << ao.priority << "]" << std::endl;
}
template <typename T, typename M>
void operator()(const char* name, const T& value, const M& /*metadata*/) {
std::cerr << name << ": " << value << std::endl;
}
};
void debug_print(const my_type & my_struct) {
visit_struct::for_each(my_struct, debug_printer{});
} Now, in theory, this can open the door to custom help messages, argument groups, custom short names, etc. And there could be many other improvements as well. Only major difference is that I really wanted to use designated initializers, and that's only available for C++20 and above. |
I seems that first character of long-name is used in a short-name.
In case:
Help prints:
There are
-b
twice. Ii can be confusing, specially with many another options between duplicates.BTW, it's possible (or is planned) to set flag name (short name)?
Maybe something like
The text was updated successfully, but these errors were encountered: