Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 8D090431FBF for ; Fri, 13 Apr 2012 18:43:36 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.799 X-Spam-Level: X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 2AKb3fQvrL8N for ; Fri, 13 Apr 2012 18:43:36 -0700 (PDT) Received: from mail-pz0-f45.google.com (mail-pz0-f45.google.com [209.85.210.45]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 0CC19431FAE for ; Fri, 13 Apr 2012 18:43:35 -0700 (PDT) Received: by dacx6 with SMTP id x6so4544874dac.18 for ; Fri, 13 Apr 2012 18:43:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=lmn8Aj6p+epysJlCbiJEigYuq4f8RB5x6He9rAQDvaU=; b=lOjcKBmt/uT6C7E7aKD6wt5KCvvv9LFcA6Y5Gv5Ckuco+6u45bANDaWXG/PFR/qOMF hBZGxcEF6oJUXmUpuRYJ8rs0TMrOQOQEz/bafolnTukt+BVb36jvg6R/1+d/CudiF1k/ QTAltpm405/AN2GvCoT1nRmvsbm0JhnZqChNnHrWZ9uJxkIRkPgcz4w+ph/ZvCpaVM5x 2qHcTeo2H159j+clakLk2j2kRX+luQL7s/LBSMYAvGgt4Cqc0xPb42geLBf9mqcRW2t9 ZF4mx/hcHdHXJox+/DxPvUXElfHpKBsK3Kf7h7xbvhzLom20Za6engNsIG7qcS4R+zKQ KjlA== Received: by 10.68.204.234 with SMTP id lb10mr8752105pbc.161.1334367815380; Fri, 13 Apr 2012 18:43:35 -0700 (PDT) Received: from localhost (215.42.233.220.static.exetel.com.au. [220.233.42.215]) by mx.google.com with ESMTPS id y5sm10267958pbk.5.2012.04.13.18.43.31 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 13 Apr 2012 18:43:34 -0700 (PDT) From: Peter Wang To: notmuch@notmuchmail.org Subject: [PATCH v4 2/6] config: Check 'config get' arity exactly Date: Sat, 14 Apr 2012 11:41:02 +1000 Message-Id: <1334367666-10954-3-git-send-email-novalazy@gmail.com> X-Mailer: git-send-email 1.7.4.4 In-Reply-To: <1334367666-10954-1-git-send-email-novalazy@gmail.com> References: <1332282698-7951-1-git-send-email-novalazy@gmail.com> <1334367666-10954-1-git-send-email-novalazy@gmail.com> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 14 Apr 2012 01:43:36 -0000 Require that 'config get' is passed exactly one additional argument, instead of silently ignoring extra arguments. As a side-effect, produce more specific error messages for the 'config' command as a whole. --- notmuch-config.c | 19 +++++++++++++++---- 1 files changed, 15 insertions(+), 4 deletions(-) diff --git a/notmuch-config.c b/notmuch-config.c index 85fc774..f9eb977 100644 --- a/notmuch-config.c +++ b/notmuch-config.c @@ -804,15 +804,26 @@ notmuch_config_command (void *ctx, int argc, char *argv[]) { argc--; argv++; /* skip subcommand argument */ - if (argc < 2) { - fprintf (stderr, "Error: notmuch config requires at least two arguments.\n"); + if (argc < 1) { + fprintf (stderr, "Error: notmuch config requires at least one argument.\n"); return 1; } - if (strcmp (argv[0], "get") == 0) + if (strcmp (argv[0], "get") == 0) { + if (argc != 2) { + fprintf (stderr, "Error: notmuch config get requires exactly " + "one argument.\n"); + return 1; + } return notmuch_config_command_get (ctx, argv[1]); - else if (strcmp (argv[0], "set") == 0) + } else if (strcmp (argv[0], "set") == 0) { + if (argc < 2) { + fprintf (stderr, "Error: notmuch config set requires at least " + "one argument.\n"); + return 1; + } return notmuch_config_command_set (ctx, argv[1], argc - 2, argv + 2); + } fprintf (stderr, "Unrecognized argument for notmuch config: %s\n", argv[0]); -- 1.7.4.4