Skip to content

Commit 6a316be

Browse files
Perdugitster
authored andcommitted
git-remote-mediawiki: put long code into a subroutine
Signed-off-by: Célestin Matte <[email protected]> Signed-off-by: Matthieu Moy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 42e9192 commit 6a316be

File tree

1 file changed

+32
-24
lines changed

1 file changed

+32
-24
lines changed

contrib/mw-to-git/git-remote-mediawiki.perl

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -122,32 +122,10 @@
122122
$wiki_name =~ s/^.*@//;
123123

124124
# Commands parser
125-
my @cmd;
126125
while (<STDIN>) {
127126
chomp;
128-
@cmd = split(/ /);
129-
if (defined($cmd[0])) {
130-
# Line not blank
131-
if ($cmd[0] eq "capabilities") {
132-
die("Too many arguments for capabilities\n") if (defined($cmd[1]));
133-
mw_capabilities();
134-
} elsif ($cmd[0] eq "list") {
135-
die("Too many arguments for list\n") if (defined($cmd[2]));
136-
mw_list($cmd[1]);
137-
} elsif ($cmd[0] eq "import") {
138-
die("Invalid arguments for import\n") if ($cmd[1] eq "" || defined($cmd[2]));
139-
mw_import($cmd[1]);
140-
} elsif ($cmd[0] eq "option") {
141-
die("Too many arguments for option\n") if ($cmd[1] eq "" || $cmd[2] eq "" || defined($cmd[3]));
142-
mw_option($cmd[1],$cmd[2]);
143-
} elsif ($cmd[0] eq "push") {
144-
mw_push($cmd[1]);
145-
} else {
146-
print STDERR "Unknown command. Aborting...\n";
147-
last;
148-
}
149-
} else {
150-
# blank line: we should terminate
127+
128+
if (!parse_command($_)) {
151129
last;
152130
}
153131

@@ -157,6 +135,36 @@
157135

158136
########################## Functions ##############################
159137

138+
sub parse_command {
139+
my ($line) = @_;
140+
my @cmd = split(/ /, $line);
141+
if (!defined $cmd[0]) {
142+
return 0;
143+
}
144+
if ($cmd[0] eq "capabilities") {
145+
die("Too many arguments for capabilities\n")
146+
if (defined($cmd[1]));
147+
mw_capabilities();
148+
} elsif ($cmd[0] eq "list") {
149+
die("Too many arguments for list\n") if (defined($cmd[2]));
150+
mw_list($cmd[1]);
151+
} elsif ($cmd[0] eq "import") {
152+
die("Invalid arguments for import\n")
153+
if ($cmd[1] eq "" || defined($cmd[2]));
154+
mw_import($cmd[1]);
155+
} elsif ($cmd[0] eq "option") {
156+
die("Too many arguments for option\n")
157+
if ($cmd[1] eq "" || $cmd[2] eq "" || defined($cmd[3]));
158+
mw_option($cmd[1],$cmd[2]);
159+
} elsif ($cmd[0] eq "push") {
160+
mw_push($cmd[1]);
161+
} else {
162+
print STDERR "Unknown command. Aborting...\n";
163+
return 0;
164+
}
165+
return 1;
166+
}
167+
160168
# MediaWiki API instance, created lazily.
161169
my $mediawiki;
162170

0 commit comments

Comments
 (0)