-
Notifications
You must be signed in to change notification settings - Fork 590
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
Allow "G", "M" and 'k' when parsing arguments #397
Comments
I think this should be up to the application to deal with. Although you can implement this yourself using a custom type. You can overload |
That would be nice to have out of the box. Both SI powers of 10 and computer powers of 2. |
I also think it would be better if the feature could be used out of the box. When using such units, the program ultimately still hopes to parse it into numbers, rather than custom types. But I don't think this should be the default behavior. Perhaps interfaces could be added to options.add_options()
("s,si_size", "A size with SI prefix", cxxopts::value<size_t>()->default_value("1k")->enable_si_prefix(), "SIZE")
("b,binary_size", "A size with binary prefix", cxxopts::value<size_t>()->default_value("1K")->enable_binary_prefix())
; But unit parsing is undoubtedly a dirty work, introducing many difficult-to-handle issues (such as case sensitivity, floating point number parsing, etc.), it is hard to implement error-free in a lightweight command line parsing. Perhaps, introducing limited basic support under clear definitions might be a good idea. Maybe I will attempt to implement it in my spare time, but for now, I still prefer to enter numbers directly or use calculations in the shell (for example, |
Is there an example of such an overload somewhere? I had to resort to doing the overloading before including #include <iostream>
#include <cxxopts.hpp> // this fails
template <typename T>
class foo {};
namespace cxxopts::values {
template <typename T>
void parse_value (const std::string& text, foo<T>& value) {}
}
// #include <cxxopts.hpp> // this works
int main (int argc, char** argv) {
auto my_foo = foo <size_t> ();
cxxopts::Options opts (argv[0], "bar");
opts.add_options () ("baz", "doc", cxxopts::value (my_foo));
auto options = opts.parse (argc, argv);
} |
I think that's I had intended, but I didn't realise that it wouldn't find the overload if it was included after. I'll see if I can come up with a way to make that work. |
openFPGALoader uses cxxopts for argument parsing. To dump the content from some flash chip, a size argument must be given. At resent I must use "--file-size 1000000" to read 1MByte, What would it take to understand "--file-size 1M"? At the moment leaving "M" and "Mi" asinde ;-)
The text was updated successfully, but these errors were encountered: