From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 2DFAC429E4A for ; Fri, 30 Mar 2012 16:16:35 -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 m2oqf-w3jTLl for ; Fri, 30 Mar 2012 16:16:34 -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 DCE90429E3F for ; Fri, 30 Mar 2012 16:16:33 -0700 (PDT) Received: by mail-pz0-f45.google.com with SMTP id x6so56814dac.18 for ; Fri, 30 Mar 2012 16:16:33 -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=EIW4MgoXQ8IckMFDn4dVnDcVIEoWDj+jt7Brxzk8OS0=; b=P0fn9c2JAhaf/iM/V8tw2C3Oyt3rcPkKue0vW1jYd8fpOnZ+sKU0BqHvShLAdg/9XF PZtG3hE6iBLALhVBh1hdkq6fT3JCGZOAaw2qsOoiLjxtgxWKXSUXpr4MvaNG9EgZrQ4E Cr5gRV9KPVESE5453Z9RdBPMl1+1ns1wrFK+fxY0UEmsFX/nbjnqSLeSU7bl+sF/6ReL 2E4owureGmaWL5RsLSlIPYw2/4TIDKmUrkOd7FofZ8RFoqkypC9W31I9WHSNe4MI2SeW 1as64+N87B1rRs3QKEIuzKBQhccBT6xPv9xRyG6Zu1AOzjEZc/rjg5AS9vLvX5NLA+6h D4VQ== Received: by 10.68.218.72 with SMTP id pe8mr1856727pbc.45.1333149393649; Fri, 30 Mar 2012 16:16:33 -0700 (PDT) Received: from localhost (215.42.233.220.static.exetel.com.au. [220.233.42.215]) by mx.google.com with ESMTPS id ko12sm8309130pbb.52.2012.03.30.16.16.30 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 30 Mar 2012 16:16:31 -0700 (PDT) From: Peter Wang To: notmuch@notmuchmail.org Subject: [PATCH v2 4/5] config: Add 'config list' command Date: Sat, 31 Mar 2012 10:15:49 +1100 Message-Id: <1333149350-22616-5-git-send-email-novalazy@gmail.com> X-Mailer: git-send-email 1.7.4.4 In-Reply-To: <1333149350-22616-1-git-send-email-novalazy@gmail.com> References: <1332282698-7951-1-git-send-email-novalazy@gmail.com> <1333149350-22616-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: Fri, 30 Mar 2012 23:16:35 -0000 Add a command to list all configuration items with their associated values. One use is as follows: a MUA may prefer to store data in a central notmuch configuration file so that the data is accessible across different machines, e.g. an addressbook. The list command helps to implement features such as tab completion on the keys. --- notmuch-config.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++--- test/config | 1 - 2 files changed, 62 insertions(+), 5 deletions(-) diff --git a/notmuch-config.c b/notmuch-config.c index 85fc774..d5540ac 100644 --- a/notmuch-config.c +++ b/notmuch-config.c @@ -799,20 +799,78 @@ notmuch_config_command_set (void *ctx, char *item, int argc, char *argv[]) return ret; } +static int +notmuch_config_command_list (void *ctx) +{ + notmuch_config_t *config; + char **groups; + size_t g, groups_length; + + config = notmuch_config_open (ctx, NULL, NULL); + if (config == NULL) + return 1; + + groups = g_key_file_get_groups (config->key_file, &groups_length); + if (groups == NULL) + return 1; + + for (g = 0; g < groups_length; g++) { + char **keys; + size_t k, keys_length; + + keys = g_key_file_get_keys (config->key_file, + groups[g], &keys_length, NULL); + if (keys == NULL) + continue; + + for (k = 0; k < keys_length; k++) { + char *value; + + value = g_key_file_get_string (config->key_file, + groups[g], keys[k], NULL); + if (value != NULL) { + printf ("%s.%s=%s\n", groups[g], keys[k], value); + free (value); + } + } + + g_strfreev (keys); + } + + g_strfreev (groups); + + notmuch_config_close (config); + + return 0; +} + int 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 at least " + "two arguments.\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 " + "two arguments.\n"); + return 1; + } return notmuch_config_command_set (ctx, argv[1], argc - 2, argv + 2); + } else if (strcmp (argv[0], "list") == 0) { + return notmuch_config_command_list (ctx); + } fprintf (stderr, "Unrecognized argument for notmuch config: %s\n", argv[0]); diff --git a/test/config b/test/config index 73c58ff..93e3a04 100755 --- a/test/config +++ b/test/config @@ -18,7 +18,6 @@ test_expect_success "Set list value" \ 'notmuch config set foo.list xxx "yyy yyy" "zzz zzz"' test_begin_subtest "List all items" -test_subtest_known_broken notmuch config set database.path "/canonical/path" output=$(notmuch config list) test_expect_equal "$output" "\ -- 1.7.4.4