[libcamera-devel] cam: options: Indent multi-line help message correctly

Message ID 20190126151659.7438-1-laurent.pinchart@ideasonboard.com
State Accepted
Commit aae0b7ffb1123103f162bdf566e2d4bce5cbf774
Headers show
Series
  • [libcamera-devel] cam: options: Indent multi-line help message correctly
Related show

Commit Message

Laurent Pinchart Jan. 26, 2019, 3:16 p.m. UTC
Split multi-line help messages and indent all lines the same way.

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

Comments

Niklas Söderlund Jan. 27, 2019, 12:26 a.m. UTC | #1
Hi Laurent,

Neat idea!

On 2019-01-26 17:16:59 +0200, Laurent Pinchart wrote:
> Split multi-line help messages and indent all lines the same way.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>

> ---
>  src/cam/options.cpp | 12 +++++++++++-
>  1 file changed, 11 insertions(+), 1 deletion(-)
> 
> diff --git a/src/cam/options.cpp b/src/cam/options.cpp
> index 55c42540f924..83601270207b 100644
> --- a/src/cam/options.cpp
> +++ b/src/cam/options.cpp
> @@ -153,7 +153,17 @@ void OptionsParser::usage()
>  		}
>  
>  		std::cerr << std::setw(indent) << std::left << argument;
> -		std::cerr << option.help << std::endl;
> +
> +		for (const char *help = option.help, *end = help; end; ) {
> +			end = strchr(help, '\n');
> +			if (end) {
> +				std::cerr << std::string(help, end - help + 1);
> +				std::cerr << std::setw(indent) << " ";
> +				help = end + 1;
> +			} else {
> +				std::cerr << help << std::endl;
> +			}
> +		}
>  	}
>  }
>  
> -- 
> Regards,
> 
> Laurent Pinchart
> 
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel@lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel

Patch

diff --git a/src/cam/options.cpp b/src/cam/options.cpp
index 55c42540f924..83601270207b 100644
--- a/src/cam/options.cpp
+++ b/src/cam/options.cpp
@@ -153,7 +153,17 @@  void OptionsParser::usage()
 		}
 
 		std::cerr << std::setw(indent) << std::left << argument;
-		std::cerr << option.help << std::endl;
+
+		for (const char *help = option.help, *end = help; end; ) {
+			end = strchr(help, '\n');
+			if (end) {
+				std::cerr << std::string(help, end - help + 1);
+				std::cerr << std::setw(indent) << " ";
+				help = end + 1;
+			} else {
+				std::cerr << help << std::endl;
+			}
+		}
 	}
 }