#!/usr/bin/perl

use strict;
use warnings;
use Pod::Usage;
use Getopt::Long;
use Gear::Remotes::InSpec;

my $help;
my $verbose_default=1;
my $verbose=$verbose_default;
my $opt_print;

my $options_result = 
    GetOptions (
	"h|help"   => \$help,
	"print"  => \$opt_print,
	"verbose+"  => \$verbose,
	"quiet"  => sub {$verbose=0},
    );

sub exit_usage {
    #exec "pod2usage --exit=0 $0";
    pod2usage({ #-message => "the options below are package-specific:" ,
	-exitval => 0  ,
	-verbose => $verbose ? $verbose - $verbose_default : 0,
	#-output  => $filehandle
	      } );
}

if ($help) {
    &exit_usage();
}

my ($sourcegit, $comment, $is_vcs_tag)=Gear::Remotes::InSpec::get_from_spec();
if ($sourcegit) {
    if ($opt_print) {
	print $sourcegit,"\n";
    } else {
	print STDERR 'Found: ', $comment,' ',$sourcegit,"\n" if $verbose;
	exec('gear-remotes-set-from-url', $sourcegit) || die "can't exec gear-remotes-set-from-url $sourcegit";
    }
}

__END__

=head1	DESCRIPTION

=head1	NAME

gear-remotes-set-from-spec-comment - create .gear/upstream/remotes file from the comments in spec file

=head1	SYNOPSIS

B<gear-remotes-set-from-spec-comment>
[B<-h>] 
[B<-p, --print>]
[B<-v>] 
[B<-q>] 

=head1	DESCRIPTION

B<gear-remotes-set-from-spec-comment> creates I<.gear/upstream/remotes> file from the comments found in spec file.
After I<.gear/upstream/remotes> is created, run B<gear-remotes-restore>.

=head1	OPTIONS

=over

=item	B<-h, --help>

Display this help and exit.

=item	B<-p, --print>

Do nothing, just print git url if found.

=item	B<-v, --verbose>

Increase verbosity level.

=item	B<-q, --quiet>

Quiet mode.

=back

=head1	AUTHOR

Written by Igor Vlasenko <viy@altlinux.org>.

=head1	COPYING

Copyright (c) 2017-2021 Igor Vlasenko, ALT Linux Team.

This 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.

=cut
