[libcamera-devel,3/4] cam: fix printing of camera name

Message ID 20190220143736.529-4-niklas.soderlund@ragnatech.se
State Superseded
Headers show
Series
  • cam: improve error paths
Related show

Commit Message

Niklas Söderlund Feb. 20, 2019, 2:37 p.m. UTC
Since commit c8c546fe99a343c1 ("cam: options: Add option type handling
to options parser") introduced type handling for options the context the
option is read became important. When reading the camera option for
printing there is no explicit context to print it as a string and
instead the int context was chosen resulting in:

    $ cam --camera foo
    Camera 0 not found

While the expected output is:

    $ cam --camera foo
    Camera foo not found

Fix this by providing the correct context for the camera option when
printing it.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
---
 src/cam/main.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Laurent Pinchart Feb. 22, 2019, 12:33 a.m. UTC | #1
Hi Niklas,

Thank you for the patch.

On Wed, Feb 20, 2019 at 03:37:35PM +0100, Niklas Söderlund wrote:
> Since commit c8c546fe99a343c1 ("cam: options: Add option type handling
> to options parser") introduced type handling for options the context the
> option is read became important. When reading the camera option for
> printing there is no explicit context to print it as a string and
> instead the int context was chosen resulting in:
> 
>     $ cam --camera foo
>     Camera 0 not found
> 
> While the expected output is:
> 
>     $ cam --camera foo
>     Camera foo not found
> 
> Fix this by providing the correct context for the camera option when
> printing it.
> 
> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>

With a Fixes: lines,

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  src/cam/main.cpp | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/src/cam/main.cpp b/src/cam/main.cpp
> index 30267970a2c8485f..522d2f0d3373dc25 100644
> --- a/src/cam/main.cpp
> +++ b/src/cam/main.cpp
> @@ -233,7 +233,8 @@ int main(int argc, char **argv)
>  	if (options.isSet(OptCamera)) {
>  		camera = cm->get(options[OptCamera]);
>  		if (!camera) {
> -			std::cout << "Camera " << options[OptCamera]
> +			std::cout << "Camera "
> +				  << std::string(options[OptCamera])
>  				  << " not found" << std::endl;
>  			goto out;
>  		}

Patch

diff --git a/src/cam/main.cpp b/src/cam/main.cpp
index 30267970a2c8485f..522d2f0d3373dc25 100644
--- a/src/cam/main.cpp
+++ b/src/cam/main.cpp
@@ -233,7 +233,8 @@  int main(int argc, char **argv)
 	if (options.isSet(OptCamera)) {
 		camera = cm->get(options[OptCamera]);
 		if (!camera) {
-			std::cout << "Camera " << options[OptCamera]
+			std::cout << "Camera "
+				  << std::string(options[OptCamera])
 				  << " not found" << std::endl;
 			goto out;
 		}