S
Slickuser
I am trying to print out the help message if no user input option is
used:
test2.pl runme #Print help usage
test2.pl runme -app "C:/a.exe" #Run script
I have try using scalar @ARGV == 0 but it doesn't help either.
Any idea? Thanks.
use strict;
use warnings;
use Getopt::Long;
main();
exit(0);
sub main
{
my $subcmds =
{
"runme" =>
{
'sub' => \&subcmd_runme
}
};
my $cmd = shift @ARGV;
defined $cmd or $cmd = '';
$subcmds->{$cmd} or die " No such command!\n";
$subcmds->{$cmd}{'sub'}->(@ARGV);
}
sub subcmd_runme
{
GetOptions
(
'app|a=s' => \my $opt_app,
'file|f:s' => \my $opt_file,
'help|h' => \my $opt_help
);
#print help if no user input options?
print "Execute script \n";
}
used:
test2.pl runme #Print help usage
test2.pl runme -app "C:/a.exe" #Run script
I have try using scalar @ARGV == 0 but it doesn't help either.
Any idea? Thanks.
use strict;
use warnings;
use Getopt::Long;
main();
exit(0);
sub main
{
my $subcmds =
{
"runme" =>
{
'sub' => \&subcmd_runme
}
};
my $cmd = shift @ARGV;
defined $cmd or $cmd = '';
$subcmds->{$cmd} or die " No such command!\n";
$subcmds->{$cmd}{'sub'}->(@ARGV);
}
sub subcmd_runme
{
GetOptions
(
'app|a=s' => \my $opt_app,
'file|f:s' => \my $opt_file,
'help|h' => \my $opt_help
);
#print help if no user input options?
print "Execute script \n";
}