Skip to content
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

Command line processing - how to invoke usage #1701

Open
davepl opened this issue Aug 23, 2024 · 2 comments
Open

Command line processing - how to invoke usage #1701

davepl opened this issue Aug 23, 2024 · 2 comments

Comments

@davepl
Copy link

davepl commented Aug 23, 2024

Below is my code to process options, but my expectation was that if the. user were to provide --help or -? that it would return false and hence print usage.

Is that not the case? Or do I have a bug?

    rgb_matrix::RuntimeOptions runtime_opt;
    if (!rgb_matrix::ParseOptionsFromFlags(&argc, &argv, &matrix_options, &runtime_opt)) 
        return usage(argv[0]);
    runtime_opt.gpio_slowdown = kDefaultGPIOSlowdown;
@davepl
Copy link
Author

davepl commented Aug 23, 2024

BTW, I'm guessing it's because the options code expects everything to be preceded by --led, so --led-help works, but seems like a bug to me!

@hzeller
Copy link
Owner

hzeller commented Aug 23, 2024

the rgb-matrix-flag parsing is done to least interfere with whatever the user needs in addition and processes with getopt(), this is why all flags have the --led-* prefix. The matrix does not go ahead and by itself print their usage of flags, as it is typically used inside another program that has their own flag processing and usage() print.
But the library provides a way to print its options that you can call inside your usage():

rgb_matrix::PrintMatrixFlags(stderr);

There are a couple of examples how flags are handled in the utils/ directory that might be helpful.

(BTW in your example I see that you first call the flags then set the runtime_opt.gpio_slowdown. Typically one would do that the other way around as you'd set some useful defaults, but then allow the user to override them on the command line. Depends of course; sometimes one wants not to have a particular value messed up).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants