From 3e4fbdd3a25c10d89250599ccd5022adebf55865 Mon Sep 17 00:00:00 2001 From: Andreas Guldstrand Date: Wed, 14 Feb 2018 07:05:05 +0100 Subject: sbosnap: move everything to module and make it OO --- SBO-Lib/lib/SBO/App/Snap.pm | 78 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100755 SBO-Lib/lib/SBO/App/Snap.pm (limited to 'SBO-Lib/lib') diff --git a/SBO-Lib/lib/SBO/App/Snap.pm b/SBO-Lib/lib/SBO/App/Snap.pm new file mode 100755 index 0000000..a00f977 --- /dev/null +++ b/SBO-Lib/lib/SBO/App/Snap.pm @@ -0,0 +1,78 @@ +#!/usr/bin/perl +# +# vim: ts=2:et +# +# sbosnap +# script to pull down / update a local copy of the slackbuilds.org tree. +# +# authors: Jacob Pipkin +# Luke Williams +# Andreas Guldstrand +# license: WTFPL + +use 5.16.0; +use strict; +use warnings FATAL => 'all'; +use SBO::Lib qw/ fetch_tree update_tree %config show_version /; +use Getopt::Long qw/ GetOptionsFromArray /; + +use parent 'SBO::App'; + +sub _parse_opts { + my @ARGS = @_; + + my ($help, $vers); + + GetOptionsFromArray( + \@ARGS, + 'help|h' => \$help, + 'version|v' => \$vers, + ); + + return { help => $help, vers => $vers, args => \@ARGS, }; +} + +sub show_usage { + my $self = shift; + my $fname = $self->{fname}; + print <<"EOF"; +Usage: $fname [options|command] + +Options: + -h|--help: + this screen. + -v|--version: + version information. + +Commands: + fetch: initialize a local copy of the slackbuilds.org tree. + update: update an existing local copy of the slackbuilds.org tree. + (generally, you may prefer "sbocheck" over "$fname update") + +EOF + return 1; +} + +sub run { + my $self = shift; + my @args = @{ $self->{args} }; + + if ($self->{help}) { $self->show_usage(); return 0 } + if ($self->{vers}) { $self->show_version(); return 0 } + + # check for a command and, if found, execute it + $args[0] //= ''; + + if ($args[0] eq 'fetch') { + fetch_tree() + } elsif ($args[0] eq 'update') { + update_tree() + } else { + $self->show_usage(); + return 1; + } + + return 0; +} + +1; -- cgit v1.2.3