Message ID | 20210715211459.19373-15-laurent.pinchart@ideasonboard.com |
---|---|
State | Accepted |
Headers | show |
Series |
|
Related | show |
Hi Laurent, On Fri, Jul 16, 2021 at 12:14:40AM +0300, Laurent Pinchart wrote: > The options parser currently ignores non-option arguments silently, > which is confusing. It's a common error to run 'cam -c1 -C 10' and > expect only 10 frames to be captured. As the -C option takes an optional > argument, the number 10 is interpreted as a non-option argument instead > of the argument to the -C option. I've been fooled by that a few times :) Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Thanks j > > Fail parsing with an appropriate message and print usage information > when a non-option argument is found. The parser may be extended later to > accept non-option arguments when the application has a use for them. > > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> > --- > src/cam/options.cpp | 7 +++++++ > 1 file changed, 7 insertions(+) > > diff --git a/src/cam/options.cpp b/src/cam/options.cpp > index 6e0d802cb986..33bc512e6571 100644 > --- a/src/cam/options.cpp > +++ b/src/cam/options.cpp > @@ -945,6 +945,13 @@ OptionsParser::Options OptionsParser::parse(int argc, char **argv) > } > } > > + if (optind < argc) { > + std::cerr << "Invalid non-option argument '" << argv[optind] > + << "'" << std::endl; > + usage(); > + return options; > + } > + > options.valid_ = true; > return options; > } > -- > Regards, > > Laurent Pinchart >
diff --git a/src/cam/options.cpp b/src/cam/options.cpp index 6e0d802cb986..33bc512e6571 100644 --- a/src/cam/options.cpp +++ b/src/cam/options.cpp @@ -945,6 +945,13 @@ OptionsParser::Options OptionsParser::parse(int argc, char **argv) } } + if (optind < argc) { + std::cerr << "Invalid non-option argument '" << argv[optind] + << "'" << std::endl; + usage(); + return options; + } + options.valid_ = true; return options; }
The options parser currently ignores non-option arguments silently, which is confusing. It's a common error to run 'cam -c1 -C 10' and expect only 10 frames to be captured. As the -C option takes an optional argument, the number 10 is interpreted as a non-option argument instead of the argument to the -C option. Fail parsing with an appropriate message and print usage information when a non-option argument is found. The parser may be extended later to accept non-option arguments when the application has a use for them. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> --- src/cam/options.cpp | 7 +++++++ 1 file changed, 7 insertions(+)