#!/usr/bin/perl

eval 'exec /usr/bin/perl  -S $0 ${1+"$@"}'
    if 0; # not running under some shell

# PODNAME: qbit_tanker_upload

=encoding UTF-8
=cut

=head1 SYNOPSIS

qbit_tanker_upload

 No obligatory options. All the settings are taken from config file
 `qbit_tanker.conf`.

 Optional options:

      --tanker_branch=master        Branch to update. Default value is master
      --ref_tanker_branch=feature_x        Base branch name. By default is queried from terminal.
                             Need only when branch in tanker doesn't exist and need to be created.

Script to upload translations to the tanker. Script will upload tranlastions
to the tanker branch with the name `--tanker_branch`

In case there is no tanker branch it will be created. The user will be asked
for the base branch if no `--ref_tanker_branch` option is specified. If `--ref_tanker_branch` option is
specified then it will be used as the base branch.

=cut

use strict;
use warnings FATAL => 'all';
use Carp;

use lib::abs '../lib';

use QBit::Tanker;
use Getopt::Long;
use Pod::Usage;

sub main {

    my $qt_ref = QBit::Tanker->new();

    my $tanker_branch;
    my $ref_tanker_branch;
    GetOptions(
        'help|h' => sub { pod2usage({-message => ''}); exit; },
        "tanker_branch=s" => \$tanker_branch,
        "ref_tanker_branch=s" => \$ref_tanker_branch,
    )
    or croak "Error in command line arguments\n";

    my $tanker_branch = $tanker_branch // 'master'
    $qt_ref->__create_branch_if_needed($tanker_branch, $ref_tanker_branch);

    $qt_ref->__download_all_po_from_tanker( $tanker_branch );
    $qt_ref->__extract_strings_to_po();
    $qt_ref->__merge_po;

    $qt_ref->__split_po_to_keysets();
    $qt_ref->__upload_keysets($tanker_branch);

    $qt_ref->__rm_tmp_files();

}

main();
__END__
