From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 18E866DE0352 for ; Sat, 14 Oct 2017 06:15:51 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: 0.018 X-Spam-Level: X-Spam-Status: No, score=0.018 tagged_above=-999 required=5 tests=[AWL=0.038, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ttZw42OWZlek for ; Sat, 14 Oct 2017 06:15:50 -0700 (PDT) Received: from mail-lf0-f45.google.com (mail-lf0-f45.google.com [209.85.215.45]) by arlo.cworth.org (Postfix) with ESMTPS id D92296DE01C2 for ; Sat, 14 Oct 2017 06:15:49 -0700 (PDT) Received: by mail-lf0-f45.google.com with SMTP id a69so12371530lfe.5 for ; Sat, 14 Oct 2017 06:15:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nikula-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=sJ7d7kJgIAYq1FbYgy2IscoHhvDUy4v1UKnbnHkIf34=; b=DMpYs+aiX3oCbBFffQBotlc+8/HelQ5qnLrHBvy1gS8coHNx/GpE47I1rBYNX6lQPs logm3IOA+mCQt9Db9JMzcBVNorBLtaJIunKIZSYY720urpwnQSakPiNa1S8yNONkqRSk pFjF2n216FyoKyOD4L6f8iVvxliTYOr6PL39nDQCQMw43Q+pEYo2XsR9J7+hRrocQOwk kF2pjLkagLEnAP/CGADyqpG47EBKcWjNmMGtYjnGDBIi0w+KraDdr4kBE5GJp0KOR9vM o7n+fYI4HeGg7mCx/BSO+emI5HH46LZDnqmNBnYyfTVR6xaCD3szOo+IVxwxnLP2VZ7U 510Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=sJ7d7kJgIAYq1FbYgy2IscoHhvDUy4v1UKnbnHkIf34=; b=eku6sqHyOAJlTH+hf0g4w+WL6dfmP4NUaOc3L2u9Y8AVE2Jb/OWSt3NufNqZ5sZPtK xbAlEcCJC8F2d4Ze5uRmBhwSDutipL5865dAqCoDD5KbH5tuLer3TD8sEc6heDbYMx1E uunwM1L+fU7O2HySNdUMIM53F4sHtDfEKWt+tTOxFpqskfPCP0YKbqstP7drYj8VWan3 xVkeuJRLTbsk7NdAYJFurZQVsAFkTu4yAOJHm4qv3h9geqYipZIuAMbnCpgpCH6cVddE HhONNV4LZRu/i9hvOdBl0hG2rSnSigDT1lVJGWVCV4M4KjJjPxbpYMj/XdGfAkQB6VDh ts6w== X-Gm-Message-State: AMCzsaU4Iy4+Q4DimARAAGzHzMm9uH+LMPrxseSFG96nGWvasVlzDJQn NUKizz+1GKmsQjPKX6P4hyiTIK2LCZM= X-Google-Smtp-Source: ABhQp+QkNAUpIEYt2Ue20sh/wvH+2I1HSqO7MUSH0tLMRr/mObPu9m7GaSYsDAGuFFm3f/xjm0rZhg== X-Received: by 10.46.16.218 with SMTP id 87mr2070206ljq.115.1507986947398; Sat, 14 Oct 2017 06:15:47 -0700 (PDT) Received: from localhost (mobile-access-5d6a0c-19.dhcp.inet.fi. [93.106.12.19]) by smtp.gmail.com with ESMTPSA id r101sm615382lfi.17.2017.10.14.06.15.46 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 14 Oct 2017 06:15:46 -0700 (PDT) From: Jani Nikula To: notmuch@notmuchmail.org Subject: [PATCH] cli: allow empty strings for notmuch insert --folder argument Date: Sat, 14 Oct 2017 16:15:43 +0300 Message-Id: <20171014131543.17521-1-jani@nikula.org> X-Mailer: git-send-email 2.11.0 X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.23 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 Oct 2017 13:15:51 -0000 Now that it's easy to add argument specific modifiers in opt descriptions, add a new .allow_empty field to allow empty strings for individual string arguments while retaining strict checks elsewhere. Use this for notmuch insert --folder, where the empty string means top level folder. --- This patch addresses id:87y3owr22c.fsf@nikula.org --- command-line-arguments.c | 2 +- command-line-arguments.h | 3 +++ doc/man1/notmuch-insert.rst | 3 ++- notmuch-insert.c | 2 +- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/command-line-arguments.c b/command-line-arguments.c index 1ff5aae578c6..db73ca5efb89 100644 --- a/command-line-arguments.c +++ b/command-line-arguments.c @@ -81,7 +81,7 @@ _process_string_arg (const notmuch_opt_desc_t *arg_desc, char next, const char * fprintf (stderr, "Option \"%s\" needs a string argument.\n", arg_desc->name); return false; } - if (arg_str[0] == '\0') { + if (arg_str[0] == '\0' && ! arg_desc->allow_empty) { fprintf (stderr, "String argument for option \"%s\" must be non-empty.\n", arg_desc->name); return false; } diff --git a/command-line-arguments.h b/command-line-arguments.h index 76ca4dcbb276..c0228f7cb634 100644 --- a/command-line-arguments.h +++ b/command-line-arguments.h @@ -32,6 +32,9 @@ typedef struct notmuch_opt_desc { /* Optional, if non-NULL, set to true if the option is present. */ bool *present; + /* Optional, allow empty strings for opt_string. */ + bool allow_empty; + /* Must be set for opt_keyword and opt_flags. */ const struct notmuch_keyword *keywords; } notmuch_opt_desc_t; diff --git a/doc/man1/notmuch-insert.rst b/doc/man1/notmuch-insert.rst index f79600d6571f..2f2466a6588b 100644 --- a/doc/man1/notmuch-insert.rst +++ b/doc/man1/notmuch-insert.rst @@ -34,7 +34,8 @@ Supported options for **insert** include ``--folder=<``\ folder\ **>** Deliver the message to the specified folder, relative to the top-level directory given by the value of **database.path**. The - default is to deliver to the top-level directory. + default is the empty string, which means delivering to the + top-level directory. ``--create-folder`` Try to create the folder named by the ``--folder`` option, if it diff --git a/notmuch-insert.c b/notmuch-insert.c index 32be74193472..cff74731aaaa 100644 --- a/notmuch-insert.c +++ b/notmuch-insert.c @@ -463,7 +463,7 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[]) unsigned int i; notmuch_opt_desc_t options[] = { - { .opt_string = &folder, .name = "folder" }, + { .opt_string = &folder, .name = "folder", .allow_empty = true }, { .opt_bool = &create_folder, .name = "create-folder" }, { .opt_bool = &keep, .name = "keep" }, { .opt_bool = &no_hooks, .name = "no-hooks" }, -- 2.11.0