diff options
author | Andreas Guldstrand <andreas.guldstrand@gmail.com> | 2018-02-14 07:05:05 +0100 |
---|---|---|
committer | Andreas Guldstrand <andreas.guldstrand@gmail.com> | 2018-02-14 07:08:10 +0100 |
commit | 3e4fbdd3a25c10d89250599ccd5022adebf55865 (patch) | |
tree | b19d7f7b56212963517054c458d08f2b3ef5e6c5 /SBO-Lib/lib/SBO/App/Snap.pm | |
parent | 34508527cab3b61fca58aa9e3643a6c1da41c736 (diff) | |
download | sbotools2-3e4fbdd3a25c10d89250599ccd5022adebf55865.tar.xz |
sbosnap: move everything to module and make it OO
Diffstat (limited to 'SBO-Lib/lib/SBO/App/Snap.pm')
-rwxr-xr-x | SBO-Lib/lib/SBO/App/Snap.pm | 78 |
1 files changed, 78 insertions, 0 deletions
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; |