1 Return-Path: <jani@nikula.org>
\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 4A319429E35
\r
6 for <notmuch@notmuchmail.org>; Sun, 13 Nov 2011 14:47:43 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
8 X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"
\r
12 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5
\r
13 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled
\r
14 Received: from olra.theworths.org ([127.0.0.1])
\r
15 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
16 with ESMTP id aIF2gzVJAjhv for <notmuch@notmuchmail.org>;
\r
17 Sun, 13 Nov 2011 14:47:41 -0800 (PST)
\r
18 Received: from mail-bw0-f53.google.com (mail-bw0-f53.google.com
\r
19 [209.85.214.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))
\r
20 (No client certificate requested)
\r
21 by olra.theworths.org (Postfix) with ESMTPS id 11AEA429E21
\r
22 for <notmuch@notmuchmail.org>; Sun, 13 Nov 2011 14:47:38 -0800 (PST)
\r
23 Received: by mail-bw0-f53.google.com with SMTP id q10so6354254bka.26
\r
24 for <notmuch@notmuchmail.org>; Sun, 13 Nov 2011 14:47:38 -0800 (PST)
\r
25 Received: by 10.205.127.139 with SMTP id ha11mr9075269bkc.111.1321224458469;
\r
26 Sun, 13 Nov 2011 14:47:38 -0800 (PST)
\r
27 Received: from localhost (dsl-hkibrasgw4-fe5cdc00-23.dhcp.inet.fi.
\r
29 by mx.google.com with ESMTPS id x14sm28066514bkf.10.2011.11.13.14.47.36
\r
30 (version=SSLv3 cipher=OTHER); Sun, 13 Nov 2011 14:47:37 -0800 (PST)
\r
31 From: Jani Nikula <jani@nikula.org>
\r
32 To: notmuch@notmuchmail.org,
\r
34 Subject: [PATCH 2/6] cli: notmuch search: use getopt_long for parsing command
\r
36 Date: Mon, 14 Nov 2011 00:47:22 +0200
\r
38 <aa33f9cf06c1909012946c5a9a7c0ff501a394c1.1321223343.git.jani@nikula.org>
\r
39 X-Mailer: git-send-email 1.7.5.4
\r
40 In-Reply-To: <cover.1321223343.git.jani@nikula.org>
\r
41 References: <cover.1321223343.git.jani@nikula.org>
\r
42 In-Reply-To: <cover.1321223343.git.jani@nikula.org>
\r
43 References: <cover.1321223343.git.jani@nikula.org>
\r
44 X-BeenThere: notmuch@notmuchmail.org
\r
45 X-Mailman-Version: 2.1.13
\r
47 List-Id: "Use and development of the notmuch mail system."
\r
48 <notmuch.notmuchmail.org>
\r
49 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
50 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
51 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
52 List-Post: <mailto:notmuch@notmuchmail.org>
\r
53 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
54 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
55 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
56 X-List-Received-Date: Sun, 13 Nov 2011 22:47:43 -0000
\r
58 Signed-off-by: Jani Nikula <jani@nikula.org>
\r
60 notmuch-search.c | 90 ++++++++++++++++++++++++++++-------------------------
\r
61 1 files changed, 48 insertions(+), 42 deletions(-)
\r
63 diff --git a/notmuch-search.c b/notmuch-search.c
\r
64 index c62a594..4f7384a 100644
\r
65 --- a/notmuch-search.c
\r
66 +++ b/notmuch-search.c
\r
67 @@ -417,81 +417,87 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
\r
68 notmuch_database_t *notmuch;
\r
69 notmuch_query_t *query;
\r
72 notmuch_sort_t sort = NOTMUCH_SORT_NEWEST_FIRST;
\r
73 const search_format_t *format = &format_text;
\r
76 output_t output = OUTPUT_SUMMARY;
\r
77 int maxitems = -1; /* unlimited */
\r
80 - argc--; argv++; /* skip subcommand argument */
\r
82 - for (i = 0; i < argc && argv[i][0] == '-'; i++) {
\r
83 - if (strcmp (argv[i], "--") == 0) {
\r
88 + static struct option options[] = {
\r
89 + { "sort", required_argument, NULL, 0 },
\r
90 + { "first", required_argument, NULL, 1 },
\r
91 + { "maxitems", required_argument, NULL, 2 },
\r
92 + { "format", required_argument, NULL, 3 },
\r
93 + { "output", required_argument, NULL, 4 },
\r
94 + { NULL, 0, NULL, 0 },
\r
97 + opt = getopt_long (argc, argv, "", options, NULL);
\r
101 - if (STRNCMP_LITERAL (argv[i], "--sort=") == 0) {
\r
102 - opt = argv[i] + sizeof ("--sort=") - 1;
\r
103 - if (strcmp (opt, "oldest-first") == 0) {
\r
107 + if (strcmp (optarg, "oldest-first") == 0) {
\r
108 sort = NOTMUCH_SORT_OLDEST_FIRST;
\r
109 - } else if (strcmp (opt, "newest-first") == 0) {
\r
110 + } else if (strcmp (optarg, "newest-first") == 0) {
\r
111 sort = NOTMUCH_SORT_NEWEST_FIRST;
\r
113 - fprintf (stderr, "Invalid value for --sort: %s\n", opt);
\r
114 + fprintf (stderr, "Invalid value for --sort: %s\n", optarg);
\r
117 - } else if (STRNCMP_LITERAL (argv[i], "--first=") == 0) {
\r
119 - opt = argv[i] + sizeof ("--first=") - 1;
\r
120 - first = strtol (opt, &p, 10);
\r
121 - if (*opt == '\0' || p == opt || *p != '\0') {
\r
122 - fprintf (stderr, "Invalid value for --first: %s\n", opt);
\r
125 + first = strtol (optarg, &p, 10);
\r
126 + if (*optarg == '\0' || p == optarg || *p != '\0') {
\r
127 + fprintf (stderr, "Invalid value for --first: %s\n", optarg);
\r
130 - } else if (STRNCMP_LITERAL (argv[i], "--maxitems=") == 0) {
\r
132 - opt = argv[i] + sizeof ("--maxitems=") - 1;
\r
133 - maxitems = strtoul (opt, &p, 10);
\r
134 - if (*opt == '\0' || p == opt || *p != '\0') {
\r
135 - fprintf (stderr, "Invalid value for --maxitems: %s\n", opt);
\r
138 + maxitems = strtoul (optarg, &p, 10);
\r
139 + if (*optarg == '\0' || p == optarg || *p != '\0') {
\r
140 + fprintf (stderr, "Invalid value for --maxitems: %s\n", optarg);
\r
143 - } else if (STRNCMP_LITERAL (argv[i], "--format=") == 0) {
\r
144 - opt = argv[i] + sizeof ("--format=") - 1;
\r
145 - if (strcmp (opt, "text") == 0) {
\r
148 + if (strcmp (optarg, "text") == 0) {
\r
149 format = &format_text;
\r
150 - } else if (strcmp (opt, "json") == 0) {
\r
151 + } else if (strcmp (optarg, "json") == 0) {
\r
152 format = &format_json;
\r
154 - fprintf (stderr, "Invalid value for --format: %s\n", opt);
\r
155 + fprintf (stderr, "Invalid value for --format: %s\n", optarg);
\r
158 - } else if (STRNCMP_LITERAL (argv[i], "--output=") == 0) {
\r
159 - opt = argv[i] + sizeof ("--output=") - 1;
\r
160 - if (strcmp (opt, "summary") == 0) {
\r
163 + if (strcmp (optarg, "summary") == 0) {
\r
164 output = OUTPUT_SUMMARY;
\r
165 - } else if (strcmp (opt, "threads") == 0) {
\r
166 + } else if (strcmp (optarg, "threads") == 0) {
\r
167 output = OUTPUT_THREADS;
\r
168 - } else if (strcmp (opt, "messages") == 0) {
\r
169 + } else if (strcmp (optarg, "messages") == 0) {
\r
170 output = OUTPUT_MESSAGES;
\r
171 - } else if (strcmp (opt, "files") == 0) {
\r
172 + } else if (strcmp (optarg, "files") == 0) {
\r
173 output = OUTPUT_FILES;
\r
174 - } else if (strcmp (opt, "tags") == 0) {
\r
175 + } else if (strcmp (optarg, "tags") == 0) {
\r
176 output = OUTPUT_TAGS;
\r
178 - fprintf (stderr, "Invalid value for --output: %s\n", opt);
\r
179 + fprintf (stderr, "Invalid value for --output: %s\n", optarg);
\r
183 - fprintf (stderr, "Unrecognized option: %s\n", argv[i]);
\r
195 config = notmuch_config_open (ctx, NULL, NULL);
\r
196 if (config == NULL)
\r