Make builtin-rm.c use parse_options.
Signed-off-by: Pierre Habouzit <madcoder@debian.org> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Pierre Habouzit committed
Oct 5, 2007 at 21:09 UTC
f09985c265f8ea2195a6d6c3e151813e6890dd7d
1 file changed
+23
-31
builtin-rm.c
+23
-31
@@ -8,9 +8,12 @@
8
#include "dir.h"
9
#include "cache-tree.h"
10
#include "tree-walk.h"
11
+#include "parse-options.h"
12
12
-static const char builtin_rm_usage[] =
13
-"git-rm [-f] [-n] [-r] [--cached] [--ignore-unmatch] [--quiet] [--] <file>...";
13
+static const char * const builtin_rm_usage[] = {
14
+ "git-rm [options] [--] <file>...",
15
+ NULL
16
+};
17
18
static struct {
19
int nr, alloc;
@@ -121,11 +124,23 @@ static int check_local_mod(unsigned char *head, int index_only)
124
125
static struct lock_file lock_file;
126
127
+static int show_only = 0, force = 0, index_only = 0, recursive = 0, quiet = 0;
128
+static int ignore_unmatch = 0;
129
+
130
+static struct option builtin_rm_options[] = {
131
+ OPT__DRY_RUN(&show_only),
132
+ OPT__QUIET(&quiet),
133
+ OPT_BOOLEAN( 0 , "cached", &index_only, "only remove from the index"),
134
+ OPT_BOOLEAN('f', NULL, &force, "override the up-to-date check"),
135
+ OPT_BOOLEAN('r', NULL, &recursive, "allow recursive removal"),
136
+ OPT_BOOLEAN( 0 , "ignore-unmatch", &ignore_unmatch,
137
+ "exit with a zero status even if nothing matched"),
138
+ OPT_END(),
139
+};
140
+
141
int cmd_rm(int argc, const char **argv, const char *prefix)
142
{
143
int i, newfd;
127
- int show_only = 0, force = 0, index_only = 0, recursive = 0, quiet = 0;
128
- int ignore_unmatch = 0;
144
const char **pathspec;
145
char *seen;
146
@@ -136,34 +151,11 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
151
if (read_cache() < 0)
152
die("index file corrupt");
153
139
- for (i = 1 ; i < argc ; i++) {
140
- const char *arg = argv[i];
141
-
142
- if (*arg != '-')
143
- break;
144
- else if (!strcmp(arg, "--")) {
145
- i++;
146
- break;
147
- }
148
- else if (!strcmp(arg, "-n"))
149
- show_only = 1;
150
- else if (!strcmp(arg, "--cached"))
151
- index_only = 1;
152
- else if (!strcmp(arg, "-f"))
153
- force = 1;
154
- else if (!strcmp(arg, "-r"))
155
- recursive = 1;
156
- else if (!strcmp(arg, "--quiet"))
157
- quiet = 1;
158
- else if (!strcmp(arg, "--ignore-unmatch"))
159
- ignore_unmatch = 1;
160
- else
161
- usage(builtin_rm_usage);
162
- }
163
- if (argc <= i)
164
- usage(builtin_rm_usage);
154
+ argc = parse_options(argc, argv, builtin_rm_options, builtin_rm_usage, 0);
155
+ if (!argc)
156
+ usage_with_options(builtin_rm_usage, builtin_rm_options);
157
166
- pathspec = get_pathspec(prefix, argv + i);
158
+ pathspec = get_pathspec(prefix, argv);
159
seen = NULL;
160
for (i = 0; pathspec[i] ; i++)
161
/* nothing */;