Repository: sonic-net/sonic-utilities

Issue:
Issue in CLI output alignment with shorter alias names in intf naming mode "alias"
 
**Description**
Issue in CLI output alignment when using shorter alias names for ports in sonic CLIs while using intf naming mode as alias
 
<!--
While using interface naming mode as 'alias' and when using shorter interface aliases like P0, P1, etc for ports in configs, the Output table cell(2,1), which is for “IFACE” field, has few extra ‘-’ characters(width equals to original intf name, not alias name)
-->
 
<!--
The current code works well till we keep the alias names greater or equal to intf names, but if we try with shorter names as mentioned below, it has this issue.  
-->
 
**Steps to reproduce the issue**
1.  Change the naming mode to alias instead of port names
    admin@sonic-svk169-dut:~$ config interface_naming_mode alias
2. Update config_db.json for port section to change alias to shorter names
3. Reload and run 'show interfaces  counters' command
 
**Describe the results you received**
For shorter alias names like P0, P1, etc..
 
```
admin@sonic-svk169-dut:~$ show interfaces  counters
IFACE    STATE    RX_OK    RX_BPS    RX_UTIL    RX_ERR    RX_DRP    RX_OVR     TX_OK    TX_BPS    TX_UTIL    TX_ERR    TX_DRP    TX_OVR
-----------  -------  -------  --------  ---------  --------  --------  --------  --------  --------  ---------  --------  --------  --------
  P0        X        0       N/A        N/A         0         0         0         0       N/A        N/A         0         0         0
  P4        X        0       N/A        N/A         0         0         0         0       N/A        N/A         0         0         0
  P8        U        2       N/A        N/A         0         0         0     15901       N/A        N/A         0         0         0
P12        U        2       N/A        N/A         0         0         0     15901       N/A        N/A         0         0         0
P16        U        2       N/A        N/A         0         0         0     15900       N/A        N/A         0         0         0
P20        U        2       N/A        N/A         0         0         0     15901       N/A        N/A         0         0         0
P24        U        2       N/A        N/A         0         0         0     15901       N/A        N/A         0         0         0
P28        X        0       N/A        N/A         0         0         0         0       N/A        N/A         0         0         0
P32        X        0       N/A        N/A         0         0         0         0       N/A        N/A         0         0         0
P36        X        0       N/A        N/A         0         0         0         0       N/A        N/A         0         0         0
P40        U        2       N/A        N/A         0         0         0     15901       N/A        N/A         0         0         0
P44        U        2       N/A        N/A         0         0         0     15901       N/A        N/A         0         0         0
P48        U        2       N/A        N/A         0         0         0     15901       N/A        N/A         0         0         0
...
 ```
 
**Describe the results you expected**
For shorter alias names like P0, P1, etc..
 ```
admin@sonic-svk169-dut:~$ show interfaces  counters
IFACE    STATE    RX_OK    RX_BPS    RX_UTIL    RX_ERR    RX_DRP    RX_OVR     TX_OK    TX_BPS    TX_UTIL    TX_ERR    TX_DRP    TX_OVR
-------  -------  -------  --------  ---------  --------  --------  --------  --------  --------  ---------  --------  --------  --------
  P0        X        0       N/A        N/A         0         0         0         0       N/A        N/A         0         0         0
  P4        X        0       N/A        N/A         0         0         0         0       N/A        N/A         0         0         0
  P8        U        2       N/A        N/A         0         0         0     15890       N/A        N/A         0         0         0
P12        U        2       N/A        N/A         0         0         0     15890       N/A        N/A         0         0         0
P16        U        2       N/A        N/A         0         0         0     15889       N/A        N/A         0         0         0
P20        U        2       N/A        N/A         0         0         0     15890       N/A        N/A         0         0         0
P24        U        2       N/A        N/A         0         0         0     15890       N/A        N/A         0         0         0
P28        X        0       N/A        N/A         0         0         0         0   
...
 ```
For bigger alias names:
 ```
admin@sonic-svk169-dut:~$ show interfaces  counters
                   IFACE    STATE    RX_OK    RX_BPS    RX_UTIL    RX_ERR    RX_DRP    RX_OVR    TX_OK    TX_BPS    TX_UTIL    TX_ERR    TX_DRP    TX_OVR
------------------------  -------  -------  --------  ---------  --------  --------  --------  -------  --------  ---------  --------  --------  --------
P00000000000000000000000        X        0       N/A        N/A         0         0         0        0       N/A        N/A         0         0         0
       P0000000000000004        X        0       N/A        N/A         0         0         0        0       N/A        N/A         0         0         0
                      P8        U        2       N/A        N/A         0         0         0       16       N/A        N/A         0         0         0
                     P12        U        2       N/A        N/A         0         0         0       17       N/A        N/A         0         0         0
                     P16        U        2       N/A        N/A         0         0         0       16       N/A        N/A         0         0         0
                     P20        U        2       N/A        N/A         0         0         0       16       N/A        N/A         0         0         0
                     P24        U        2       N/A        N/A         0         0         0       16       N/A        N/A         0         0         0
                     P28        X        0       N/A        N/A         0         0         0        0       N/A        N/A         0         0         0
                     P32        X        0       N/A        N/A         0         0         0        0       N/A        N/A         0         0         0
                     P36        X        0       N/A        N/A         0         0         0        0       N/A        N/A         0         0         0
 ```


Discussion:
<img width="1277" alt="errorneous_1" src="https://user-images.githubusercontent.com/70937876/106704392-10aab700-6612-11eb-8114-ede3e7cfd556.png">

Attached is the output of "show interface counters" cli when using shorter alias names

Resolving patch:
diff --git a/utilities_common/cli.py b/utilities_common/cli.py
--- a/utilities_common/cli.py
+++ b/utilities_common/cli.py
@@ -351,6 +351,8 @@ def print_output_in_alias_mode(output, index):
     if output.startswith("---"):
         word = output.split()
         dword = word[index]
+        if(len(dword) > iface_alias_converter.alias_max_length):
+            dword = dword[:len(dword) - iface_alias_converter.alias_max_length]
         underline = dword.rjust(iface_alias_converter.alias_max_length,
                                 '-')
         word[index] = underline


Test patch: