2007-11-16 19:47:00 +00:00
|
|
|
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
|
|
|
|
package xCAT::PPClog;
|
|
|
|
use strict;
|
|
|
|
use Getopt::Long;
|
|
|
|
|
|
|
|
|
|
|
|
##########################################################################
|
|
|
|
# Parse the command line for options and operands
|
|
|
|
##########################################################################
|
|
|
|
sub parse_args {
|
|
|
|
|
|
|
|
my $request = shift;
|
|
|
|
my $args = $request->{arg};
|
|
|
|
my %opt = ();
|
2008-02-06 19:28:19 +00:00
|
|
|
my @reventlog = qw(clear all);
|
2007-11-16 19:47:00 +00:00
|
|
|
my @VERSION = qw( 2.0 );
|
|
|
|
my $cmd;
|
|
|
|
|
|
|
|
#############################################
|
|
|
|
# Responds with usage statement
|
|
|
|
#############################################
|
|
|
|
local *usage = sub {
|
|
|
|
return( [ $_[0],
|
|
|
|
"reventlog -h|--help",
|
|
|
|
"reventlog -v|--version",
|
2008-02-06 19:28:19 +00:00
|
|
|
"reventlog [-V|--verbose] noderange " . join( '|', @reventlog )."|<number of entries to retrieve>",
|
2007-11-16 19:47:00 +00:00
|
|
|
" -h writes usage information to standard output",
|
|
|
|
" -v displays command version",
|
2008-02-06 19:28:19 +00:00
|
|
|
" -V verbose output"])
|
2007-11-16 19:47:00 +00:00
|
|
|
};
|
|
|
|
#############################################
|
|
|
|
# Process command-line arguments
|
|
|
|
#############################################
|
|
|
|
if ( !defined( $args )) {
|
|
|
|
return(usage( "No command specified" ));
|
|
|
|
}
|
|
|
|
#############################################
|
|
|
|
# Checks case in GetOptions, allows opts
|
|
|
|
# to be grouped (e.g. -vx), and terminates
|
|
|
|
# at the first unrecognized option.
|
|
|
|
#############################################
|
|
|
|
@ARGV = @$args;
|
|
|
|
$Getopt::Long::ignorecase = 0;
|
|
|
|
Getopt::Long::Configure( "bundling" );
|
|
|
|
|
2008-02-06 19:28:19 +00:00
|
|
|
if ( !GetOptions( \%opt, qw(h|help V|Verbose v|version) )) {
|
2007-11-16 19:47:00 +00:00
|
|
|
return( usage() );
|
|
|
|
}
|
|
|
|
####################################
|
|
|
|
# Option -h for Help
|
|
|
|
####################################
|
|
|
|
if ( exists( $opt{h} )) {
|
|
|
|
return( usage() );
|
|
|
|
}
|
|
|
|
####################################
|
2008-01-11 19:33:58 +00:00
|
|
|
# Option -v for version
|
|
|
|
####################################
|
|
|
|
if ( exists( $opt{v} )) {
|
|
|
|
return( \@VERSION );
|
|
|
|
}
|
|
|
|
####################################
|
2007-11-16 19:47:00 +00:00
|
|
|
# Check for "-" with no option
|
|
|
|
####################################
|
|
|
|
if ( grep(/^-$/, @ARGV )) {
|
|
|
|
return(usage( "Missing option: -" ));
|
|
|
|
}
|
|
|
|
####################################
|
2008-02-06 19:28:19 +00:00
|
|
|
# Unsupported commands
|
2007-11-16 19:47:00 +00:00
|
|
|
####################################
|
2008-02-06 19:28:19 +00:00
|
|
|
($cmd) = grep(/^$ARGV[0]$/, @reventlog );
|
|
|
|
if ( !defined( $cmd )) {
|
|
|
|
|
2007-11-16 19:47:00 +00:00
|
|
|
################################
|
2008-02-06 19:28:19 +00:00
|
|
|
# Check for non-zero integer
|
2007-11-16 19:47:00 +00:00
|
|
|
################################
|
2008-02-06 19:28:19 +00:00
|
|
|
if ( $ARGV[0] !~ /^[1-9]{1}$|^[1-9]{1}[0-9]+$/ ) {
|
2007-11-16 19:47:00 +00:00
|
|
|
return(usage( "Invalid command: $ARGV[0]" ));
|
|
|
|
}
|
2008-02-06 19:28:19 +00:00
|
|
|
$cmd = "entries";
|
|
|
|
$opt{e} = $ARGV[0];
|
2007-11-16 19:47:00 +00:00
|
|
|
}
|
2008-02-06 19:28:19 +00:00
|
|
|
shift @ARGV;
|
|
|
|
|
2007-11-16 19:47:00 +00:00
|
|
|
####################################
|
|
|
|
# Check for an extra argument
|
|
|
|
####################################
|
|
|
|
if ( defined( $ARGV[0] )) {
|
|
|
|
return(usage( "Invalid Argument: $ARGV[0]" ));
|
|
|
|
}
|
|
|
|
####################################
|
|
|
|
# Set method to invoke
|
|
|
|
####################################
|
|
|
|
$request->{method} = $cmd;
|
|
|
|
return( \%opt );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1;
|
2008-02-06 19:28:19 +00:00
|
|
|
|