#!/usr/bin/perl

###############################################################################
## Copyright (c) 2007-2012 SUSE LINUX Products GmbH, Nuernberg, Germany.
###############################################################################

use strict;
use warnings;
use FindBin;
BEGIN { unshift @INC, "$FindBin::Bin/../www/perl-lib" }

use SMT::CLI;
use SMT::Utils;
use File::Basename;

use Locale::gettext ();
use POSIX ();     # Needed for setlocale()

POSIX::setlocale(&POSIX::LC_MESSAGES, "");

if(!SMT::Utils::dropPrivileges())
{
    print STDERR __("Unable to drop privileges. Abort!\n");
    exit 1;
}

my $mirrorable;
my $domirror;
my $verbose;
my $help;
my $format;

use Getopt::Long;
Getopt::Long::Configure( 'no_auto_abbrev');
my $optres = Getopt::Long::GetOptions(
                                      'verbose|v' => \$verbose,
                                      'help|h' => \$help,
                                      'format|f=s' => \$format,
                                     );

if ( (defined $help && $help == 1 ) || !$optres )
{
  print basename($0) . " : " . __("list active registrations\n");
  print "    --help       (-h) : " . __("show this help\n");
  print "    --verbose    (-v) : " . __("show detailed informations about the registered devices\n");
  print "    --format     (-f) : " . __("format the output ('asciitable', 'csv')\n");
  # Option --outfile would make this script write the output into the smt's directory
  # because of the dropPrivileges call
  exit 0;
}

my %params = (verbose => $verbose);
$params{format} = (defined $format ? lc($format):'asciitable');

if (! SMT::CLI::checkFormat($params{format})) {
    exit 1;
}

SMT::CLI::listRegistrations(%params);

exit 0;

#
# Manpage
#

=head1 NAME

smt list-registrations

=head1 SYNOPSIS

smt [help|--help|-h] list-registrations

=head1 DESCRIPTION

I<smt list-registrations> shows information about active registrations in SMT.

=head1 OPTIONS

=item --verbose -v

Show detailed informations about the registered devices.


=head1 AUTHORS and CONTRIBUTORS

Duncan Mac-Vicar Prett, Lukas Ocilka, Jens Daniel Schmidt, Michael Calmer

=head1 LICENSE

Copyright (c) 2007-2012 SUSE LINUX Products GmbH, Nuernberg, Germany.

This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later
version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 675 Mass
Ave, Cambridge, MA 02139, USA.

=cut
