Adds --help|-h options; shows usage message and exits 0 if no arguments

This commit is contained in:
Jed Reynolds
2017-10-16 19:00:55 -07:00
parent c1a982d072
commit 41fe0661e5
5 changed files with 96 additions and 52 deletions

View File

@@ -1475,6 +1475,11 @@ sub initStationAddr {
## ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ## ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
my $help; my $help;
if (@ARGV < 2) {
print $usage;
exit 0;
}
GetOptions GetOptions
( (
'mgr|m=s' => \$::lfmgr_host, 'mgr|m=s' => \$::lfmgr_host,

View File

@@ -55,21 +55,31 @@ Example:
$0 --mgr 192.168.100.138 --action set_atten --atten_serno 3 --atten_idx all --atten_val 550\n"; $0 --mgr 192.168.100.138 --action set_atten --atten_serno 3 --atten_idx all --atten_val 550\n";
my $i = 0; my $i = 0;
my $show_help = 0;
if (@ARGV < 2) {
print $usage;
exit 0;
}
GetOptions GetOptions
( (
'atten_serno|s=s' => \$atten_serno, 'help|h' => \$show_help,
'atten_idx|i=s' => \$atten_idx, 'atten_serno|s=s' => \$atten_serno,
'atten_val|v=s' => \$atten_val, 'atten_idx|i=s' => \$atten_idx,
'action|a=s' => \$action, 'atten_val|v=s' => \$atten_val,
'cmd|c=s' => \$do_cmd, 'action|a=s' => \$action,
'mgr|m=s' => \$lfmgr_host, 'cmd|c=s' => \$do_cmd,
'mgr_port|p=i' => \$lfmgr_port, 'mgr|m=s' => \$lfmgr_host,
'resource|r=i' => \$resource, 'mgr_port|p=i' => \$lfmgr_port,
'quiet|q=s' => \$quiet, 'resource|r=i' => \$resource,
'quiet|q=s' => \$quiet,
) || (print($usage) && exit(1)); ) || (print($usage) && exit(1));
if ($show_help) {
print $usage;
exit 0;
}
if ($do_cmd ne "NA") { if ($do_cmd ne "NA") {
$action = "do_cmd"; $action = "do_cmd";

View File

@@ -150,42 +150,54 @@ Example:
my $i = 0; my $i = 0;
my $cmd; my $cmd;
die($::usage) if (@ARGV < 2);
my $log_cli = "unset"; # use ENV{LOG_CLI} elsewhere my $log_cli = "unset"; # use ENV{LOG_CLI} elsewhere
my $show_help = 0;
if (@ARGV < 2) {
print $usage;
exit 0;
}
GetOptions GetOptions
( (
'endp_name|e=s' => \$::endp_name, 'help|h' => \$show_help,
'endp_cmd=s' => \$::endp_cmd, 'endp_name|e=s' => \$::endp_name,
'endp_vals|o=s' => \$::endp_vals, 'endp_cmd=s' => \$::endp_cmd,
'action|a=s' => \$::action, 'endp_vals|o=s' => \$::endp_vals,
'cmd|c=s' => \$::do_cmd, 'action|a=s' => \$::action,
'mgr|m=s' => \$::lfmgr_host, 'cmd|c=s' => \$::do_cmd,
'mgr_port|p=i' => \$::lfmgr_port, 'mgr|m=s' => \$::lfmgr_host,
'resource|r=i' => \$::resource, 'mgr_port|p=i' => \$::lfmgr_port,
'port_name=s' => \$::port_name, 'resource|r=i' => \$::resource,
'speed|s=i' => \$::speed, 'port_name=s' => \$::port_name,
'max_speed=s' => \$::speed, 'speed|s=i' => \$::speed,
'quiet|q=s' => \$::quiet, 'max_speed=s' => \$::speed,
'endp_type=s' => \$::endp_type, 'quiet|q=s' => \$::quiet,
'mcast_addr=s' => \$::mcast_addr, 'endp_type=s' => \$::endp_type,
'mcast_port=s' => \$::mcast_port, 'mcast_addr=s' => \$::mcast_addr,
'min_pkt_sz=s' => \$::min_pkt_sz, 'mcast_port=s' => \$::mcast_port,
'max_pkt_sz=s' => \$::max_pkt_sz, 'min_pkt_sz=s' => \$::min_pkt_sz,
'rcv_mcast=s' => \$::rcv_mcast, 'max_pkt_sz=s' => \$::max_pkt_sz,
'use_csums=s' => \$::use_csums, 'rcv_mcast=s' => \$::rcv_mcast,
'ttl=i' => \$::ttl, 'use_csums=s' => \$::use_csums,
'report_timer=i' => \$::report_timer, 'ttl=i' => \$::ttl,
'cx_name=s' => \$::cx_name, 'report_timer=i' => \$::report_timer,
'cx_endps=s' => \$::cx_endps, 'cx_name=s' => \$::cx_name,
'test_mgr=s' => \$::test_mgr, 'cx_endps=s' => \$::cx_endps,
'tos=s' => \$::tos, 'test_mgr=s' => \$::test_mgr,
'arm_pps=i' => \$::arm_pps, 'tos=s' => \$::tos,
'ip_port=i' => \$::ip_port, 'arm_pps=i' => \$::arm_pps,
'multicon=i' => \$::multicon, 'ip_port=i' => \$::ip_port,
'log_cli=s{0,1}'=> \$log_cli, 'multicon=i' => \$::multicon,
'log_cli=s{0,1}'=> \$log_cli,
) || die("$::usage"); ) || die("$::usage");
if ($show_help) {
print $usage;
exit 0;
}
if ($::quiet eq "0") { if ($::quiet eq "0") {
$::quiet = "no"; $::quiet = "no";
} }

View File

@@ -83,21 +83,26 @@ my $i = 0;
GetOptions GetOptions
( (
'endp_name|e=s' => \$endp_name, 'help|h' => \$show_help,
'speed|s=i' => \$speed, 'endp_name|e=s' => \$endp_name,
'cx|c=s' => \$cx, 'speed|s=i' => \$speed,
'drop_pm|d=i' => \$drop_pm, 'cx|c=s' => \$cx,
'latency|l=i' => \$latency, 'drop_pm|d=i' => \$drop_pm,
'jitter|j=i' => \$jitter, 'latency|l=i' => \$latency,
'switch|w=s' => \$switch, 'jitter|j=i' => \$jitter,
'manager|m=s' => \$lfmgr_host, 'switch|w=s' => \$switch,
'pcap|p=s' => \$pcap, 'manager|m=s' => \$lfmgr_host,
'load|L=s' => \$load, 'pcap|p=s' => \$pcap,
'state|S=s' => \$state, 'load|L=s' => \$load,
'quiet|q=i' => \$quiet, 'state|S=s' => \$state,
'quiet|q=i' => \$quiet,
) || die("$usage"); ) || die("$usage");
if ($show_help) {
print $usage;
exit 0;
}
if (! ($quiet == 0xffff)) { if (! ($quiet == 0xffff)) {
open(CMD_LOG, ">$cmd_log_name") or die("Can't open $cmd_log_name for writing...\n"); open(CMD_LOG, ">$cmd_log_name") or die("Can't open $cmd_log_name for writing...\n");
if (! ($quiet & 0x2)) { if (! ($quiet & 0x2)) {

View File

@@ -94,6 +94,7 @@ my $usage = "$0 --port_name {name | number}
[--eap_identity {value|[BLANK]}] [--eap_identity {value|[BLANK]}]
[--eap_passwd {value|[BLANK]}] [--eap_passwd {value|[BLANK]}]
[--log_file {value}] # disabled by default [--log_file {value}] # disabled by default
[--help|-h ] # show help
Examples: Examples:
./lf_portmod.pl --manager 192.168.1.101 --card 1 --port_name eth2 --show_port ./lf_portmod.pl --manager 192.168.1.101 --card 1 --port_name eth2 --show_port
@@ -110,9 +111,15 @@ Examples:
my $i = 0; my $i = 0;
my $log_cli = 'unset'; my $log_cli = 'unset';
my $show_help = 0;
if (@ARGV < 2) {
print $usage;
exit 0;
}
GetOptions GetOptions
( (
'help|h' => \$show_help,
'ap=s' => \$ap, 'ap=s' => \$ap,
'port_name|e=s' => \$port_name, 'port_name|e=s' => \$port_name,
'cmd|c=s' => \$cmd, 'cmd|c=s' => \$cmd,
@@ -145,6 +152,11 @@ GetOptions
$::quiet = "yes"; $::quiet = "yes";
} }
if ($show_help) {
print $usage;
exit 0
}
# Open connection to the LANforge server. # Open connection to the LANforge server.
if (defined $log_cli) { if (defined $log_cli) {
if ($log_cli ne "unset") { if ($log_cli ne "unset") {