Commit d0b73697 authored by Peter Pentchev's avatar Peter Pentchev

Add the --features long option.

parent 43a4c5ab
......@@ -5,6 +5,7 @@ Change log for ethstats, the network traffic statistics utility
an interface name
- allow the program to be run directly during the tests
- add the "--help" and "--version" long options
- add the "--features" long option
1.1.1 2015/12/28
- fix a grave bug I introduced in 1.1.0: get the correct value
......
......@@ -53,6 +53,19 @@ test: all
${TEST_SCRIPT} --version
${TEST_SCRIPT} --help
@echo "=== The features long option"
${TEST_SCRIPT} --features
${TEST_SCRIPT} --features | fgrep -qe ' ethstats='
if [ -f "`type -p feature-check 2>/dev/null`" ] && [ -x "`type -p feature-check 2>/dev/null`" ] && feature-check feature-check feature-check; then \
echo "=== Feature checks"; \
feature-check -l -- ${TEST_SCRIPT}; \
feature-check -- ${TEST_SCRIPT} ethstats; \
feature-check -- ${TEST_SCRIPT} ethstats ge 1; \
feature-check -- ${TEST_SCRIPT} 'ethstats lt 1000'; \
else \
echo "=== Skipping the feature checks - the feature-check tool does not seem to be installed"; \
fi
@echo "=== Error out on invalid options"
! ${TEST_SCRIPT} -X
! ${TEST_SCRIPT} --whee
......
......@@ -10,9 +10,16 @@ use strict;
use Getopt::Tiny;
use Terminal::ANSIColor;
constant VERSION = '1.2.0';
sub version()
{
say 'ethstats 1.2.0';
say 'ethstats ' ~ VERSION;
}
sub features()
{
say 'Features: ethstats=' ~ VERSION;
}
sub usage(Bool:D $err = True)
......@@ -216,6 +223,7 @@ sub convert(Str $iface, UInt:D $period, InterfaceStats:D $total)
given $v {
when 'help' { %flags<h> = True }
when 'version' { %flags<V> = True }
when 'features' { %flags<features> = True }
default {
note "Invalid long option '$v'";
usage;
......@@ -270,10 +278,13 @@ sub convert(Str $iface, UInt:D $period, InterfaceStats:D $total)
if %flags<V> {
version;
}
if %flags<features> {
features;
}
if %flags<h> {
usage False;
}
if %flags<V> || %flags<h> {
if %flags<V> || %flags<features> || %flags<h> {
exit 0;
}
......
......@@ -58,6 +58,11 @@ sub version()
say "ethstats $main::VERSION";
}
sub features()
{
say "Features: ethstats=$main::VERSION";
}
sub format_line($ $)
{
my ($name, $dev) = @_;
......@@ -157,20 +162,24 @@ MAIN:
getopts 'Cc:hi:Mn:tV-:', \%opts or usage(1);
my $Vflag = $opts{V} || ($opts{'-'} // '') eq 'version';
my $hflag = $opts{h};
my $featuresflag;
my $dash = $opts{'-'};
if (defined $dash) {
if ($dash eq 'version') {
$Vflag = 1;
} elsif ($dash eq 'help') {
$hflag = 1;
} elsif ($dash eq 'features') {
$featuresflag = 1;
} else {
warn "Invalid long option '$dash'\n";
usage 1;
}
}
version if $Vflag;
features if $featuresflag;
usage 0 if $hflag;
exit 0 if $Vflag || $hflag;
exit 0 if $Vflag || $featuresflag || $hflag;
my $addtime = $opts{t};
if (defined $opts{n}) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment