about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2020-06-14 18:09:56 +0530
committerAndinus <andinus@nand.sh>2020-06-14 18:09:56 +0530
commitdc87ff67f47010cb2b25e6cff93c02bb0b8859ff (patch)
treeaff6276a42dd14f04cd000388bde229f86cdc887
parentd128d6030915dbed396e9232db389c5169705808 (diff)
downloadara-dc87ff67f47010cb2b25e6cff93c02bb0b8859ff.tar.gz
Add option to show only passed states
Now user can specify states in "show" option & only those states will
be printed, "hide" option is ignored when "show" is passed.

Note: "hide" is ignored only for states & not for columns.
-rwxr-xr-xara.pl30
1 files changed, 22 insertions, 8 deletions
diff --git a/ara.pl b/ara.pl
index 9885950..96a8ab1 100755
--- a/ara.pl
+++ b/ara.pl
@@ -28,7 +28,7 @@ foreach my $path (@INC) {
 }
 
 my ( $use_local_file, $get_latest, $state_notes, $rows_to_print, $no_delta,
-     $no_total, @to_hide, %hide );
+     $no_total, @to_hide, %hide, @to_show, %show );
 
 GetOptions(
     "local" => \$use_local_file,
@@ -39,6 +39,7 @@ GetOptions(
     "nototal" => \$no_total,
     "hide=s{1,}" => \@to_hide, # Getopt::Long docs say that this is an
                                # experimental feature with a warning.
+    "show=s{1,}" => \@to_show,
     "help", "h" => sub { HelpMessage() },
 ) or die "Error in command line arguments";
 
@@ -61,6 +62,9 @@ undef @hide{ @to_hide }
                         # Alternatively can do @hide{ @to_hide } = ()
                         # which will work even if @to_hide is empty.
 
+undef @show{ @to_show }
+    if scalar @to_show;
+
 # Alias updated to last updated. This will allow user to just enter
 # updated in hide option.
 undef $hide{'last updated'}
@@ -79,7 +83,8 @@ sub HelpMessage {
     --rows=i  Number of rows to print (i is Integer)
     --nodelta Don't print changes in values
     --nototal Don't print 'Total' row
-    --hide    Hide states, columns from table (space seperated values)";
+    --hide    Hide states, columns from table (space seperated)
+    --show    Show only these states (space seperated)";
     print LOCALCOLOR CYAN "
     --help    Print this help message
 ";
@@ -206,12 +211,21 @@ foreach my $i ( 0 ... scalar @$statewise - 1 ) {
     $state = "Unassigned"
         if $state eq "State Unassigned";
 
-    next
-        if exists $hide{lc $state}
-        # User sees the statecode if length $state > 16 so we also
-        # match against that.
-        or ( length $state > 16
-             and exists $hide{lc $statewise->[$i]{statecode}});
+    # If user has asked to show specific states then forget about hide
+    # option.
+    if ( scalar @to_show ) {
+        next
+            unless exists $show{lc $state}
+            or ( length $state > 16
+                 and exists $show{lc $statewise->[$i]{statecode}})
+    } else {
+        next
+            if exists $hide{lc $state}
+            # User sees the statecode if length $state > 16 so we also
+            # match against that.
+            or ( length $state > 16
+                 and exists $hide{lc $statewise->[$i]{statecode}});
+    }
 
     $state = $statewise->[$i]{statecode}
         if length $state > 16;