aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--SBO-Lib/MANIFEST1
-rwxr-xr-xSBO-Lib/lib/SBO/App/Snap.pm78
-rwxr-xr-xsbosnap47
3 files changed, 82 insertions, 44 deletions
diff --git a/SBO-Lib/MANIFEST b/SBO-Lib/MANIFEST
index 2e48b3f..a00cb9d 100644
--- a/SBO-Lib/MANIFEST
+++ b/SBO-Lib/MANIFEST
@@ -6,6 +6,7 @@ t/SBO-Lib.t
t/versions.t
lib/SBO/App.pm
lib/SBO/App/Remove.pm
+lib/SBO/App/Snap.pm
lib/SBO/Lib.pm
lib/SBO/Lib/Build.pm
lib/SBO/Lib/Download.pm
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 <j@dawnrazor.net>
+# Luke Williams <xocel@iquidus.org>
+# Andreas Guldstrand <andreas.guldstrand@gmail.com>
+# license: WTFPL <http://sam.zoy.org/wtfpl/COPYING>
+
+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;
diff --git a/sbosnap b/sbosnap
index 6de9fd7..7462e93 100755
--- a/sbosnap
+++ b/sbosnap
@@ -13,49 +13,8 @@
use 5.16.0;
use strict;
use warnings FATAL => 'all';
-use SBO::Lib qw/ fetch_tree update_tree %config show_version /;
-use File::Basename;
-use Getopt::Long;
+use SBO::App::Snap;
-my $sbo_home = $config{SBO_HOME};
-my $self = basename($0);
+my $app = SBO::App::Snap->new(@ARGV);
-sub show_usage {
- print <<"EOF";
-Usage: $self [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 "$self update")
-
-EOF
- return 1;
-}
-
-my ($help, $vers);
-
-GetOptions('help|h' => \$help, 'version|v' => \$vers);
-
-if ($help) { show_usage(); exit 0 }
-if ($vers) { show_version(); exit 0 }
-
-# check for a command and, if found, execute it
-$ARGV[0] //= '';
-
-if ($ARGV[0] eq 'fetch') {
- fetch_tree()
-} elsif ($ARGV[0] eq 'update') {
- update_tree()
-} else {
- show_usage();
- exit 1;
-}
-
-exit 0;
+exit $app->run();