work on long option names, #73

pull/89/merge
David Schweikert 8 years ago
parent 6bd608bf7a
commit 4f672b9b62

@ -2,52 +2,52 @@
use Test::Command tests => 9;
my $I_HELP = " -I if bind to a particular interface\n";
my $I_HELP = " -I, --iface=IFACE bind to a particular interface\n";
$I_HELP = '' if $^O eq 'darwin';
# fping -h
my $cmd1 = Test::Command->new(cmd => "fping -h");
$cmd1->exit_is_num(0);
$cmd1->stdout_is_eq(<<END);
Usage: fping [options] [targets...]
-4 only use IPv4 addresses
-6 only use IPv6 addresses
-a show targets that are alive
-A show targets by address
-b n amount of ping data to send, in bytes (default 56)
-B f set exponential backoff factor to f
-c n count of pings to send to each target (default 1)
-C n same as -c, report results in verbose format
-D print timestamp before each output line
-e show elapsed time on return packets
-f file read list of targets from a file ( - means stdin) (only if no -g specified)
-g generate target list (only if no -f specified)
(specify the start and end IP in the target list, or supply a IP netmask)
Probing options:
-4 only ping IPv4 addresses
-6 only ping IPv6 addresses
-b, --size=BYTES amount of ping data to send, in bytes (default 56)
-B, --backoff=N set exponential backoff factor to N
-c, --count=N count of pings to send to each target (default 1)
-f, --file=FILE read list of targets from a file ( - means stdin)
-g, --generate generate target list (only if no -f specified)
(specify the start and end IP in the target list, or use a CIDR address)
(ex. fping -g 192.168.1.0 192.168.1.255 or fping -g 192.168.1.0/24)
-H n Set the IP TTL value (Time To Live hops)
-i n interval between sending ping packets (in millisec) (default 25)
${I_HELP} -l loop sending pings forever
-m use all IPs of provided hostnames (e.g. IPv4 and IPv6), use with -A
-M set the Don't Fragment flag
-n show targets by name (-d is equivalent)
-N output compatible for netdata (-l -Q are required)
-o show the accumulated outage time (lost packets * packet interval)
-O n set the type of service (tos) flag on the ICMP packets
-p n interval between ping packets to one target (in millisec)
-H, --ttl=N set the IP TTL value (Time To Live hops)
$I_HELP -l, --loop loop sending pings forever
-m, --all use all IPs of provided hostnames (e.g. IPv4 and IPv6), use with -A
-M, --dontfrag set the Don't Fragment flag
-O, --tos=N set the type of service (tos) flag on the ICMP packets
-p, --period=MSEC interval between ping packets to one target (in millisec)
(in looping and counting modes, default 1000)
-q quiet (don't show per-target/per-ping results)
-Q n same as -q, but show summary every n seconds
-r n number of retries (default 3)
-R random packet data (to foil link data compression)
-s print final stats
-S addr set source address
-t n individual target initial timeout (in millisec) (default 500)
-T n ignored (for compatibility with fping 2.4)
-u show targets that are unreachable
-v show version
targets list of targets to check (if no -f specified)
-r, --retry=N number of retries (default 3)
-R, --random random packet data (to foil link data compression)
-S, --src=IP set source address
-t, --timeout=MSEC individual target initial timeout (in millisec) (default 500)
Output options:
-a, --alive show targets that are alive
-A, --addr show targets by address
-C, --vcount=N same as -c, report results in verbose format
-D, --timestamp print timestamp before each output line
-e, --elapsed show elapsed time on return packets
-i, --interval=MSEC interval between sending ping packets (in ms) (default 25)
-n, --name show targets by name (-d is equivalent)
-N, --netdata output compatible for netdata (-l -Q are required)
-o, --outage show the accumulated outage time (lost packets * packet interval)
-q, --quiet quiet (don't show per-target/per-ping results)
-Q, --squiet=SECS same as -q, but show summary every n seconds
-s, --stats print final stats
-u, --unreach show targets that are unreachable
-v, --version show version
END
$cmd1->stderr_is_eq("");
@ -62,9 +62,4 @@ $cmd2->stderr_is_eq("");
my $cmd3 = Test::Command->new(cmd => "fping -Z");
$cmd3->exit_is_num(1);
$cmd3->stdout_is_eq("");
if($^O eq 'darwin') {
$cmd3->stderr_is_eq("fping: illegal option -- Z\nsee 'fping -h' for usage information\n");
}
else {
$cmd3->stderr_is_eq("fping: invalid option -- 'Z'\nsee 'fping -h' for usage information\n");
}
$cmd3->stderr_like(qr{^fping: (illegal|invalid) option -- '?Z'?\nsee 'fping -h' for usage information\n$});

@ -375,7 +375,7 @@ int main(int argc, char** argv)
{ "size", 'b', OPTPARSE_REQUIRED },
{ "backoff", 'B', OPTPARSE_REQUIRED },
{ "count", 'c', OPTPARSE_REQUIRED },
{ "scount", 'C', OPTPARSE_REQUIRED },
{ "vcount", 'C', OPTPARSE_REQUIRED },
{ NULL, 'd', OPTPARSE_NONE }, // same as '--names'
{ "timestamp", 'D', OPTPARSE_NONE },
{ "elapsed", 'e', OPTPARSE_NONE },
@ -389,21 +389,22 @@ int main(int argc, char** argv)
{ "all", 'm', OPTPARSE_NONE },
{ "dontfrag", 'M', OPTPARSE_NONE },
{ "names", 'n', OPTPARSE_NONE },
{ "rdns", 'N', OPTPARSE_NONE }, // FIXME: similar to --names, but do name->IP->name if a name is provided
{ "outage", 'o', OPTPARSE_NONE }, // FIXME: document in POD
{ "netdata", 'N', OPTPARSE_NONE },
{ "outage", 'o', OPTPARSE_NONE },
{ "tos", 'O', OPTPARSE_REQUIRED },
{ "period", 'p', OPTPARSE_REQUIRED },
{ "quiet", 'q', OPTPARSE_NONE },
{ "squiet", 'Q', OPTPARSE_REQUIRED },
{ "retry", 'r', OPTPARSE_REQUIRED },
{ "random", 'R', OPTPARSE_NONE }, // FIXME: document in POD
{ "random", 'R', OPTPARSE_NONE },
{ "stats", 's', OPTPARSE_NONE },
{ "src", 'S', OPTPARSE_REQUIRED },
{ "timeout", 't', OPTPARSE_REQUIRED },
{ NULL, 'T', OPTPARSE_REQUIRED },
{ "unreach", 'u', OPTPARSE_NONE },
{ "version", 'v', OPTPARSE_NONE },
{ 0 }
{ "rdns", 'X', OPTPARSE_NONE }, // FIXME: similar to --names, but do name->IP->name if a name is provided
{ 0, 0, 0 }
};
//while ((c = optparse(&optparse_state, "46ADMNRadeghlmnoqsuvzB:C:H:I:O:Q:S:T:b:c:f:i:p:r:t:")) != EOF) {
@ -2663,47 +2664,47 @@ void ev_remove(HOST_ENTRY* h)
void usage(int is_error)
{
FILE* out = is_error ? stderr : stdout;
fprintf(out, "\n");
fprintf(out, "Usage: %s [options] [targets...]\n", prog);
fprintf(out, " -4 only use IPv4 addresses\n");
fprintf(out, " -6 only use IPv6 addresses\n");
fprintf(out, " -a show targets that are alive\n");
fprintf(out, " -A show targets by address\n");
fprintf(out, " -b n amount of ping data to send, in bytes (default %d)\n", DEFAULT_PING_DATA_SIZE);
fprintf(out, " -B f set exponential backoff factor to f\n");
fprintf(out, " -c n count of pings to send to each target (default %d)\n", count);
fprintf(out, " -C n same as -c, report results in verbose format\n");
fprintf(out, " -D print timestamp before each output line\n");
fprintf(out, " -e show elapsed time on return packets\n");
fprintf(out, " -f file read list of targets from a file ( - means stdin) (only if no -g specified)\n");
fprintf(out, " -g generate target list (only if no -f specified)\n");
fprintf(out, " (specify the start and end IP in the target list, or supply a IP netmask)\n");
fprintf(out, "\n");
fprintf(out, "Probing options:\n");
fprintf(out, " -4 only ping IPv4 addresses\n");
fprintf(out, " -6 only ping IPv6 addresses\n");
fprintf(out, " -b, --size=BYTES amount of ping data to send, in bytes (default %d)\n", DEFAULT_PING_DATA_SIZE);
fprintf(out, " -B, --backoff=N set exponential backoff factor to N\n");
fprintf(out, " -c, --count=N count of pings to send to each target (default %d)\n", count);
fprintf(out, " -f, --file=FILE read list of targets from a file ( - means stdin)\n");
fprintf(out, " -g, --generate generate target list (only if no -f specified)\n");
fprintf(out, " (specify the start and end IP in the target list, or use a CIDR address)\n");
fprintf(out, " (ex. %s -g 192.168.1.0 192.168.1.255 or %s -g 192.168.1.0/24)\n", prog, prog);
fprintf(out, " -H n Set the IP TTL value (Time To Live hops)\n");
fprintf(out, " -i n interval between sending ping packets (in millisec) (default %d)\n", interval / 100);
fprintf(out, " -H, --ttl=N set the IP TTL value (Time To Live hops)\n");
#ifdef SO_BINDTODEVICE
fprintf(out, " -I if bind to a particular interface\n");
fprintf(out, " -I, --iface=IFACE bind to a particular interface\n");
#endif
fprintf(out, " -l loop sending pings forever\n");
fprintf(out, " -m use all IPs of provided hostnames (e.g. IPv4 and IPv6), use with -A\n");
fprintf(out, " -M set the Don't Fragment flag\n");
fprintf(out, " -n show targets by name (-d is equivalent)\n");
fprintf(out, " -N output compatible for netdata (-l -Q are required)\n");
fprintf(out, " -o show the accumulated outage time (lost packets * packet interval)\n");
fprintf(out, " -O n set the type of service (tos) flag on the ICMP packets\n");
fprintf(out, " -p n interval between ping packets to one target (in millisec)\n");
fprintf(out, " -l, --loop loop sending pings forever\n");
fprintf(out, " -m, --all use all IPs of provided hostnames (e.g. IPv4 and IPv6), use with -A\n");
fprintf(out, " -M, --dontfrag set the Don't Fragment flag\n");
fprintf(out, " -O, --tos=N set the type of service (tos) flag on the ICMP packets\n");
fprintf(out, " -p, --period=MSEC interval between ping packets to one target (in millisec)\n");
fprintf(out, " (in looping and counting modes, default %d)\n", perhost_interval / 100);
fprintf(out, " -q quiet (don't show per-target/per-ping results)\n");
fprintf(out, " -Q n same as -q, but show summary every n seconds\n");
fprintf(out, " -r n number of retries (default %d)\n", DEFAULT_RETRY);
fprintf(out, " -R random packet data (to foil link data compression)\n");
fprintf(out, " -s print final stats\n");
fprintf(out, " -S addr set source address\n");
fprintf(out, " -t n individual target initial timeout (in millisec) (default %d)\n", timeout / 100);
fprintf(out, " -T n ignored (for compatibility with fping 2.4)\n");
fprintf(out, " -u show targets that are unreachable\n");
fprintf(out, " -v show version\n");
fprintf(out, " targets list of targets to check (if no -f specified)\n");
fprintf(out, " -r, --retry=N number of retries (default %d)\n", DEFAULT_RETRY);
fprintf(out, " -R, --random random packet data (to foil link data compression)\n");
fprintf(out, " -S, --src=IP set source address\n");
fprintf(out, " -t, --timeout=MSEC individual target initial timeout (in millisec) (default %d)\n", timeout / 100);
fprintf(out, "\n");
fprintf(out, "Output options:\n");
fprintf(out, " -a, --alive show targets that are alive\n");
fprintf(out, " -A, --addr show targets by address\n");
fprintf(out, " -C, --vcount=N same as -c, report results in verbose format\n");
fprintf(out, " -D, --timestamp print timestamp before each output line\n");
fprintf(out, " -e, --elapsed show elapsed time on return packets\n");
fprintf(out, " -i, --interval=MSEC interval between sending ping packets (in ms) (default %d)\n", interval / 100);
fprintf(out, " -n, --name show targets by name (-d is equivalent)\n");
fprintf(out, " -N, --netdata output compatible for netdata (-l -Q are required)\n");
fprintf(out, " -o, --outage show the accumulated outage time (lost packets * packet interval)\n");
fprintf(out, " -q, --quiet quiet (don't show per-target/per-ping results)\n");
fprintf(out, " -Q, --squiet=SECS same as -q, but show summary every n seconds\n");
fprintf(out, " -s, --stats print final stats\n");
fprintf(out, " -u, --unreach show targets that are unreachable\n");
fprintf(out, " -v, --version show version\n");
exit(is_error);
}

Loading…
Cancel
Save