Skip to content

Commit

Permalink
diff: fix grid drawing
Browse files Browse the repository at this point in the history
The missing interfaces data doesn't depend on existing interfaces.
Also, only draw the table if it has columns.
  • Loading branch information
daniloegea committed Jul 31, 2023
1 parent 7294969 commit 4db9223
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions netplan/cli/commands/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ def run(self):
self.run_command()

def print_table(self, diff: dict, **style: dict):
main_table = Table.grid()

if interfaces := diff.get('interfaces'):
main_table = Table.grid()
for iface, data in interfaces.items():
name = data.get('name')

Expand Down Expand Up @@ -116,19 +117,21 @@ def print_table(self, diff: dict, **style: dict):
main_table.add_section()
main_table.add_row(table, end_section=True)

# Add missing interfaces to the grid
missing_interfaces_system = diff.get('missing_interfaces_system', [])
missing_interfaces_netplan = diff.get('missing_interfaces_netplan', [])
if missing_interfaces_system or missing_interfaces_netplan:
table = Table(expand=True, title='Missing Interfaces', **style)
table.add_column('Missing interfaces in Netplan\'s State', justify="center", ratio=2)
table.add_column('Missing interfaces in System\'s State', justify="center", ratio=2)
for (iface1, iface2) in zip_longest(missing_interfaces_netplan, missing_interfaces_system):
table.add_row(iface1, iface2)

main_table.add_section()
main_table.add_row(table, end_section=True)

# Add missing interfaces to the grid
missing_interfaces_system = diff.get('missing_interfaces_system', [])
missing_interfaces_netplan = diff.get('missing_interfaces_netplan', [])
if missing_interfaces_system or missing_interfaces_netplan:
table = Table(expand=True, title='Missing Interfaces', **style)
table.add_column('Missing interfaces in Netplan\'s State', justify="center", ratio=2)
table.add_column('Missing interfaces in System\'s State', justify="center", ratio=2)
for (iface1, iface2) in zip_longest(missing_interfaces_netplan, missing_interfaces_system):
table.add_row(iface1, iface2)

main_table.add_section()
main_table.add_row(table, end_section=True)

# Draw the grid
if main_table.columns:
console = Console()
console.print(main_table)

Expand Down

0 comments on commit 4db9223

Please sign in to comment.