From patchwork Thu Jul 15 21:14:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 12979 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id C68D0C3226 for ; Thu, 15 Jul 2021 21:15:19 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 099826854F; Thu, 15 Jul 2021 23:15:15 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="dLlDKLaN"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 44C1C6853C for ; Thu, 15 Jul 2021 23:15:07 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id CBAE8340 for ; Thu, 15 Jul 2021 23:15:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1626383707; bh=STVU7WD6Okipkyu7N9JWNLXmNHQAY+ZettkexYzpVho=; h=From:To:Subject:Date:In-Reply-To:References:From; b=dLlDKLaNh665Un81aoJVSa85OLWeFdMEpJHKqK6c8NcLSEHJqNKeuthmPoiUkNlFo TMuqhMzqvDWJKpQOoVTYVpix3MCOj+VSmqanj8H4EWG+/ElNcEm3NUA9q1ZcIHb9cV mLaNHqqB40QlyBNEA0+5jhQ2aPlDjt6A1y/FCHrc= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Fri, 16 Jul 2021 00:14:34 +0300 Message-Id: <20210715211459.19373-9-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210715211459.19373-1-laurent.pinchart@ideasonboard.com> References: <20210715211459.19373-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 08/33] cam: options: Move key string left in usage() for key-value parser X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" When printing usage information for a key-value parser, the documentation of the keys and values is printed in the second column of the usage text: -s, --stream key=value[,key=value,...] ... Set configuration of a camera stream height=integer Height in pixels pixelformat=string Pixel format name role=string Role for the stream (viewfinder, video, still, raw) width=integer Width in pixels -h, --help Display this help message This results in long lines. Improve this by moving the key description to the first column, and aligning the value description as other option description text: -s, --stream key=value[,key=value,...] ... Set configuration of a camera stream height=integer Height in pixels pixelformat=string Pixel format name role=string Role for the stream (viewfinder, video, still, raw) width=integer Width in pixels -h, --help Display this help message Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- src/cam/options.cpp | 28 ++++++++++++++++++---------- src/cam/options.h | 1 + 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/cam/options.cpp b/src/cam/options.cpp index 350c8084f75f..379b68c3be60 100644 --- a/src/cam/options.cpp +++ b/src/cam/options.cpp @@ -410,27 +410,30 @@ KeyValueParser::Options KeyValueParser::parse(const char *arguments) return options; } -void KeyValueParser::usage(int indent) +unsigned int KeyValueParser::maxOptionLength() const { - unsigned int space = 0; + unsigned int maxLength = 0; for (auto const &iter : optionsMap_) { const Option &option = iter.second; - unsigned int length = 14; + unsigned int length = 10 + strlen(option.name); if (option.argument != ArgumentNone) length += 1 + strlen(option.typeName()); if (option.argument == ArgumentOptional) length += 2; - if (length > space) - space = length; + if (length > maxLength) + maxLength = length; } - space = (space + 7) / 8 * 8; + return maxLength; +} +void KeyValueParser::usage(int indent) +{ for (auto const &iter : optionsMap_) { const Option &option = iter.second; - std::string argument = option.name; + std::string argument = std::string(" ") + option.name; if (option.argument != ArgumentNone) { if (option.argument == ArgumentOptional) @@ -442,14 +445,13 @@ void KeyValueParser::usage(int indent) argument += "]"; } - std::cerr << std::setw(indent) << std::right << " " - << std::setw(space) << std::left << argument; + std::cerr << std::setw(indent) << std::left << argument; 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 + space) << " "; + std::cerr << std::setw(indent) << " "; help = end + 1; } else { std::cerr << help << std::endl; @@ -917,6 +919,12 @@ void OptionsParser::usage() if (length > indent) indent = length; + + if (option->keyValueParser) { + length = option->keyValueParser->maxOptionLength(); + if (length > indent) + indent = length; + } } indent = (indent + 7) / 8 * 8; diff --git a/src/cam/options.h b/src/cam/options.h index 4418e201bf1f..5c51a94c2f37 100644 --- a/src/cam/options.h +++ b/src/cam/options.h @@ -72,6 +72,7 @@ private: KeyValueParser &operator=(const KeyValueParser &) = delete; friend class OptionsParser; + unsigned int maxOptionLength() const; void usage(int indent); std::map optionsMap_;