[libcamera-devel] cam: options: Restore std::cerr adjustement field
diff mbox series

Message ID 20210723042353.6616-1-laurent.pinchart@ideasonboard.com
State Accepted
Headers show
Series
  • [libcamera-devel] cam: options: Restore std::cerr adjustement field
Related show

Commit Message

Laurent Pinchart July 23, 2021, 4:23 a.m. UTC
The std::cerr adjustment is set to std::left to print the usage text.
Restore it to its original value when done, to avoid affecting the
caller.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 src/cam/options.cpp | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Comments

Jacopo Mondi July 27, 2021, 9:39 a.m. UTC | #1
Hi Laurent,

On Fri, Jul 23, 2021 at 07:23:53AM +0300, Laurent Pinchart wrote:
> The std::cerr adjustment is set to std::left to print the usage text.
> Restore it to its original value when done, to avoid affecting the
> caller.

Seems sane!

Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>

Thanks
   j

>
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
>  src/cam/options.cpp | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/src/cam/options.cpp b/src/cam/options.cpp
> index 33bc512e6571..4f7e869144c8 100644
> --- a/src/cam/options.cpp
> +++ b/src/cam/options.cpp
> @@ -453,7 +453,7 @@ void KeyValueParser::usage(int indent)
>  				argument += "]";
>  		}
>
> -		std::cerr << std::setw(indent) << std::left << argument;
> +		std::cerr << std::setw(indent) << argument;
>
>  		for (const char *help = option.help, *end = help; end;) {
>  			end = strchr(help, '\n');
> @@ -994,7 +994,12 @@ void OptionsParser::usage()
>
>  	std::cerr << "Options:" << std::endl;
>
> +	std::ios_base::fmtflags f(std::cerr.flags());
> +	std::cerr << std::left;
> +
>  	usageOptions(options_, indent);
> +
> +	std::cerr.flags(f);
>  }
>
>  void OptionsParser::usageOptions(const std::list<Option> &options,
> @@ -1031,7 +1036,7 @@ void OptionsParser::usageOptions(const std::list<Option> &options,
>  		if (option.isArray)
>  			argument += " ...";
>
> -		std::cerr << std::setw(indent) << std::left << argument;
> +		std::cerr << std::setw(indent) << argument;
>
>  		for (const char *help = option.help, *end = help; end; ) {
>  			end = strchr(help, '\n');
> --
> Regards,
>
> Laurent Pinchart
>
Kieran Bingham July 27, 2021, 10:24 a.m. UTC | #2
in $SUBJECT s/adjustement/adjustment/

On 23/07/2021 05:23, Laurent Pinchart wrote:
> The std::cerr adjustment is set to std::left to print the usage text.
> Restore it to its original value when done, to avoid affecting the
> caller.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

LGTM...

Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

> ---
>  src/cam/options.cpp | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/src/cam/options.cpp b/src/cam/options.cpp
> index 33bc512e6571..4f7e869144c8 100644
> --- a/src/cam/options.cpp
> +++ b/src/cam/options.cpp
> @@ -453,7 +453,7 @@ void KeyValueParser::usage(int indent)
>  				argument += "]";
>  		}
>  
> -		std::cerr << std::setw(indent) << std::left << argument;
> +		std::cerr << std::setw(indent) << argument;
>  
>  		for (const char *help = option.help, *end = help; end;) {
>  			end = strchr(help, '\n');
> @@ -994,7 +994,12 @@ void OptionsParser::usage()
>  
>  	std::cerr << "Options:" << std::endl;
>  
> +	std::ios_base::fmtflags f(std::cerr.flags());
> +	std::cerr << std::left;
> +
>  	usageOptions(options_, indent);
> +
> +	std::cerr.flags(f);
>  }
>  
>  void OptionsParser::usageOptions(const std::list<Option> &options,
> @@ -1031,7 +1036,7 @@ void OptionsParser::usageOptions(const std::list<Option> &options,
>  		if (option.isArray)
>  			argument += " ...";
>  
> -		std::cerr << std::setw(indent) << std::left << argument;
> +		std::cerr << std::setw(indent) << argument;
>  
>  		for (const char *help = option.help, *end = help; end; ) {
>  			end = strchr(help, '\n');
>

Patch
diff mbox series

diff --git a/src/cam/options.cpp b/src/cam/options.cpp
index 33bc512e6571..4f7e869144c8 100644
--- a/src/cam/options.cpp
+++ b/src/cam/options.cpp
@@ -453,7 +453,7 @@  void KeyValueParser::usage(int indent)
 				argument += "]";
 		}
 
-		std::cerr << std::setw(indent) << std::left << argument;
+		std::cerr << std::setw(indent) << argument;
 
 		for (const char *help = option.help, *end = help; end;) {
 			end = strchr(help, '\n');
@@ -994,7 +994,12 @@  void OptionsParser::usage()
 
 	std::cerr << "Options:" << std::endl;
 
+	std::ios_base::fmtflags f(std::cerr.flags());
+	std::cerr << std::left;
+
 	usageOptions(options_, indent);
+
+	std::cerr.flags(f);
 }
 
 void OptionsParser::usageOptions(const std::list<Option> &options,
@@ -1031,7 +1036,7 @@  void OptionsParser::usageOptions(const std::list<Option> &options,
 		if (option.isArray)
 			argument += " ...";
 
-		std::cerr << std::setw(indent) << std::left << argument;
+		std::cerr << std::setw(indent) << argument;
 
 		for (const char *help = option.help, *end = help; end; ) {
 			end = strchr(help, '\n');