#!/usr/bin/env perl

################################################################################
##  bu -- backup files into a .tar.gz archive                                 ##
##                                                                            ##
##  Authors: Matt Martini                                                     ##
##           Eugene Miretskiy                                                 ##
##                                                                            ##
##  Copyright © 2000-2025  Matt Martini <matt.martini@imaginarywave.com>      ##
##                                                                            ##
################################################################################

########################################
#      Requirements and Packages       #
########################################
use Dev::Util::Syntax;
use Dev::Util qw(::Backup);

use File::Basename;
use Term::ANSIColor;

Readonly my $VERSION => version->declare("v2.19.6");

$Term::ANSIColor::AUTORESET = 1;

########################################
#            Main Program              #
########################################

#check BUDIR env var for sanity
$Dev::Util::Backup::BACKUPDIR = $ENV{ BUDIR } if ( $ENV{ BUDIR } );

# $Backup::BACKUPDIR = $ENV{BUDIR} if($ENV{BUDIR});

my $newfile;

foreach (@ARGV) {
    print "Backing up ", colored( $_, 'blue' ), " ...\t";

    if ( eval { $newfile = backup($_); 1 } ) {
        print " file saved as    ", colored( $newfile, "bold blue" ), "\n";
    }
    else {
        pmc( [ " backup failed, ", "red" ], [ $@, "bold red" ], [ "\n", "black" ] );
    }

}

# print strings in different colors
# each argument is ref array which will be passed
# AS IS to colored sub
# Ex: multicolor(["1234", "blue"], ["5678", "black"], ["90", "bold blue"].....)
sub multicolor {
    return map { colored(@$_) } @_;
}

#print multicolor string
sub pmc {
    print multicolor(@_);
    return;
}
