made subnet list output prettier

This commit is contained in:
Adora Laura Kalb 2023-03-24 17:59:51 +01:00
parent cf3ff366c3
commit a95eab3221

View file

@ -39,8 +39,9 @@ var subnetlistCmd = &cobra.Command{
return subnets[i].Subnet.Addr().Less(subnets[j].Subnet.Addr())
})
fmt.Printf("%-15s VLAN %-25s Free IPs\n", "Prefix", "Name")
for _, subnet := range subnets {
//if verbose {
var numip, freeip int
if subnet.Subnet.Addr().Is4() {
@ -53,9 +54,16 @@ var subnetlistCmd = &cobra.Command{
freeip = numip - len(subnet.Addresses)
fmt.Printf("%v:\t%v\t(vl: %v)\tfree: %v\n", subnet.Subnet, subnet.Name, subnet.Vlan, freeip)
if freeip > 1000 {
fmt.Printf("%-15s %-4s %-25s >1000\n", subnet.Subnet, subnet.Vlan, subnet.Name)
} else {
//fmt.Printf("| %-20s | %-20s |\n", "vegetables", "fruits")
fmt.Printf("%-15s %-4s %-25s %v\n", subnet.Subnet, subnet.Vlan, subnet.Name, freeip)
}
} else {
fmt.Printf("%v:\t%v\t(vl: %v)\n", subnet.Subnet, subnet.Name, subnet.Vlan)
//todo
}
//} else {
// fmt.Printf("%v:\t%v\t(vl: %v)\n", subnet.Subnet, subnet.Name, subnet.Vlan)