summaryrefslogtreecommitdiff
path: root/imap-send.c
diff options
context:
space:
mode:
authorBernhard Reiter <ockham@raz.or.at>2014-11-05 14:29:21 (GMT)
committerJunio C Hamano <gitster@pobox.com>2014-11-06 00:24:27 (GMT)
commitf1a35295c2b66d2501f034d864afb2c5d8bb0e08 (patch)
treee958702317fb98c74640d6e000909cd766e0e596 /imap-send.c
parentf745acb028ee8f7dcd1c8f10127b8feeaa255cf7 (diff)
downloadgit-f1a35295c2b66d2501f034d864afb2c5d8bb0e08.zip
git-f1a35295c2b66d2501f034d864afb2c5d8bb0e08.tar.gz
git-f1a35295c2b66d2501f034d864afb2c5d8bb0e08.tar.bz2
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>
Diffstat (limited to 'imap-send.c')
-rw-r--r--imap-send.c28
1 files changed, 18 insertions, 10 deletions
diff --git a/imap-send.c b/imap-send.c
index 70bcc7a..7f9d30e 100644
--- a/imap-send.c
+++ b/imap-send.c
@@ -26,11 +26,19 @@
#include "credential.h"
#include "exec_cmd.h"
#include "run-command.h"
+#include "parse-options.h"
#ifdef NO_OPENSSL
typedef void *SSL;
#endif
-static const char imap_send_usage[] = "git imap-send < <mbox>";
+static int verbosity;
+
+static const char * const imap_send_usage[] = { "git imap-send [-v] [-q] < <mbox>", NULL };
+
+static struct option imap_send_options[] = {
+ OPT__VERBOSITY(&verbosity),
+ OPT_END()
+};
#undef DRV_OK
#define DRV_OK 0
@@ -38,8 +46,6 @@ static const char imap_send_usage[] = "git imap-send < <mbox>";
#define DRV_BOX_BAD -2
#define DRV_STORE_BAD -3
-static int Verbose, Quiet;
-
__attribute__((format (printf, 1, 2)))
static void imap_info(const char *, ...);
__attribute__((format (printf, 1, 2)))
@@ -418,7 +424,7 @@ static int buffer_gets(struct imap_buffer *b, char **s)
if (b->buf[b->offset + 1] == '\n') {
b->buf[b->offset] = 0; /* terminate the string */
b->offset += 2; /* next line */
- if (Verbose)
+ if (0 < verbosity)
puts(*s);
return 0;
}
@@ -433,7 +439,7 @@ static void imap_info(const char *msg, ...)
{
va_list va;
- if (!Quiet) {
+ if (0 <= verbosity) {
va_start(va, msg);
vprintf(msg, va);
va_end(va);
@@ -445,7 +451,7 @@ static void imap_warn(const char *msg, ...)
{
va_list va;
- if (Quiet < 2) {
+ if (-2 < verbosity) {
va_start(va, msg);
vfprintf(stderr, msg, va);
va_end(va);
@@ -522,7 +528,7 @@ static struct imap_cmd *issue_imap_cmd(struct imap_store *ctx,
cmd->tag, cmd->cmd, cmd->cb.dlen,
CAP(LITERALPLUS) ? "+" : "");
- if (Verbose) {
+ if (0 < verbosity) {
if (imap->num_in_progress)
printf("(%d in progress) ", imap->num_in_progress);
if (!starts_with(cmd->cmd, "LOGIN"))
@@ -1352,12 +1358,14 @@ int main(int argc, char **argv)
git_setup_gettext();
- if (argc != 1)
- usage(imap_send_usage);
-
setup_git_directory_gently(&nongit_ok);
git_imap_config();
+ argc = parse_options(argc, (const char **)argv, "", imap_send_options, imap_send_usage, 0);
+
+ if (argc)
+ usage_with_options(imap_send_usage, imap_send_options);
+
if (!server.port)
server.port = server.use_ssl ? 993 : 143;