From 777bebfe39826e932523e27b4c5a844498010969 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Wed, 24 Sep 2008 18:54:13 -0400 Subject: [PATCH] Define the common Getopt options in Ksplice.pm. Signed-off-by: Anders Kaseorg --- Ksplice.pm.in | 10 ++++++++-- ksplice-apply.in | 10 ++-------- ksplice-create.in | 10 ++-------- ksplice-undo.in | 10 ++-------- ksplice-view.in | 9 +-------- 5 files changed, 15 insertions(+), 34 deletions(-) diff --git a/Ksplice.pm.in b/Ksplice.pm.in index 84b409e..f6d0b6d 100644 --- a/Ksplice.pm.in +++ b/Ksplice.pm.in @@ -18,7 +18,7 @@ require Exporter; our @ISA = qw(Exporter); our @EXPORT = qw( Verbose GetOptions pod2usage shellwords - $datadir $libexecdir $version_str + $datadir $libexecdir @common_options $help child_error runval runval_raw runstr runstr_err runval_in runval_infile unpack_update get_stage set_stage set_debug_level get_abort_cause get_patch update_loaded get_debug_output get_conflicts @@ -27,7 +27,13 @@ our @EXPORT = qw( ); our ($datadir, $libexecdir) = qw(KSPLICE_DATA_DIR KSPLICE_LIBEXEC_DIR); -our $version_str = "Ksplice version PACKAGE_VERSION\n"; + +our $help = 0; +our @common_options = ( + "help|?" => \$help, + "version" => sub { print "Ksplice version PACKAGE_VERSION\n"; exit(0); }, + "verbose|v:+" => \$Verbose::level, +); sub child_error { if($? == -1) { diff --git a/ksplice-apply.in b/ksplice-apply.in index 6304a8e..4add055 100644 --- a/ksplice-apply.in +++ b/ksplice-apply.in @@ -22,16 +22,10 @@ use warnings; use lib 'KSPLICE_DATA_DIR'; use Ksplice; -my ($help, $wantversion, $debug) = (0, 0, 0); -GetOptions("help|?" => \$help, - "version" => \$wantversion, - "verbose|v:+" => \$Verbose::level, +my $debug = 0; +GetOptions(@common_options, "debug" => \$debug) or pod2usage(1); -if($wantversion) { - print $version_str; - exit(0); -} pod2usage(1) if($help || scalar(@ARGV) != 1); my $file = abs_path($ARGV[0]); diff --git a/ksplice-create.in b/ksplice-create.in index 2345bde..b96ff9f 100644 --- a/ksplice-create.in +++ b/ksplice-create.in @@ -26,11 +26,9 @@ my ($patchfile, $diffext, $orig_config_dir, $jobs, $kid); my @only_targets; my @extra_match; my $standalone; -my ($help, $wantversion, $prebuild, $skip_prebuild) = (0, 0, 0, 0); +my ($prebuild, $skip_prebuild) = (0, 0); my @patch_opt = "-p1"; -GetOptions("help|?" => \$help, - "version" => \$wantversion, - "verbose|v:+" => \$Verbose::level, +GetOptions(@common_options, "id=s" => \$kid, "patch=s" => \$patchfile, "diffext=s" => \$diffext, @@ -43,10 +41,6 @@ GetOptions("help|?" => \$help, "config=s" => \$orig_config_dir, "patch-opt=s" => \@patch_opt) or pod2usage(1); -if($wantversion) { - print $version_str; - exit(0); -} pod2usage(1) if($help || scalar(@ARGV) != 1); my $actions = (defined $patchfile) + (defined $diffext) + ($prebuild); pod2usage(1) if($actions != 1); diff --git a/ksplice-undo.in b/ksplice-undo.in index 57e4486..071109f 100644 --- a/ksplice-undo.in +++ b/ksplice-undo.in @@ -22,16 +22,10 @@ use warnings; use lib 'KSPLICE_DATA_DIR'; use Ksplice; -my ($help, $wantversion, $debug) = (0, 0, 0); -GetOptions("help|?" => \$help, - "version" => \$wantversion, - "verbose|v:+" => \$Verbose::level, +my $debug = 0; +GetOptions(@common_options, "debug" => \$debug) or pod2usage(1); -if($wantversion) { - print $version_str; - exit(0); -} pod2usage(1) if($help || scalar(@ARGV) != 1); my $kid = $ARGV[0]; diff --git a/ksplice-view.in b/ksplice-view.in index 71cdead..15c96f8 100644 --- a/ksplice-view.in +++ b/ksplice-view.in @@ -23,17 +23,10 @@ use lib 'KSPLICE_DATA_DIR'; use Ksplice; my ($kid, $mid, $module, $update, $file); -my ($help, $wantversion) = (0, 0); -GetOptions("help|?" => \$help, - "version" => \$wantversion, - "verbose|v:+" => \$Verbose::level, +GetOptions(@common_options, "id=s" => \$kid, "file=s" => \$file) or pod2usage(1); -if($wantversion) { - print $version_str; - exit(0); -} pod2usage(1) if($help || scalar(@ARGV) != 0); my $actions = (defined $kid) + (defined $file); pod2usage(1) if($actions > 1); -- 2.11.4.GIT