Re: notmuch-search-toggle-order and notmuch-tree
[notmuch-archives.git] / 3b / a7b5c8e0114d7dca22a368233357ad60951d0f
1 Return-Path: <sojkam1@fel.cvut.cz>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 0EE72429E30\r
6         for <notmuch@notmuchmail.org>; Thu, 30 Oct 2014 16:59:57 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -2.3\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id DVNCoY47OsYk for <notmuch@notmuchmail.org>;\r
16         Thu, 30 Oct 2014 16:59:52 -0700 (PDT)\r
17 Received: from max.feld.cvut.cz (max.feld.cvut.cz [147.32.192.36])\r
18         by olra.theworths.org (Postfix) with ESMTP id D58EF431FDB\r
19         for <notmuch@notmuchmail.org>; Thu, 30 Oct 2014 16:59:45 -0700 (PDT)\r
20 Received: from localhost (unknown [192.168.200.7])\r
21         by max.feld.cvut.cz (Postfix) with ESMTP id 44E725CCFF5\r
22         for <notmuch@notmuchmail.org>; Fri, 31 Oct 2014 00:59:45 +0100 (CET)\r
23 X-Virus-Scanned: IMAP STYX AMAVIS\r
24 Received: from max.feld.cvut.cz ([192.168.200.1])\r
25         by localhost (styx.feld.cvut.cz [192.168.200.7]) (amavisd-new,\r
26         port 10044) with ESMTP id Z-M6ezEjNVDH for <notmuch@notmuchmail.org>;\r
27         Fri, 31 Oct 2014 00:59:40 +0100 (CET)\r
28 Received: from imap.feld.cvut.cz (imap.feld.cvut.cz [147.32.192.34])\r
29         by max.feld.cvut.cz (Postfix) with ESMTP id 74A915CCFF6\r
30         for <notmuch@notmuchmail.org>; Fri, 31 Oct 2014 00:59:40 +0100 (CET)\r
31 Received: from wsh by steelpick.2x.cz with local (Exim 4.84)\r
32         (envelope-from <sojkam1@fel.cvut.cz>)\r
33         id 1Xjzcs-0005bO-Qp; Fri, 31 Oct 2014 00:59:34 +0100\r
34 From: Michal Sojka <sojkam1@fel.cvut.cz>\r
35 To: notmuch@notmuchmail.org\r
36 Subject: [PATCH v5 3/7] cli: search: Convert --output to keyword-flag argument\r
37 Date: Fri, 31 Oct 2014 00:59:29 +0100\r
38 Message-Id: <1414713573-21461-4-git-send-email-sojkam1@fel.cvut.cz>\r
39 X-Mailer: git-send-email 2.1.1\r
40 In-Reply-To: <1414713573-21461-1-git-send-email-sojkam1@fel.cvut.cz>\r
41 References: <1414713573-21461-1-git-send-email-sojkam1@fel.cvut.cz>\r
42 X-BeenThere: notmuch@notmuchmail.org\r
43 X-Mailman-Version: 2.1.13\r
44 Precedence: list\r
45 List-Id: "Use and development of the notmuch mail system."\r
46         <notmuch.notmuchmail.org>\r
47 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
48         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
49 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
50 List-Post: <mailto:notmuch@notmuchmail.org>\r
51 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
52 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
53         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
54 X-List-Received-Date: Thu, 30 Oct 2014 23:59:57 -0000\r
55 \r
56 This converts "notmuch search" to use the recently introduced\r
57 keyword-flag argument parser. At this point, it only makes the code\r
58 slightly less readable but following commits that add new --output\r
59 keywords will profit from this.\r
60 ---\r
61  notmuch-search.c | 35 ++++++++++++++++++-----------------\r
62  1 file changed, 18 insertions(+), 17 deletions(-)\r
63 \r
64 diff --git a/notmuch-search.c b/notmuch-search.c\r
65 index 0c3e972..ce46877 100644\r
66 --- a/notmuch-search.c\r
67 +++ b/notmuch-search.c\r
68 @@ -23,11 +23,11 @@\r
69  #include "string-util.h"\r
70  \r
71  typedef enum {\r
72 -    OUTPUT_SUMMARY,\r
73 -    OUTPUT_THREADS,\r
74 -    OUTPUT_MESSAGES,\r
75 -    OUTPUT_FILES,\r
76 -    OUTPUT_TAGS\r
77 +    OUTPUT_SUMMARY     = 1 << 0,\r
78 +    OUTPUT_THREADS     = 1 << 1,\r
79 +    OUTPUT_MESSAGES    = 1 << 2,\r
80 +    OUTPUT_FILES       = 1 << 3,\r
81 +    OUTPUT_TAGS                = 1 << 4,\r
82  } output_t;\r
83  \r
84  typedef struct {\r
85 @@ -338,7 +338,7 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
86      notmuch_database_t *notmuch;\r
87      search_options_t opt = {\r
88         .sort = NOTMUCH_SORT_NEWEST_FIRST,\r
89 -       .output = OUTPUT_SUMMARY,\r
90 +       .output = 0,\r
91         .offset = 0,\r
92         .limit = -1, /* unlimited */\r
93         .dupe = -1,\r
94 @@ -367,7 +367,7 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
95                                   { "text0", NOTMUCH_FORMAT_TEXT0 },\r
96                                   { 0, 0 } } },\r
97         { NOTMUCH_OPT_INT, &notmuch_format_version, "format-version", 0, 0 },\r
98 -       { NOTMUCH_OPT_KEYWORD, &opt.output, "output", 'o',\r
99 +       { NOTMUCH_OPT_KEYWORD_FLAGS, &opt.output, "output", 'o',\r
100           (notmuch_keyword_t []){ { "summary", OUTPUT_SUMMARY },\r
101                                   { "threads", OUTPUT_THREADS },\r
102                                   { "messages", OUTPUT_MESSAGES },\r
103 @@ -390,6 +390,9 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
104      if (opt_index < 0)\r
105         return EXIT_FAILURE;\r
106  \r
107 +    if (! opt.output)\r
108 +       opt.output = OUTPUT_SUMMARY;\r
109 +\r
110      switch (format_sel) {\r
111      case NOTMUCH_FORMAT_TEXT:\r
112         opt.format = sprinter_text_create (config, stdout);\r
113 @@ -455,19 +458,17 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
114         notmuch_query_set_omit_excluded (opt.query, exclude);\r
115      }\r
116  \r
117 -    switch (opt.output) {\r
118 -    default:\r
119 -    case OUTPUT_SUMMARY:\r
120 -    case OUTPUT_THREADS:\r
121 +    if (opt.output == OUTPUT_SUMMARY ||\r
122 +       opt.output == OUTPUT_THREADS)\r
123         ret = do_search_threads (&opt);\r
124 -       break;\r
125 -    case OUTPUT_MESSAGES:\r
126 -    case OUTPUT_FILES:\r
127 +    else if (opt.output == OUTPUT_MESSAGES ||\r
128 +            opt.output == OUTPUT_FILES)\r
129         ret = do_search_messages (&opt);\r
130 -       break;\r
131 -    case OUTPUT_TAGS:\r
132 +    else if (opt.output == OUTPUT_TAGS)\r
133         ret = do_search_tags (notmuch, &opt);\r
134 -       break;\r
135 +    else {\r
136 +       fprintf (stderr, "Error: the combination of outputs is not supported.\n");\r
137 +       ret = 1;\r
138      }\r
139  \r
140      notmuch_query_destroy (opt.query);\r
141 -- \r
142 2.1.1\r
143 \r