4a3e4a94141caaca7431c7380705ff2189c2d0f9
   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
  11use strict;
  12use warnings;
  13
  14use Getopt::Long;
  15
  16# By default, use UTF-8 to communicate with Git and the user
  17binmode STDERR, ':encoding(UTF-8)';
  18binmode STDOUT, ':encoding(UTF-8)';
  19
  20# Global parameters
  21my $verbose = 0;
  22sub v_print {
  23        if ($verbose) {
  24                return print {*STDERR} @_;
  25        }
  26        return;
  27}
  28
  29my %commands = (
  30        'help' =>
  31                [\&help, {}, \&help]
  32);
  33
  34# Search for sub-command
  35my $cmd = $commands{'help'};
  36for (0..@ARGV-1) {
  37        if (defined $commands{$ARGV[$_]}) {
  38                $cmd = $commands{$ARGV[$_]};
  39                splice @ARGV, $_, 1;
  40                last;
  41        }
  42};
  43GetOptions( %{$cmd->[1]},
  44        'help|h' => \&{$cmd->[2]},
  45        'verbose|v'  => \$verbose);
  46
  47# Launch command
  48&{$cmd->[0]};
  49
  50############################## Help Functions ##################################
  51
  52sub help {
  53        print {*STDOUT} <<'END';
  54usage: git mw <command> <args>
  55
  56git mw commands are:
  57    help        Display help information about git mw
  58END
  59        exit;
  60}