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 <benoit.person@ensimag.fr> Signed-off-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Benoit Person committed
Jul 4, 2013 at 22:38 UTC
07a263b9056ac7135ed84d64cabf80c5a6b1972e
2 files changed
+64
-3
contrib/mw-to-git/Makefile
+4
-3
@@ -14,6 +14,7 @@
14
15
GIT_MEDIAWIKI_PM=Git/Mediawiki.pm
16
SCRIPT_PERL=git-remote-mediawiki.perl
17
+SCRIPT_PERL+=git-mw.perl
18
GIT_ROOT_DIR=../..
19
HERE=contrib/mw-to-git/
20
@@ -27,15 +28,15 @@ install_pm:
28
install $(GIT_MEDIAWIKI_PM) $(INSTLIBDIR)/$(GIT_MEDIAWIKI_PM)
29
30
build:
30
- $(MAKE) -C $(GIT_ROOT_DIR) SCRIPT_PERL=$(SCRIPT_PERL_FULL) \
31
+ $(MAKE) -C $(GIT_ROOT_DIR) SCRIPT_PERL="$(SCRIPT_PERL_FULL)" \
32
build-perl-script
33
34
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)" \
36
install-perl-script
37
38
clean:
38
- $(MAKE) -C $(GIT_ROOT_DIR) SCRIPT_PERL=$(SCRIPT_PERL_FULL) \
39
+ $(MAKE) -C $(GIT_ROOT_DIR) SCRIPT_PERL="$(SCRIPT_PERL_FULL)" \
40
clean-perl-script
41
rm $(INSTLIBDIR)/$(GIT_MEDIAWIKI_PM)
42
contrib/mw-to-git/git-mw.perl
new
+60
@@ -0,0 +1,60 @@
1
+#!/usr/bin/perl
2
+
3
+# Copyright (C) 2013
4
+# Benoit Person <benoit.person@ensimag.imag.fr>
5
+# Celestin Matte <celestin.matte@ensimag.imag.fr>
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
+}