git-remote-mediawiki: add git-mw command
[git] / contrib / mw-to-git / git-mw.perl
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 }