#!/usr/bin/perl

use strict;
use warnings;
use Getopt::Long qw(:config no_ignore_case);
use Text::ASCIITable;
use Perun::Agent;
use Perun::Common qw(printMessage getSortingFunction printTable);

sub help {
	return qq{
	Prints list of all VOs
	---------------------------------------
	Available options:
	--orderByName | -n order by short name
	--orderById   | -i order by id
	--batch       | -b batch
	--help        | -h prints this help

	};
}

my $sortingFunction;
our $batch;
GetOptions ("help|h" => sub {
		print help;
		exit 0;
	}, "batch|b"     => \$batch, "orderById|i" => sub { $sortingFunction = getSortingFunction('getId') },
	"orderByName|n"  => sub {$sortingFunction = getSortingFunction("getShortName", 1); } ) || die help;

unless (defined $sortingFunction) { $sortingFunction = getSortingFunction("getShortName", 1); }

my $agent = Perun::Agent->new();
my $vosAgent = $agent->getVosAgent;
my @vos = $vosAgent->getVos;
unless (@vos) {
	printMessage "No VOs found", $batch;
	exit 0;
}

printTable($sortingFunction, @vos);