[PATCH] Make builtin-rm 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-rm.c |   56 +++++++++++++++++++++++++-------------------------------
 1 files changed, 25 insertions(+), 31 deletions(-)

diff --git a/builtin-rm.c b/builtin-rm.c
index 3b0677e..74eb23c 100644
--- a/builtin-rm.c
+++ b/builtin-rm.c
@@ -8,9 +8,12 @@
 #include "dir.h"
 #include "cache-tree.h"
 #include "tree-walk.h"
+#include "parse-options.h"
 
-static const char builtin_rm_usage[] =
-"git-rm [-f] [-n] [-r] [--cached] [--ignore-unmatch] [--quiet] [--] <file>...";
+static const char * const builtin_rm_usage[] = {
+	"git-rm [options] [--] <file>...",
+	NULL
+};
 
 static struct {
 	int nr, alloc;
@@ -121,11 +124,22 @@ static int check_local_mod(unsigned char *head, int index_only)
 
 static struct lock_file lock_file;
 
+static int show_only = 0, force = 0, index_only = 0, recursive = 0, quiet = 0;
+static int ignore_unmatch = 0;
+
+static struct option builtin_rm_options[] = {
+	OPT_BOOLEAN('n', NULL,             &show_only,  "dry-run"),
+	OPT_BOOLEAN( 0 , "cached",         &index_only, "only remove from the index"),
+	OPT_BOOLEAN('f', NULL,             &force,      "override the up-to-date check"),
+	OPT_BOOLEAN('r', NULL,             &recursive,  "allow recursive removal"),
+	OPT_BOOLEAN( 0 , "quiet",          &quiet,      "be quiet"),
+	OPT_BOOLEAN( 0 , "ignore-unmatch", &ignore_unmatch,
+				"exit with a zero status even if nothing matched")
+};
+
 int cmd_rm(int argc, const char **argv, const char *prefix)
 {
 	int i, newfd;
-	int show_only = 0, force = 0, index_only = 0, recursive = 0, quiet = 0;
-	int ignore_unmatch = 0;
 	const char **pathspec;
 	char *seen;
 
@@ -136,34 +150,14 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
 	if (read_cache() < 0)
 		die("index file corrupt");
 
-	for (i = 1 ; i < argc ; i++) {
-		const char *arg = argv[i];
-
-		if (*arg != '-')
-			break;
-		else if (!strcmp(arg, "--")) {
-			i++;
-			break;
-		}
-		else if (!strcmp(arg, "-n"))
-			show_only = 1;
-		else if (!strcmp(arg, "--cached"))
-			index_only = 1;
-		else if (!strcmp(arg, "-f"))
-			force = 1;
-		else if (!strcmp(arg, "-r"))
-			recursive = 1;
-		else if (!strcmp(arg, "--quiet"))
-			quiet = 1;
-		else if (!strcmp(arg, "--ignore-unmatch"))
-			ignore_unmatch = 1;
-		else
-			usage(builtin_rm_usage);
-	}
-	if (argc <= i)
-		usage(builtin_rm_usage);
+	i = parse_options(argc, argv, builtin_rm_options,
+	                  ARRAY_SIZE(builtin_rm_options),
+	                  builtin_rm_usage, 0);
+	if (i == 0)
+		make_usage(builtin_rm_usage, builtin_rm_options,
+                   ARRAY_SIZE(builtin_rm_options));
 
-	pathspec = get_pathspec(prefix, argv + i);
+	pathspec = get_pathspec(prefix, argv);
 	seen = NULL;
 	for (i = 0; pathspec[i] ; i++)
 		/* nothing */;
-- 
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)