#!/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 $used;
my $catstat;
my $help;
my $format;

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

if ( (defined $help && $help == 1 ) || !$optres )
{
  print basename($0) . " : " . __("list known products\n");
  print "   --used       (-u) : " . __("show only used products\n");
  print "   --catstat    (-c) : " . __("show repository (catalog) status: Are all repositories localy mirrored, which are required for this product?\n");
#  print "    -verbose    (-v) : " . __("show detailed product information\n");
  print "   --help       (-h) : " . __("show this help\n");
  print "   --format     (-f) : " . __("format the output ('asciitable', 'csv')\n");
  exit 0;
}

my %params = (verbose => $verbose, used => $used, catstat => $catstat);

$params{format} = (defined $format ? lc($format):'asciitable');

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

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

exit 0;

#
# Manpage
#

=head1 NAME

smt list-products -

=head1 SYNOPSIS

smt list-products [options]

=head1 DESCRIPTION

C<smt list-products> shows information about known products allowing filtering by varous criteria.

=head1 OPTIONS

=item --used -u

Shows only used products.

=item --catstat -c

Shows repository (catalog) status. Are all repositories localy mirrored,
which are required for this product?.

=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
