#!/usr/bin/perl

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

sub help {
	return qq{
	Prints list of Attributes Definition
	------------------------------------------
	Available options:
	--orderById   | -i  order by numeric Id
	--orderByName | -n  order by name (default)
	--batch       | -b  batch
	--help        | -h  prints this help
	};
}

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


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

my $agent = Perun::Agent->new();
my $attrAgent = $agent->getAttributesAgent;
my @attrs = $attrAgent->getAttributesDefinition;
unless (@attrs) {
	printMessage "No Attribute found", $batch;
	exit 0;
}

printTable($sortingFunction, @attrs);
