[libcamera-devel] [PATCH] cam: options: optional arguments needs to be specified as --foo=bar

Laurent Pinchart laurent.pinchart at ideasonboard.com
Fri Jan 25 12:01:34 CET 2019


Hi Niklas,

On Fri, Jan 25, 2019 at 12:23:11AM +0100, Niklas Söderlund wrote:
> It's not state in the documentation but optional arguments needs to be
> specified using as '--foo=bar' instead of '--foo bar', otherwise the
> value is not propagated to optarg during argument parsing. Update the
> usage printing helper to reflect this requirement.
> 
> Signed-off-by: Niklas Söderlund <niklas.soderlund at ragnatech.se>
> ---
>  src/cam/options.cpp | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/src/cam/options.cpp b/src/cam/options.cpp
> index 82acff9bbeea476d..73d81d0bc0ec6d38 100644
> --- a/src/cam/options.cpp
> +++ b/src/cam/options.cpp
> @@ -143,7 +143,8 @@ void OptionsParser::usage()
>  		};
>  
>  		if (option.argument != ArgumentNone) {
> -			argument += std::string(" ");
> +			argument += option.argument == ArgumentOptional ?
> +				"=" : " ";
>  			if (option.argument == ArgumentOptional)
>  				argument += "[";
>  			argument += option.argumentName;

This will output

	-f, --foo value

for mandatory arguments, and

	-f, --foo=[value]

for optional arguments. If we want to print the =, shouldn't it be
--foo[=value] ? And how should we handle the case where no long option
is available, with this patch -f=[value] would be printed, which isn't
correct I think.

-- 
Regards,

Laurent Pinchart


More information about the libcamera-devel mailing list