Re: Flat search and threaded views
[notmuch-archives.git] / 36 / 2aec6e132f752e5107263e02ca657de71738e2
1 Return-Path: <bremner@tesseract.cs.unb.ca>\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 arlo.cworth.org (Postfix) with ESMTP id B17516DE1B09\r
6  for <notmuch@notmuchmail.org>; Tue,  7 Apr 2015 12:33:40 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0.419\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0.419 tagged_above=-999 required=5 tests=[AWL=0.409, \r
12  T_HEADER_FROM_DIFFERENT_DOMAINS=0.01] autolearn=disabled\r
13 Received: from arlo.cworth.org ([127.0.0.1])\r
14  by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
15  with ESMTP id 62ymMWw1fqm9 for <notmuch@notmuchmail.org>;\r
16  Tue,  7 Apr 2015 12:33:38 -0700 (PDT)\r
17 Received: from mx.xen14.node3324.gplhost.com (gitolite.debian.net\r
18  [87.98.215.224])\r
19  by arlo.cworth.org (Postfix) with ESMTPS id 8DCDD6DE1B00\r
20  for <notmuch@notmuchmail.org>; Tue,  7 Apr 2015 12:33:38 -0700 (PDT)\r
21 Received: from remotemail by mx.xen14.node3324.gplhost.com with local (Exim\r
22  4.80) (envelope-from <bremner@tesseract.cs.unb.ca>)\r
23  id 1YfZE9-0001y9-4H; Tue, 07 Apr 2015 19:32:01 +0000\r
24 Received: (nullmailer pid 16656 invoked by uid 1000); Tue, 07 Apr 2015\r
25  19:30:51 -0000\r
26 From: David Bremner <david@tethera.net>\r
27 To: Mark Walters <markwalters1009@gmail.com>, David Bremner\r
28  <david@tethera.net>, notmuch@notmuchmail.org\r
29 Subject: [PATCH 4/4] cli: add standard option processing to config, help and\r
30  setup\r
31 Date: Wed,  8 Apr 2015 04:30:42 +0900\r
32 Message-Id: <1428435042-16503-5-git-send-email-david@tethera.net>\r
33 X-Mailer: git-send-email 2.1.4\r
34 In-Reply-To: <1428435042-16503-1-git-send-email-david@tethera.net>\r
35 References: <871tjws8w8.fsf@qmul.ac.uk>\r
36  <1428435042-16503-1-git-send-email-david@tethera.net>\r
37 X-BeenThere: notmuch@notmuchmail.org\r
38 X-Mailman-Version: 2.1.18\r
39 Precedence: list\r
40 List-Id: "Use and development of the notmuch mail system."\r
41  <notmuch.notmuchmail.org>\r
42 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
43  <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
44 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
45 List-Post: <mailto:notmuch@notmuchmail.org>\r
46 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
47 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
48  <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
49 X-List-Received-Date: Tue, 07 Apr 2015 19:33:40 -0000\r
50 \r
51 In particular this fixes a recently encountered bug where the\r
52 "--config" argument to "notmuch setup" is silently ignored, which the\r
53 unpleasant consequence of overwriting the users config file.\r
54 ---\r
55  notmuch-client.h     |  2 ++\r
56  notmuch-config.c     |  9 ++++++++-\r
57  notmuch-setup.c      |  3 +++\r
58  notmuch.c            | 32 +++++++++++++++++++++++++++++++-\r
59  test/random-corpus.c |  9 +++++++++\r
60  5 files changed, 53 insertions(+), 2 deletions(-)\r
61 \r
62 diff --git a/notmuch-client.h b/notmuch-client.h\r
63 index 8ecfac6..78680aa 100644\r
64 --- a/notmuch-client.h\r
65 +++ b/notmuch-client.h\r
66 @@ -468,4 +468,6 @@ notmuch_database_dump (notmuch_database_t *notmuch,\r
67  #include "command-line-arguments.h"\r
68  extern const notmuch_opt_desc_t  notmuch_shared_options [];\r
69  void notmuch_process_shared_options (const char* subcommand_name);\r
70 +int notmuch_minimal_options (const char* subcommand_name,\r
71 +                            int argc, char **argv);\r
72  #endif\r
73 diff --git a/notmuch-config.c b/notmuch-config.c\r
74 index 2d5c297..9348278 100644\r
75 --- a/notmuch-config.c\r
76 +++ b/notmuch-config.c\r
77 @@ -872,8 +872,15 @@ int\r
78  notmuch_config_command (notmuch_config_t *config, int argc, char *argv[])\r
79  {\r
80      int ret;\r
81 +    int opt_index;\r
82  \r
83 -    argc--; argv++; /* skip subcommand argument */\r
84 +    opt_index = notmuch_minimal_options ("config", argc, argv);\r
85 +    if (opt_index < 0)\r
86 +       return EXIT_FAILURE;\r
87 +\r
88 +    /* skip at least subcommand argument */\r
89 +    argc-= opt_index;\r
90 +    argv+= opt_index;\r
91  \r
92      if (argc < 1) {\r
93         fprintf (stderr, "Error: notmuch config requires at least one argument.\n");\r
94 diff --git a/notmuch-setup.c b/notmuch-setup.c\r
95 index 36a6171..7dd5822 100644\r
96 --- a/notmuch-setup.c\r
97 +++ b/notmuch-setup.c\r
98 @@ -145,6 +145,9 @@ notmuch_setup_command (notmuch_config_t *config,\r
99         chomp_newline (response);                               \\r
100      } while (0)\r
101  \r
102 +    if (notmuch_minimal_options ("setup", argc, argv) < 0)\r
103 +       return EXIT_FAILURE;\r
104 +\r
105      if (notmuch_config_is_new (config))\r
106         welcome_message_pre_setup ();\r
107  \r
108 diff --git a/notmuch.c b/notmuch.c\r
109 index 3a9da90..2198b73 100644\r
110 --- a/notmuch.c\r
111 +++ b/notmuch.c\r
112 @@ -71,6 +71,28 @@ notmuch_process_shared_options (const char *subcommand_name) {\r
113      }\r
114  }\r
115  \r
116 +/* This is suitable for subcommands that do not actually open the\r
117 + * database.\r
118 + */\r
119 +int notmuch_minimal_options (const char *subcommand_name,\r
120 +                                 int argc, char **argv)\r
121 +{\r
122 +    int opt_index;\r
123 +\r
124 +    notmuch_opt_desc_t options[] = {\r
125 +       { NOTMUCH_OPT_INHERIT, (void *) &notmuch_shared_options, NULL, 0, 0 },\r
126 +       { 0, 0, 0, 0, 0 }\r
127 +    };\r
128 +\r
129 +    opt_index = parse_arguments (argc, argv, options, 1);\r
130 +\r
131 +    if (opt_index < 0)\r
132 +       return -1;\r
133 +\r
134 +    /* We can't use argv here as it is sometimes NULL */\r
135 +    notmuch_process_shared_options (subcommand_name);\r
136 +    return opt_index;\r
137 +}\r
138  \r
139  static command_t commands[] = {\r
140      { NULL, notmuch_command, TRUE,\r
141 @@ -250,7 +272,15 @@ _help_for (const char *topic_name)\r
142  static int\r
143  notmuch_help_command (unused (notmuch_config_t * config), int argc, char *argv[])\r
144  {\r
145 -    argc--; argv++; /* Ignore "help" */\r
146 +    int opt_index;\r
147 +\r
148 +    opt_index = notmuch_minimal_options ("help", argc, argv);\r
149 +    if (opt_index < 0)\r
150 +       return EXIT_FAILURE;\r
151 +\r
152 +    /* skip at least subcommand argument */\r
153 +    argc-= opt_index;\r
154 +    argv+= opt_index;\r
155  \r
156      if (argc == 0) {\r
157         return _help_for (NULL);\r
158 diff --git a/test/random-corpus.c b/test/random-corpus.c\r
159 index 790193d..6c467bb 100644\r
160 --- a/test/random-corpus.c\r
161 +++ b/test/random-corpus.c\r
162 @@ -114,6 +114,15 @@ random_utf8_string (void *ctx, size_t char_count)\r
163      return buf;\r
164  }\r
165  \r
166 +/* stubs since we cannot link with notmuch.o */\r
167 +const notmuch_opt_desc_t notmuch_shared_options[] = {\r
168 +       { 0, 0, 0, 0, 0 }\r
169 +};\r
170 +\r
171 +void\r
172 +notmuch_process_shared_options (unused (const char *dummy))\r
173 +{\r
174 +}\r
175  \r
176  int\r
177  main (int argc, char **argv)\r
178 -- \r
179 2.1.4\r
180 \r