From: Michele Ballabio <barra_cuda@katamail.com>
To: git@vger.kernel.org
Cc: gitster@pobox.com
Subject: [PATCH 9/9] builtin-mailinfo.c: use parse_options()
Date: Wed, 23 Jul 2008 23:42:12 +0200 [thread overview]
Message-ID: <1216849332-26813-10-git-send-email-barra_cuda@katamail.com> (raw)
In-Reply-To: <1216849332-26813-1-git-send-email-barra_cuda@katamail.com>
Signed-off-by: Michele Ballabio <barra_cuda@katamail.com>
---
builtin-mailinfo.c | 39 +++++++++++++++++++++------------------
1 files changed, 21 insertions(+), 18 deletions(-)
diff --git a/builtin-mailinfo.c b/builtin-mailinfo.c
index f974b9d..f1ed269 100644
--- a/builtin-mailinfo.c
+++ b/builtin-mailinfo.c
@@ -6,6 +6,7 @@
#include "builtin.h"
#include "utf8.h"
#include "strbuf.h"
+#include "parse-options.h"
static FILE *cmitmsg, *patchfile, *fin, *fout;
@@ -905,8 +906,10 @@ static int mailinfo(FILE *in, FILE *out, int ks, const char *encoding,
return 0;
}
-static const char mailinfo_usage[] =
- "git mailinfo [-k] [-u | --encoding=<encoding> | -n] msg patch <mail >info";
+static const char * const mailinfo_usage[] = {
+ "git mailinfo [-k] [-u | --encoding=<encoding> | -n] msg patch <mail >info",
+ NULL
+};
int cmd_mailinfo(int argc, const char **argv, const char *prefix)
{
@@ -920,22 +923,22 @@ int cmd_mailinfo(int argc, const char **argv, const char *prefix)
def_charset = (git_commit_encoding ? git_commit_encoding : "utf-8");
metainfo_charset = def_charset;
- while (1 < argc && argv[1][0] == '-') {
- if (!strcmp(argv[1], "-k"))
- keep_subject = 1;
- else if (!strcmp(argv[1], "-u"))
- metainfo_charset = def_charset;
- else if (!strcmp(argv[1], "-n"))
- metainfo_charset = NULL;
- else if (!prefixcmp(argv[1], "--encoding="))
- metainfo_charset = argv[1] + 11;
- else
- usage(mailinfo_usage);
- argc--; argv++;
- }
+ const struct option options[] = {
+ OPT_BOOLEAN('k', NULL, &keep_subject,
+ "keep subject, don't clean it up"),
+ OPT_SET_PTR('u', NULL, &metainfo_charset,
+ "re-code in UTF-8", (intptr_t)def_charset),
+ OPT_SET_PTR('n', NULL, &metainfo_charset,
+ "disable re-coding", (intptr_t)NULL),
+ OPT_STRING(0, "encoding", &metainfo_charset,
+ "encoding", "override default encoding"),
+ OPT_END()
+ };
+
+ argc = parse_options(argc, argv, options, mailinfo_usage, 0);
- if (argc != 3)
- usage(mailinfo_usage);
+ if (argc != 2)
+ usage_with_options(mailinfo_usage, options);
- return !!mailinfo(stdin, stdout, keep_subject, metainfo_charset, argv[1], argv[2]);
+ return !!mailinfo(stdin, stdout, keep_subject, metainfo_charset, argv[0], argv[1]);
}
--
1.5.6.3
prev parent reply other threads:[~2008-07-23 21:37 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-23 21:42 [PATCH 0/9] Extend use of parse_options() Michele Ballabio
2008-07-23 21:42 ` [PATCH 1/9] builtin-verify-tag.c: use parse_options() Michele Ballabio
2008-07-24 16:59 ` Olivier Marin
2008-07-24 17:08 ` Johannes Schindelin
2008-07-25 15:20 ` Olivier Marin
2008-07-26 0:53 ` Johannes Schindelin
2008-07-28 10:48 ` [PATCH] builtin-verify-tag: fix -v option parsing Olivier Marin
2008-07-28 11:06 ` Johannes Schindelin
2008-07-28 11:42 ` Olivier Marin
2008-07-28 12:10 ` Johannes Schindelin
2008-07-23 21:42 ` [PATCH 2/9] builtin-write-tree.c: use parse_options() Michele Ballabio
2008-07-23 21:42 ` [PATCH 3/9] builtin-prune-packed.c: " Michele Ballabio
2008-07-23 21:42 ` [PATCH 4/9] builtin-ls-tree.c: " Michele Ballabio
2008-07-23 21:42 ` [PATCH 5/9] builtin-rev-list.c: " Michele Ballabio
2008-07-23 21:42 ` [PATCH 6/9] builtin-init-db.c: " Michele Ballabio
2008-07-24 16:15 ` Olivier Marin
2008-07-24 17:07 ` Johannes Schindelin
2008-07-25 15:20 ` Olivier Marin
2008-07-26 0:55 ` Johannes Schindelin
2008-07-24 20:07 ` Michele Ballabio
2008-07-25 8:15 ` [PATCH 6/9 - v2] " Michele Ballabio
2008-07-25 15:20 ` [PATCH 6/9] " Olivier Marin
2008-07-25 19:53 ` [PATCH 6/9 - v3] " Michele Ballabio
2008-07-23 21:42 ` [PATCH 7/9] builtin-checkout-index.c: " Michele Ballabio
2008-07-24 14:44 ` Johannes Schindelin
2008-07-24 20:08 ` Michele Ballabio
2008-07-24 20:35 ` Sverre Rabbelier
2008-07-25 9:01 ` René Scharfe
2008-07-25 16:25 ` [PATCH 7/9 - v2] " Michele Ballabio
2008-07-23 21:42 ` [PATCH 8/9] builtin-fetch-pack.c: " Michele Ballabio
2008-07-23 21:42 ` Michele Ballabio [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1216849332-26813-10-git-send-email-barra_cuda@katamail.com \
--to=barra_cuda@katamail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).