-
Notifications
You must be signed in to change notification settings - Fork 100
fix: honour -o json/custom across missing and broken commands #586
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
39cdbfe
d23935e
a92fcd3
fd7e392
dd62518
5913c20
a564ecf
f7df348
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ import ( | |
| "fmt" | ||
| "os" | ||
|
|
||
| "github.com/civo/cli/common" | ||
| "github.com/civo/cli/config" | ||
| "github.com/civo/cli/utility" | ||
| "github.com/spf13/cobra" | ||
|
|
@@ -29,36 +30,57 @@ var networkShowCmd = &cobra.Command{ | |
| os.Exit(1) | ||
| } | ||
|
|
||
| // Display Core Network Details | ||
| fmt.Println("Network Details:") | ||
| fmt.Printf("ID: %s\n", network.ID) | ||
| fmt.Printf("Name: %s\n", network.Name) | ||
| fmt.Printf("Default: %s\n", utility.BoolToYesNo(network.Default)) | ||
| fmt.Printf("CIDR: %s\n", network.CIDR) | ||
| fmt.Printf("Status: %s\n", network.Status) | ||
| fmt.Printf("IPv4 Enabled: %s\n", utility.BoolToYesNo(network.IPv4Enabled)) | ||
| fmt.Printf("IPv6 Enabled: %s\n", utility.BoolToYesNo(network.IPv6Enabled)) | ||
| ow := utility.NewOutputWriter() | ||
| ow.StartLine() | ||
| ow.AppendDataWithLabel("id", network.ID, "ID") | ||
| ow.AppendDataWithLabel("name", network.Name, "Name") | ||
| ow.AppendDataWithLabel("default", utility.BoolToYesNo(network.Default), "Default") | ||
| ow.AppendDataWithLabel("cidr", network.CIDR, "CIDR") | ||
| ow.AppendDataWithLabel("status", network.Status, "Status") | ||
| ow.AppendDataWithLabel("ipv4_enabled", utility.BoolToYesNo(network.IPv4Enabled), "IPv4 Enabled") | ||
| ow.AppendDataWithLabel("ipv6_enabled", utility.BoolToYesNo(network.IPv6Enabled), "IPv6 Enabled") | ||
| ow.AppendDataWithLabel("vlan_id", fmt.Sprintf("%d", network.VlanID), "VLAN ID") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The fields This way,
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also a minor nitpick, we're using |
||
| ow.AppendDataWithLabel("physical_interface", network.PhysicalInterface, "Hardware Address") | ||
| ow.AppendDataWithLabel("gateway_ipv4", network.GatewayIPv4, "Gateway IPv4") | ||
| ow.AppendDataWithLabel("allocation_pool_v4_start", network.AllocationPoolV4Start, "Allocation Pool IPv4 Start") | ||
| ow.AppendDataWithLabel("allocation_pool_v4_end", network.AllocationPoolV4End, "Allocation Pool IPv4 End") | ||
| ow.AppendDataWithLabel("nameservers_v4", utility.SliceToString(network.NameserversV4), "Nameservers IPv4") | ||
| ow.AppendDataWithLabel("nameservers_v6", utility.SliceToString(network.NameserversV6), "Nameservers IPv6") | ||
|
|
||
| // Conditional VLAN Details | ||
| if network.VlanID != 0 { | ||
| fmt.Println("\nVLAN Details:") | ||
| fmt.Printf("VLAN ID: %d\n", network.VlanID) | ||
| fmt.Printf("Hardware Address: %s\n", network.PhysicalInterface) | ||
| fmt.Printf("Gateway IPv4: %s\n", network.GatewayIPv4) | ||
| fmt.Printf("Allocation Pool IPv4 Start: %s\n", network.AllocationPoolV4Start) | ||
| fmt.Printf("Allocation Pool IPv4 End: %s\n", network.AllocationPoolV4End) | ||
| } else { | ||
| fmt.Println("\nNo VLAN Configuration") | ||
| } | ||
| switch common.OutputFormat { | ||
| case "json": | ||
| ow.WriteSingleObjectJSON(common.PrettySet) | ||
| case "custom": | ||
| ow.WriteCustomOutput(common.OutputFields) | ||
| default: | ||
| fmt.Println("Network Details:") | ||
| fmt.Printf("ID: %s\n", network.ID) | ||
| fmt.Printf("Name: %s\n", network.Name) | ||
| fmt.Printf("Default: %s\n", utility.BoolToYesNo(network.Default)) | ||
| fmt.Printf("CIDR: %s\n", network.CIDR) | ||
| fmt.Printf("Status: %s\n", network.Status) | ||
| fmt.Printf("IPv4 Enabled: %s\n", utility.BoolToYesNo(network.IPv4Enabled)) | ||
| fmt.Printf("IPv6 Enabled: %s\n", utility.BoolToYesNo(network.IPv6Enabled)) | ||
|
|
||
| // Nameserver Details | ||
| if len(network.NameserversV4) > 0 || len(network.NameserversV6) > 0 { | ||
| fmt.Println("\nNameserver Details:") | ||
| if len(network.NameserversV4) > 0 { | ||
| fmt.Printf("Nameservers IPv4: %s\n", utility.SliceToString(network.NameserversV4)) | ||
| if network.VlanID != 0 { | ||
| fmt.Println("\nVLAN Details:") | ||
| fmt.Printf("VLAN ID: %d\n", network.VlanID) | ||
| fmt.Printf("Hardware Address: %s\n", network.PhysicalInterface) | ||
| fmt.Printf("Gateway IPv4: %s\n", network.GatewayIPv4) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is actually a pre-existing "bug" we could solve here: we can show the gateway IP even for non-VLAN networks, so this can be moved outside the guard. |
||
| fmt.Printf("Allocation Pool IPv4 Start: %s\n", network.AllocationPoolV4Start) | ||
| fmt.Printf("Allocation Pool IPv4 End: %s\n", network.AllocationPoolV4End) | ||
| } else { | ||
| fmt.Println("\nNo VLAN Configuration") | ||
| } | ||
| if len(network.NameserversV6) > 0 { | ||
| fmt.Printf("Nameservers IPv6: %s\n", utility.SliceToString(network.NameserversV6)) | ||
|
|
||
| if len(network.NameserversV4) > 0 || len(network.NameserversV6) > 0 { | ||
| fmt.Println("\nNameserver Details:") | ||
| if len(network.NameserversV4) > 0 { | ||
| fmt.Printf("Nameservers IPv4: %s\n", utility.SliceToString(network.NameserversV4)) | ||
| } | ||
| if len(network.NameserversV6) > 0 { | ||
| fmt.Printf("Nameservers IPv6: %s\n", utility.SliceToString(network.NameserversV6)) | ||
| } | ||
| } | ||
| } | ||
| }, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By removing this line, the human-form output no longer shows the UUID of the instance, but only the hostname. Consider adding it (between parentheses?) in the human-form output, next to the hostname