Skip to content

Commit f1a3529

Browse files
ockhamgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f745acb commit f1a3529

File tree

2 files changed

+31
-11
lines changed

2 files changed

+31
-11
lines changed

Documentation/git-imap-send.txt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ git-imap-send - Send a collection of patches from stdin to an IMAP folder
99
SYNOPSIS
1010
--------
1111
[verse]
12-
'git imap-send'
12+
'git imap-send' [-v] [-q]
1313

1414

1515
DESCRIPTION
@@ -26,6 +26,18 @@ Typical usage is something like:
2626
git format-patch --signoff --stdout --attach origin | git imap-send
2727

2828

29+
OPTIONS
30+
-------
31+
32+
-v::
33+
--verbose::
34+
Be verbose.
35+
36+
-q::
37+
--quiet::
38+
Be quiet.
39+
40+
2941
CONFIGURATION
3042
-------------
3143

imap-send.c

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,26 @@
2626
#include "credential.h"
2727
#include "exec_cmd.h"
2828
#include "run-command.h"
29+
#include "parse-options.h"
2930
#ifdef NO_OPENSSL
3031
typedef void *SSL;
3132
#endif
3233

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+
};
3442

3543
#undef DRV_OK
3644
#define DRV_OK 0
3745
#define DRV_MSG_BAD -1
3846
#define DRV_BOX_BAD -2
3947
#define DRV_STORE_BAD -3
4048

41-
static int Verbose, Quiet;
42-
4349
__attribute__((format (printf, 1, 2)))
4450
static void imap_info(const char *, ...);
4551
__attribute__((format (printf, 1, 2)))
@@ -418,7 +424,7 @@ static int buffer_gets(struct imap_buffer *b, char **s)
418424
if (b->buf[b->offset + 1] == '\n') {
419425
b->buf[b->offset] = 0; /* terminate the string */
420426
b->offset += 2; /* next line */
421-
if (Verbose)
427+
if (0 < verbosity)
422428
puts(*s);
423429
return 0;
424430
}
@@ -433,7 +439,7 @@ static void imap_info(const char *msg, ...)
433439
{
434440
va_list va;
435441

436-
if (!Quiet) {
442+
if (0 <= verbosity) {
437443
va_start(va, msg);
438444
vprintf(msg, va);
439445
va_end(va);
@@ -445,7 +451,7 @@ static void imap_warn(const char *msg, ...)
445451
{
446452
va_list va;
447453

448-
if (Quiet < 2) {
454+
if (-2 < verbosity) {
449455
va_start(va, msg);
450456
vfprintf(stderr, msg, va);
451457
va_end(va);
@@ -522,7 +528,7 @@ static struct imap_cmd *issue_imap_cmd(struct imap_store *ctx,
522528
cmd->tag, cmd->cmd, cmd->cb.dlen,
523529
CAP(LITERALPLUS) ? "+" : "");
524530

525-
if (Verbose) {
531+
if (0 < verbosity) {
526532
if (imap->num_in_progress)
527533
printf("(%d in progress) ", imap->num_in_progress);
528534
if (!starts_with(cmd->cmd, "LOGIN"))
@@ -1352,12 +1358,14 @@ int main(int argc, char **argv)
13521358

13531359
git_setup_gettext();
13541360

1355-
if (argc != 1)
1356-
usage(imap_send_usage);
1357-
13581361
setup_git_directory_gently(&nongit_ok);
13591362
git_imap_config();
13601363

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+
13611369
if (!server.port)
13621370
server.port = server.use_ssl ? 993 : 143;
13631371

0 commit comments

Comments
 (0)