App-DistSync

 view release on metacpan or  search on metacpan

bin/distsync  view on Meta::CPAN

    "longhelp|H|?",         # Show long help page
    "debug|devel|d",        # Debug mode
    "verbose|v",            # Verbose mode
    "version|ver|V",        # Print VERSION of the project

    # Client options
    "proxy|x=s",            # Proxy URL
    "insecure|k",           # Insecure connection
    "timeout|T=i",          # Timeoute value in seconds. Default - 60

    # Project
    "directory|dir|D=s",    # Directory
    "delay|i=i",            # Delay. 0 - off, 1-n - secs, default - 3600
) || pod2usage(-exitval => 1, -verbose => 0, -output => \*STDERR);
pod2usage(-exitval => 0, -verbose => 1) if $options->{help};
pod2usage(-exitval => 0, -verbose => 2) if $options->{longhelp};
printf("DistSync v%s\n", App::DistSync->VERSION) && exit(0) if $options->{version};

# Get command
my $command   = @ARGV ? shift @ARGV : CMDDEFAULT;
pod2usage(-exitval => 1, -verbose => 99, -sections => 'SYNOPSIS|OPTIONS|COMMANDS', -output => \*STDERR)
    unless scalar grep {$_ eq $command} @{(COMMANDS)};

# Work directory
my $dir = $options->{directory} || shift(@ARGV) || getcwd();
die sprintf("Directory \"%s\" not exists", $dir) unless $dir && (-e $dir) && (-d $dir or -l $dir);

# Debugging on
$App::DistSync::Util::DEBUG = $App::DistSync::DEBUG = 1 if $options->{debug};

# Start process
my $started = time;
debug("%s START", tms);

# Lock file
my $lock = App::DistSync::LockFile->new(
        file => File::Spec->catfile($dir, App::DistSync::MANILOCK()),
        $options->{delay} ? (delay => $options->{delay}) : (),
        pid => $$,
    );
if ($lock->lock->error) {
    warn $lock->error . "\n";
    goto FINISH;
}

# Create instance
my $ds = App::DistSync->new(
    dir     => $dir,
    pid     => $$,
    timeout => $options->{timeout},
    verbose => $options->{verbose},
    insecure=> $options->{insecure},
    proxy   => $options->{proxy},
);

my $exitval = 1; # error

# Init
if ($command eq 'init') {
    $ds->init or goto FINISH;
    say "The work directory has been successfully initialized";
    printf "Your files are in \"%s\"\n", $ds->dir if $options->{verbose};
    $exitval = 0; # Ok
}

# Status
elsif ($command eq 'status') {
    if ($ds->status) {
        $ds->_show_summary;
        $exitval = 0; # Ok
    }
}

# Sync
elsif ($command eq 'sync') {
    if ($ds->sync) {
        say "Sync successfully completed";
        goto FINISH unless $options->{verbose};
        $ds->_show_summary;
        $exitval = 0; # Ok
    } else {
        printf("Sync \"%s\" completed with errors\n", $ds->dir);
    }
}

# Make manifest file
elsif ($command eq 'manifest' or $command eq 'mkmani') {
    if ($ds->mkmani) {
        say sprintf "The MANIFEST file has been successfully generated in \"%s\"", $ds->dir;
        $exitval = 0; # Ok
    } else {
        printf("Failed to generate MANIFEST file in \"%s\"\n", $ds->dir);
    }
}

FINISH: debug("%s FINISH", tms);
warn $lock->error . "\n" if $lock->unlock->error;
exit $exitval;

1;

__END__




( run in 0.514 second using v1.01-cache-2.11-cpan-d7a12ab2c7f )