rpi-rgb-led-matrix icon indicating copy to clipboard operation
rpi-rgb-led-matrix copied to clipboard

Command line processing - how to invoke usage

Open davepl opened this issue 1 year ago • 2 comments

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 avatar Aug 23 '24 21:08 davepl

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!

davepl avatar Aug 23 '24 21:08 davepl

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).

hzeller avatar Aug 23 '24 21:08 hzeller