#!/usr/bin/env perl

use strict;
use warnings;
use 5.014;

use Getopt::Long qw(:config gnu_getopt pass_through);
use App::Multigit qw(mg_each);
use Future;
use curry;

my $workdir;
GetOptions(
    'help|h' => sub {
        say usage();
        exit 0;
    },
    'workdir=s' => \$workdir,
);

chdir $workdir;

my $future = mg_each(sub {
    my ($repo) = @_;
    $repo->run([ qw(git branch), @ARGV ])
        ->finally($repo->curry::report)
});

my %report = $future->get;

for my $repo (sort keys %report) {
    say for $repo, $report{$repo};
}

sub usage {
<<EOU;
Usage:
    mg branch [argv]

    Runs `git branch argv` on each repository. See `git help branch`.

    With no arguments, therefore, this just lists the branches in each
    repository.
EOU
}
