imap-send: use parse options API to determine verbosity

The -v/-q options were sort-of supported but without using the parse-options API, and were not documented. Signed-off-by: Bernhard Reiter <ockham@raz.or.at> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Bernhard Reiter committed Nov 5, 2014 at 15:29 UTC f1a35295c2b66d2501f034d864afb2c5d8bb0e08
2 files changed +31 -11
Documentation/git-imap-send.txt
+13 -1
@@ -9,7 +9,7 @@ git-imap-send - Send a collection of patches from stdin to an IMAP folder
9 SYNOPSIS
10 --------
11 [verse]
12 -'git imap-send'
12 +'git imap-send' [-v] [-q]
13
14
15 DESCRIPTION
@@ -26,6 +26,18 @@ Typical usage is something like:
26 git format-patch --signoff --stdout --attach origin | git imap-send
27
28
29 +OPTIONS
30 +-------
31 +
32 +-v::
33 +--verbose::
34 + Be verbose.
35 +
36 +-q::
37 +--quiet::
38 + Be quiet.
39 +
40 +
41 CONFIGURATION
42 -------------
43
imap-send.c
+18 -10
@@ -26,11 +26,19 @@
26 #include "credential.h"
27 #include "exec_cmd.h"
28 #include "run-command.h"
29 +#include "parse-options.h"
30 #ifdef NO_OPENSSL
31 typedef void *SSL;
32 #endif
33
33 -static const char imap_send_usage[] = "git imap-send < <mbox>";
34 +static int verbosity;
35 +
36 +static const char * const imap_send_usage[] = { "git imap-send [-v] [-q] < <mbox>", NULL };
37 +
38 +static struct option imap_send_options[] = {
39 + OPT__VERBOSITY(&verbosity),
40 + OPT_END()
41 +};
42
43 #undef DRV_OK
44 #define DRV_OK 0
@@ -38,8 +46,6 @@ static const char imap_send_usage[] = "git imap-send < <mbox>";
46 #define DRV_BOX_BAD -2
47 #define DRV_STORE_BAD -3
48
41 -static int Verbose, Quiet;
42 -
49 __attribute__((format (printf, 1, 2)))
50 static void imap_info(const char *, ...);
51 __attribute__((format (printf, 1, 2)))
@@ -418,7 +424,7 @@ static int buffer_gets(struct imap_buffer *b, char **s)
424 if (b->buf[b->offset + 1] == '\n') {
425 b->buf[b->offset] = 0; /* terminate the string */
426 b->offset += 2; /* next line */
421 - if (Verbose)
427 + if (0 < verbosity)
428 puts(*s);
429 return 0;
430 }
@@ -433,7 +439,7 @@ static void imap_info(const char *msg, ...)
439 {
440 va_list va;
441
436 - if (!Quiet) {
442 + if (0 <= verbosity) {
443 va_start(va, msg);
444 vprintf(msg, va);
445 va_end(va);
@@ -445,7 +451,7 @@ static void imap_warn(const char *msg, ...)
451 {
452 va_list va;
453
448 - if (Quiet < 2) {
454 + if (-2 < verbosity) {
455 va_start(va, msg);
456 vfprintf(stderr, msg, va);
457 va_end(va);
@@ -522,7 +528,7 @@ static struct imap_cmd *issue_imap_cmd(struct imap_store *ctx,
528 cmd->tag, cmd->cmd, cmd->cb.dlen,
529 CAP(LITERALPLUS) ? "+" : "");
530
525 - if (Verbose) {
531 + if (0 < verbosity) {
532 if (imap->num_in_progress)
533 printf("(%d in progress) ", imap->num_in_progress);
534 if (!starts_with(cmd->cmd, "LOGIN"))
@@ -1352,12 +1358,14 @@ int main(int argc, char **argv)
1358
1359 git_setup_gettext();
1360
1355 - if (argc != 1)
1356 - usage(imap_send_usage);
1357 -
1361 setup_git_directory_gently(&nongit_ok);
1362 git_imap_config();
1363
1364 + argc = parse_options(argc, (const char **)argv, "", imap_send_options, imap_send_usage, 0);
1365 +
1366 + if (argc)
1367 + usage_with_options(imap_send_usage, imap_send_options);
1368 +
1369 if (!server.port)
1370 server.port = server.use_ssl ? 993 : 143;
1371