Skip to content

Commit 07a263b

Browse files
Benoit Persongitster
authored andcommitted
git-remote-mediawiki: add git-mw command
For now, git-remote-mediawiki is only a remote-helper. This patch adds a new toolset script in which we will be able to build new tools for git-remote-mediawiki. This toolset uses a subcommand-mechanism to launch the proper action. For now only the 'help' subcommand is implemented. It also provides some generic code for the verbose and help command line options. Signed-off-by: Benoit Person <[email protected]> Signed-off-by: Matthieu Moy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 192f7a0 commit 07a263b

File tree

2 files changed

+64
-3
lines changed

2 files changed

+64
-3
lines changed

contrib/mw-to-git/Makefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
GIT_MEDIAWIKI_PM=Git/Mediawiki.pm
1616
SCRIPT_PERL=git-remote-mediawiki.perl
17+
SCRIPT_PERL+=git-mw.perl
1718
GIT_ROOT_DIR=../..
1819
HERE=contrib/mw-to-git/
1920

@@ -27,15 +28,15 @@ install_pm:
2728
install $(GIT_MEDIAWIKI_PM) $(INSTLIBDIR)/$(GIT_MEDIAWIKI_PM)
2829

2930
build:
30-
$(MAKE) -C $(GIT_ROOT_DIR) SCRIPT_PERL=$(SCRIPT_PERL_FULL) \
31+
$(MAKE) -C $(GIT_ROOT_DIR) SCRIPT_PERL="$(SCRIPT_PERL_FULL)" \
3132
build-perl-script
3233

3334
install: install_pm
34-
$(MAKE) -C $(GIT_ROOT_DIR) SCRIPT_PERL=$(SCRIPT_PERL_FULL) \
35+
$(MAKE) -C $(GIT_ROOT_DIR) SCRIPT_PERL="$(SCRIPT_PERL_FULL)" \
3536
install-perl-script
3637

3738
clean:
38-
$(MAKE) -C $(GIT_ROOT_DIR) SCRIPT_PERL=$(SCRIPT_PERL_FULL) \
39+
$(MAKE) -C $(GIT_ROOT_DIR) SCRIPT_PERL="$(SCRIPT_PERL_FULL)" \
3940
clean-perl-script
4041
rm $(INSTLIBDIR)/$(GIT_MEDIAWIKI_PM)
4142

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

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/perl
2+
3+
# Copyright (C) 2013
4+
# Benoit Person <[email protected]>
5+
# Celestin Matte <[email protected]>
6+
# License: GPL v2 or later
7+
8+
# Set of tools for git repo with a mediawiki remote.
9+
# Documentation & bugtracker: https://github.com/moy/Git-Mediawiki/
10+
11+
use strict;
12+
use warnings;
13+
14+
use Getopt::Long;
15+
16+
# By default, use UTF-8 to communicate with Git and the user
17+
binmode STDERR, ':encoding(UTF-8)';
18+
binmode STDOUT, ':encoding(UTF-8)';
19+
20+
# Global parameters
21+
my $verbose = 0;
22+
sub v_print {
23+
if ($verbose) {
24+
return print {*STDERR} @_;
25+
}
26+
return;
27+
}
28+
29+
my %commands = (
30+
'help' =>
31+
[\&help, {}, \&help]
32+
);
33+
34+
# Search for sub-command
35+
my $cmd = $commands{'help'};
36+
for (0..@ARGV-1) {
37+
if (defined $commands{$ARGV[$_]}) {
38+
$cmd = $commands{$ARGV[$_]};
39+
splice @ARGV, $_, 1;
40+
last;
41+
}
42+
};
43+
GetOptions( %{$cmd->[1]},
44+
'help|h' => \&{$cmd->[2]},
45+
'verbose|v' => \$verbose);
46+
47+
# Launch command
48+
&{$cmd->[0]};
49+
50+
############################## Help Functions ##################################
51+
52+
sub help {
53+
print {*STDOUT} <<'END';
54+
usage: git mw <command> <args>
55+
56+
git mw commands are:
57+
help Display help information about git mw
58+
END
59+
exit;
60+
}

0 commit comments

Comments
 (0)