[PATCH] Make builtin-symbolic-ref.c use parse_options.

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: <git@...>, Junio C Hamano <gitster@...>
Cc: Pierre Habouzit <madcoder@...>, <git@...>
Date: Saturday, October 13, 2007 - 9:29 am

Signed-off-by: Pierre Habouzit <madcoder@debian.org>
---
 builtin-symbolic-ref.c |   54 +++++++++++++++++------------------------------
 1 files changed, 20 insertions(+), 34 deletions(-)

diff --git a/builtin-symbolic-ref.c b/builtin-symbolic-ref.c
index 9eb95e5..c5e5173 100644
--- a/builtin-symbolic-ref.c
+++ b/builtin-symbolic-ref.c
@@ -1,9 +1,12 @@
 #include "builtin.h"
 #include "cache.h"
 #include "refs.h"
+#include "parse-options.h"
 
-static const char git_symbolic_ref_usage[] =
-"git-symbolic-ref [-q] [-m <reason>] name [ref]";
+static const char * const git_symbolic_ref_usage[] = {
+	"git-symbolic-ref [options] name [ref]",
+	NULL
+};
 
 static void check_symref(const char *HEAD, int quiet)
 {
@@ -26,44 +29,27 @@ int cmd_symbolic_ref(int argc, const char **argv, const char *prefix)
 {
 	int quiet = 0;
 	const char *msg = NULL;
+	struct option git_symbolic_ref_options[] = {
+		OPT_BOOLEAN('q', "quiet", &quiet, "do not issue errors"),
+		OPT_STRING( 'm', NULL, &msg, "reason", "reason of the update"),
+	};
 
 	git_config(git_default_config);
-
-	while (1 < argc) {
-		const char *arg = argv[1];
-		if (arg[0] != '-')
-			break;
-		else if (!strcmp("-q", arg))
-			quiet = 1;
-		else if (!strcmp("-m", arg)) {
-			argc--;
-			argv++;
-			if (argc <= 1)
-				break;
-			msg = argv[1];
-			if (!*msg)
-				die("Refusing to perform update with empty message");
-		}
-		else if (!strcmp("--", arg)) {
-			argc--;
-			argv++;
-			break;
-		}
-		else
-			die("unknown option %s", arg);
-		argc--;
-		argv++;
-	}
-
+	argc = parse_options(argc, argv, git_symbolic_ref_options,
+	                     ARRAY_SIZE(git_symbolic_ref_options),
+	                     git_symbolic_ref_usage, 0);
+	if (msg &&!*msg)
+		die("Refusing to perform update with empty message");
 	switch (argc) {
-	case 2:
-		check_symref(argv[1], quiet);
+	case 1:
+		check_symref(argv[0], quiet);
 		break;
-	case 3:
-		create_symref(argv[1], argv[2], msg);
+	case 2:
+		create_symref(argv[0], argv[1], msg);
 		break;
 	default:
-		usage(git_symbolic_ref_usage);
+		make_usage(git_symbolic_ref_usage, git_symbolic_ref_options,
+		           ARRAY_SIZE(git_symbolic_ref_options));
 	}
 	return 0;
 }
-- 
1.5.3.GIT

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[RFC] CLI option parsing and usage generation for porcelains, Pierre Habouzit, (Sat Oct 13, 9:29 am)
[PATCH] parse-options: Allow abbreviated options when unambi..., Johannes Schindelin, (Sun Oct 14, 12:54 pm)
Re: [PATCH] parse-options: Allow abbreviated options when un..., Johannes Schindelin, (Sun Oct 14, 2:02 pm)
Re: [PATCH] parse-options: Allow abbreviated options when un..., Johannes Schindelin, (Sun Oct 14, 6:12 pm)
git-svn and submodules, was Re: [PATCH] parse-options: Allow..., Johannes Schindelin, (Sun Oct 14, 6:59 pm)
Re: git-svn and submodules, Benoit SIGOURE, (Mon Oct 15, 3:07 am)
Re: git-svn and submodules, Linus Torvalds, (Mon Oct 15, 11:53 am)
Re: git-svn and submodules, Karl , (Mon Oct 15, 10:45 am)
.gitignore and svn:ignore [WAS: git-svn and submodules], Chris Shoemaker, (Mon Oct 15, 11:14 am)
Re: .gitignore and svn:ignore [WAS: git-svn and submodules], Chris Shoemaker, (Tue Oct 16, 9:05 am)
Re: git-svn and submodules, Andreas Ericsson, (Mon Oct 15, 6:00 am)
Re: git-svn and submodules, Benoit SIGOURE, (Mon Oct 15, 6:51 am)
Re: [RFC] CLI option parsing and usage generation for porcel..., Wincent Colaiuta, (Sat Oct 13, 10:53 am)
[PATCH] Add a simple option parser., Pierre Habouzit, (Sat Oct 13, 9:29 am)
Re: [PATCH] Add a simple option parser., Alex Riesen, (Sat Oct 13, 3:16 pm)
Re: [PATCH] Add a simple option parser., Pierre Habouzit, (Sat Oct 13, 4:54 pm)
Re: [PATCH] Add a simple option parser., Alex Riesen, (Sat Oct 13, 6:14 pm)
Re: [PATCH] Add a simple option parser., Pierre Habouzit, (Sun Oct 14, 3:02 am)
Re: [PATCH] Add a simple option parser., Johannes Schindelin, (Sat Oct 13, 10:39 am)
Re: [PATCH] Add a simple option parser., Pierre Habouzit, (Sat Oct 13, 10:58 am)
[PATCH] Port builtin-add.c to use the new option parser., Pierre Habouzit, (Sat Oct 13, 9:29 am)
Re: [PATCH] Port builtin-add.c to use the new option parser., Johannes Schindelin, (Sat Oct 13, 10:47 am)
Re: [PATCH] Port builtin-add.c to use the new option parser., Pierre Habouzit, (Sat Oct 13, 11:03 am)
Re: [PATCH] Port builtin-add.c to use the new option parser., Pierre Habouzit, (Sat Oct 13, 4:27 pm)
[PATCH] Make builtin-rm use parse_options., Pierre Habouzit, (Sat Oct 13, 9:29 am)
[PATCH] Make builtin-mv use parse-options, Pierre Habouzit, (Sat Oct 13, 9:29 am)
[PATCH] Make builtin-branch.c use parse_options., Pierre Habouzit, (Sat Oct 13, 9:29 am)
[PATCH] Make builtin-describe use parse_options, Pierre Habouzit, (Sat Oct 13, 9:29 am)
[PATCH] Make git-fetch use parse_options., Pierre Habouzit, (Sat Oct 13, 9:29 am)
[PATCH] Make builtin-revert.c use parse_options., Pierre Habouzit, (Sat Oct 13, 9:29 am)
[PATCH] Make builtin-update-ref.c use parse_options, Pierre Habouzit, (Sat Oct 13, 9:29 am)
[PATCH] Simplify usage string printing, Jonas Fonseca, (Sun Oct 14, 10:01 am)
Re: [PATCH] Simplify usage string printing, Pierre Habouzit, (Sun Oct 14, 12:26 pm)
[PATCH] Make builtin-symbolic-ref.c use parse_options., Pierre Habouzit, (Sat Oct 13, 9:29 am)
[PATCH] Make builtin-http-fetch use parse_options., Pierre Habouzit, (Sat Oct 13, 9:29 am)