From patchwork Thu Jul 15 21:14:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 12986 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 369FAC3227 for ; Thu, 15 Jul 2021 21:15:23 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4434A6059F; Thu, 15 Jul 2021 23:15:20 +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="UaL6Jkas"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 653B468553 for ; Thu, 15 Jul 2021 23:15:09 +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 CE405340 for ; Thu, 15 Jul 2021 23:15:08 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1626383709; bh=d/GKM8jX8FccS5quAQcvimkG/BOL4gq1kNDBoypOx4E=; h=From:To:Subject:Date:In-Reply-To:References:From; b=UaL6JkasM2xf0Of6W1EClrqRi3jLr2bG2YIF9JyMJukk0hir8KDUhOq/3/kmi5EDP RLrQprccLEPEQ+E4yw8OivQShkiPnzW3xKI9oJLIFUKHmox6Bp0j5jB+rmCwu31Zv2 dCMzcwHz8kAsTV2tKprnpEoQSl+SbyBHDvlMXrxg= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Fri, 16 Jul 2021 00:14:40 +0300 Message-Id: <20210715211459.19373-15-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 14/33] cam: options: Fail parsing when non-option arguments are found 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" The options parser currently ignores non-option arguments silently, which is confusing. It's a common error to run 'cam -c1 -C 10' and expect only 10 frames to be captured. As the -C option takes an optional argument, the number 10 is interpreted as a non-option argument instead of the argument to the -C option. Fail parsing with an appropriate message and print usage information when a non-option argument is found. The parser may be extended later to accept non-option arguments when the application has a use for them. Signed-off-by: Laurent Pinchart Reviewed-by: Jacopo Mondi --- src/cam/options.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/cam/options.cpp b/src/cam/options.cpp index 6e0d802cb986..33bc512e6571 100644 --- a/src/cam/options.cpp +++ b/src/cam/options.cpp @@ -945,6 +945,13 @@ OptionsParser::Options OptionsParser::parse(int argc, char **argv) } } + if (optind < argc) { + std::cerr << "Invalid non-option argument '" << argv[optind] + << "'" << std::endl; + usage(); + return options; + } + options.valid_ = true; return options; }