Save flags into variables.

Signed-off-by: Nicolás Ortega Froysa <nicolas@ortegas.org>
This commit is contained in:
Nicolás A. Ortega Froysa 2024-02-23 18:21:29 +01:00
parent ddc9514bb1
commit 9bbe9b4a8f

View File

@ -30,6 +30,9 @@ use Getopt::Std;
my $VERSION = "1.0"; my $VERSION = "1.0";
my $PROG_NAME = "pacundo"; my $PROG_NAME = "pacundo";
my $r_flag = 0;
my $dry_run = 0;
sub print_version { sub print_version {
print("$PROG_NAME v$VERSION\n"); print("$PROG_NAME v$VERSION\n");
} }
@ -50,7 +53,7 @@ OPTIONS:
-v Print program version\n"); -v Print program version\n");
} }
getopts("irvh", \my %opts); getopts("irdvh", \my %opts);
if ($opts{'v'}) { if ($opts{'v'}) {
&print_version(); &print_version();
@ -58,4 +61,11 @@ if ($opts{'v'}) {
} elsif ($opts{'h'}) { } elsif ($opts{'h'}) {
&print_help(); &print_help();
exit 0; exit 0;
} elsif ($opts{'r'} && $opts{'i'}) {
print("Improper usage. -r and -i cannot be used at the same time.\n");
print("Use -h for help information.\n");
exit 1;
} }
$r_flag = 1 if ($opts{'r'});
$dry_run = 1 if ($opts{'d'});