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 BF6DC431FCB for ; Sat, 19 Jan 2013 16:51:20 -0800 (PST) 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 3IRHTWOnGfM1 for ; Sat, 19 Jan 2013 16:51:19 -0800 (PST) Received: from mail-da0-f41.google.com (mail-da0-f41.google.com [209.85.210.41]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 2164F431FD7 for ; Sat, 19 Jan 2013 16:51:13 -0800 (PST) Received: by mail-da0-f41.google.com with SMTP id e20so2173786dak.0 for ; Sat, 19 Jan 2013 16:51:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=yYO3yXQ8teEYfIowhs5IPJMox5W3E3gv0TRKzrxCX70=; b=kLWZfOfXhrxzPWs3R6sRigk7oIFwLI4KJeuM+Xs1Ub1hXDqTI3aGnmGRgaGJliZFiX yoh/m7ShYpWyXHzZYGys/Mu/zaaT0s6hzywHsl52hByoNh4a9gZct9aHx6lKKDHVwSVW yD79fGPy9edAW7rXC5JvGSiUBPrLii4+8xugCxfpC6I2RwH1Q/nTTCTtw/hQsYYnLXCj 8/cO5BF/0cXe8sOOUQvXMOiNwrjXtxd9i1BqnDfp8C3PR7F94CSkO1URoHHGQJNC6a3H RcpJUGR3aVeoc97YKKyxg7B7mcqwqGmAL/FgQHwChvybidSmTV0U+G3ulRWCQEk8MTIy tAmA== X-Received: by 10.68.222.196 with SMTP id qo4mr18542791pbc.140.1358643072235; Sat, 19 Jan 2013 16:51:12 -0800 (PST) Received: from localhost (215.42.233.220.static.exetel.com.au. [220.233.42.215]) by mx.google.com with ESMTPS id nm2sm5799967pbc.43.2013.01.19.16.51.10 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sat, 19 Jan 2013 16:51:11 -0800 (PST) From: Peter Wang To: notmuch@notmuchmail.org Subject: [PATCH v3 08/20] tag-util: move out 'tag' command-line checks Date: Sun, 20 Jan 2013 11:49:52 +1100 Message-Id: <1358643004-14522-9-git-send-email-novalazy@gmail.com> X-Mailer: git-send-email 1.7.12.1 In-Reply-To: <1358643004-14522-1-git-send-email-novalazy@gmail.com> References: <1358643004-14522-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: Sun, 20 Jan 2013 00:51:21 -0000 parse_tag_command_line checked for two error conditions which are specific to the 'tag' command. It can be reused for the notmuch 'insert' command if we move the checks out, into notmuch-tag.c. --- notmuch-tag.c | 10 ++++++++++ tag-util.c | 10 ---------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/notmuch-tag.c b/notmuch-tag.c index d9daf8f..a901dad 100644 --- a/notmuch-tag.c +++ b/notmuch-tag.c @@ -234,6 +234,16 @@ notmuch_tag_command (void *ctx, int argc, char *argv[]) if (parse_tag_command_line (ctx, argc - opt_index, argv + opt_index, &query_string, tag_ops)) return 1; + + if (tag_op_list_size (tag_ops) == 0) { + fprintf (stderr, "Error: 'notmuch tag' requires at least one tag to add or remove.\n"); + return 1; + } + + if (*query_string == '\0') { + fprintf (stderr, "Error: notmuch tag requires at least one search term.\n"); + return 1; + } } config = notmuch_config_open (ctx, NULL, NULL); diff --git a/tag-util.c b/tag-util.c index 3f9da05..41f2c09 100644 --- a/tag-util.c +++ b/tag-util.c @@ -186,18 +186,8 @@ parse_tag_command_line (void *ctx, int argc, char **argv, tag_op_list_append (tag_ops, argv[i] + 1, is_remove); } - if (tag_op_list_size (tag_ops) == 0) { - fprintf (stderr, "Error: 'notmuch tag' requires at least one tag to add or remove.\n"); - return TAG_PARSE_INVALID; - } - *query_str = query_string_from_args (ctx, argc - i, &argv[i]); - if (*query_str == NULL || **query_str == '\0') { - fprintf (stderr, "Error: notmuch tag requires at least one search term.\n"); - return TAG_PARSE_INVALID; - } - return TAG_PARSE_SUCCESS; } -- 1.7.12.1