Completely re-written to be more modular (hopefully easier to follow):
* Separated logic in Snap.pm, Commands.pm, Package.pm, and Sources.pm * Removed usher creation of directory structure (now in files.tar.gz) * Files like /etc/passwd now handled by snap-base
This commit is contained in:
258
SRC/snap/Commands.pm
Normal file
258
SRC/snap/Commands.pm
Normal file
@@ -0,0 +1,258 @@
|
||||
package Snap::Commands;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent 'Snap';
|
||||
|
||||
my $commands = {
|
||||
files => {
|
||||
options => [
|
||||
'<PKGNAME|FILE>',
|
||||
'[-t TARGET]',
|
||||
'[-v]'
|
||||
],
|
||||
brief => 'List files in package',
|
||||
help => [
|
||||
"\t\tPKGNAME or FILE is required. If PKGNAME\n"
|
||||
. "\t\t\t\tis used it must be an installed package\n",
|
||||
"\t\t\tAn optional target may be specified"
|
||||
. " to\n\t\t\t\tquery a separate"
|
||||
. " directory/file system\n",
|
||||
"\t\t\t\tShow full manifest details"
|
||||
]
|
||||
},
|
||||
genpkg => {
|
||||
options => [
|
||||
'<PKGNAME>'
|
||||
],
|
||||
brief => 'Create package build directory',
|
||||
help => [
|
||||
"\t\t\tPKGNAME is required. This will"
|
||||
. " create a\n\t\t\t\tdirectory of the same"
|
||||
. " name and populate\n\t\t\t\tit with a"
|
||||
. " skeleton of files and"
|
||||
. " directories\n\t\t\t\trequired to build"
|
||||
. " a snap package"
|
||||
]
|
||||
},
|
||||
help => {
|
||||
options => [],
|
||||
brief => 'Print brief usage information',
|
||||
help => []
|
||||
},
|
||||
info => {
|
||||
options => [
|
||||
'<PKGNAME[=VER]|FILE>',
|
||||
'[-t TARGET]'
|
||||
],
|
||||
brief => 'List package info',
|
||||
help => [
|
||||
"\t\tPKGNAME or FILE is required."
|
||||
. " A version string\n\t\t\t\tcan optionally"
|
||||
. " be provided with the PKGNAME\n"
|
||||
. "\t\t\t\tas packagename=x.x.x\n",
|
||||
"\t\t\tAn optional target may be specified"
|
||||
. " to\n\t\t\t\tquery a separate directory"
|
||||
. "/file system"
|
||||
]
|
||||
},
|
||||
install => {
|
||||
options => [
|
||||
'<PKGNAME[=VER]|FILE>',
|
||||
'[-t TARGET]',
|
||||
'[--no-deps]',
|
||||
'[-y]'
|
||||
],
|
||||
brief => 'Install package',
|
||||
help => [
|
||||
"\t\tPKGNAME or FILE is required"
|
||||
. " A version string\n\t\t\t\tcan optionally"
|
||||
. " be provided with the PKGNAME\n"
|
||||
. "\t\t\t\tas packagename=x.x.x\n",
|
||||
"\t\t\tAn optional target may be specified"
|
||||
. " to\n\t\t\t\tinstall the package to a"
|
||||
. " separate\n\t\t\t\tdirectory/file system\n",
|
||||
"\t\t\tInstall the package without dependencies\n",
|
||||
"\t\t\t\tProceed without prompting"
|
||||
]
|
||||
},
|
||||
list => {
|
||||
options => [
|
||||
'[-a]',
|
||||
'[-r REPO]',
|
||||
'[-t TARGET]'
|
||||
],
|
||||
brief => 'List packages',
|
||||
help => [
|
||||
"\t\t\t\tList all repo and installed packages\n",
|
||||
"\t\t\tOptionally specify a repository to list\n",
|
||||
"\t\t\tAn optional target may be specified"
|
||||
. " to\n\t\t\t\tquery a separate directory"
|
||||
. "/file system"
|
||||
]
|
||||
},
|
||||
purge => {
|
||||
options => [
|
||||
'<PKGNAME>',
|
||||
'[-t TARGET]',
|
||||
'[-y]'
|
||||
],
|
||||
brief => 'Remove package and/or configs',
|
||||
help => [
|
||||
"\t\t\tPKGNAME is required\n",
|
||||
"\t\t\tAn optional target may be specified"
|
||||
. " to\n\t\t\t\tinstall the package to a"
|
||||
. " separate\n\t\t\t\tdirectory/file system\n",
|
||||
"\t\t\t\tProceed without prompting"
|
||||
]
|
||||
},
|
||||
rebuild => {
|
||||
options => [
|
||||
'[-t TARGET]',
|
||||
'[-y]'
|
||||
],
|
||||
brief => 'Rebuild package DB',
|
||||
help => [
|
||||
"\t\t\tAn optional target may be specified"
|
||||
. " to\n\t\t\t\trepair the DB of a"
|
||||
. " separate\n\t\t\t\tdirectory/file system\n",
|
||||
"\t\t\t\tProceed without prompting"
|
||||
]
|
||||
},
|
||||
reinstall => {
|
||||
options => [
|
||||
'<PKGNAME>',
|
||||
'[-t TARGET]',
|
||||
'[-y]'
|
||||
],
|
||||
brief => 'Re-install package',
|
||||
help => [
|
||||
"\t\t\tPKGNAME is required\n",
|
||||
"\t\t\tAn optional target may be specified"
|
||||
. " to\n\t\t\t\tre-install the package on a"
|
||||
. " separate\n\t\t\t\tdirectory/file system\n",
|
||||
"\t\t\t\tProceed without prompting"
|
||||
]
|
||||
},
|
||||
remove => {
|
||||
options => [
|
||||
'<PKGNAME>',
|
||||
'[-t TARGET]',
|
||||
'[-y]'
|
||||
],
|
||||
brief => 'Remove a package',
|
||||
help => [
|
||||
"\t\t\tPKGNAME is required\n",
|
||||
"\t\t\tAn optional target may be specified"
|
||||
. " to\n\t\t\t\tremove the package from a"
|
||||
. " separate\n\t\t\t\tdirectory/file system\n",
|
||||
"\t\t\t\tProceed without prompting"
|
||||
]
|
||||
},
|
||||
search => {
|
||||
options => [
|
||||
'[STRING[=VER]]',
|
||||
'[-a]',
|
||||
'[-v]'
|
||||
],
|
||||
brief => 'Search repositories for packages',
|
||||
help => [
|
||||
"\t\tSTRING is optional. If STRING is not\n"
|
||||
. "\t\t\t\tprovided all repo packages are listed.\n"
|
||||
. "\t\t\t\tAn optional version string may be used\n",
|
||||
"\t\t\t\tReturn all versions from all repos\n",
|
||||
"\t\t\t\tPrint verbose output"
|
||||
]
|
||||
},
|
||||
source => {
|
||||
options => [
|
||||
'<PKGNAME[=VER]>'
|
||||
],
|
||||
brief => 'Retrieve package source',
|
||||
help => [
|
||||
"\t\tPKGNAME is required."
|
||||
. " A version string\n\t\t\t\tcan optionally"
|
||||
. " be provided with the PKGNAME\n"
|
||||
. "\t\t\t\tas packagename=x.x.x"
|
||||
]
|
||||
},
|
||||
upgrade => {
|
||||
options => [
|
||||
'[PKGNAME]',
|
||||
'[-t TARGET]',
|
||||
'[-y]'
|
||||
],
|
||||
brief => 'Upgrade packages',
|
||||
help => [
|
||||
"\t\t\tWith no arguments all packages are upgraded\n"
|
||||
. "\t\t\t\totherwise only the specified package\n",
|
||||
"\t\t\tAn optional target may be specified"
|
||||
. " to\n\t\t\t\tupgrade the package on a"
|
||||
. " separate\n\t\t\t\tdirectory/file system\n",
|
||||
"\t\t\t\tProceed without prompting"
|
||||
]
|
||||
},
|
||||
verify => {
|
||||
options => [
|
||||
'[PKGNAME]',
|
||||
'[-t TARGET]',
|
||||
'[-y]'
|
||||
],
|
||||
brief => 'Verify integrity of packages',
|
||||
help => [
|
||||
"\t\t\tWith no arguments all packages are verified\n"
|
||||
. "\t\t\t\totherwise only the specified package\n",
|
||||
"\t\t\tAn optional target may be specified"
|
||||
. " to\n\t\t\t\tverify the package on a"
|
||||
. " separate\n\t\t\t\tdirectory/file system\n",
|
||||
"\t\t\t\tProceed without prompting"
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
sub commandhelp {
|
||||
my $self = shift;
|
||||
my $command = shift;
|
||||
|
||||
if ( ! $self->{$command} ) {
|
||||
Snap->error( 64, "help(): Invalid command '$command'" );
|
||||
}
|
||||
|
||||
my $options = $commands->{$command}{'options'};
|
||||
my $help = $commands->{$command}{'help'};
|
||||
|
||||
print "\nsnap $command @{$commands->{$command}{'options'}}\n\n";
|
||||
print "$commands->{$command}{'brief'}\n\n";
|
||||
|
||||
for ( my $i = 0; $i <= $#{$options}; $i++ ) {
|
||||
print " $options->[$i]$help->[$i]\n";
|
||||
}
|
||||
|
||||
print "\n";
|
||||
}
|
||||
|
||||
sub new {
|
||||
my $class = shift;
|
||||
|
||||
return( bless( $commands, $class ) );
|
||||
}
|
||||
|
||||
sub help {
|
||||
if ( @ARGV ) {
|
||||
Snap->error( -1, "usage(): Invalid option '$ARGV[0]'" );
|
||||
}
|
||||
|
||||
print "\nUsage: $0 <COMMAND> <ARGS>\n\n"
|
||||
. "snap is the Snaplinux package management utility\n\n"
|
||||
. "COMMANDS\n\n";
|
||||
|
||||
foreach my $command ( sort( keys( %$commands ) ) ) {
|
||||
print " $command \t\t\t$commands->{$command}{'brief'}\n"
|
||||
}
|
||||
|
||||
print "\nTo view more information for commands run:\n"
|
||||
. "snap <COMMAND> -h\n\n";
|
||||
}
|
||||
|
||||
1;
|
||||
Reference in New Issue
Block a user