Skip to content
15 changes: 14 additions & 1 deletion cmd/apikey/apikey_current.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -24,7 +25,19 @@ var apikeyCurrentCmd = &cobra.Command{
if index != "" {
config.Current.Meta.CurrentAPIKey = index
config.SaveConfig()
fmt.Printf("Set the default API Key to be %s\n", utility.Green(index))

ow := utility.NewOutputWriter()
ow.StartLine()
ow.AppendDataWithLabel("name", index, "Name")

switch common.OutputFormat {
case "json":
ow.WriteSingleObjectJSON(common.PrettySet)
case "custom":
ow.WriteCustomOutput(common.OutputFields)
default:
fmt.Printf("Set the default API Key to be %s\n", utility.Green(index))
}
}

},
Expand Down
13 changes: 12 additions & 1 deletion cmd/apikey/apikey_remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,18 @@ var apikeyRemoveCmd = &cobra.Command{
config.SaveConfig()

if numKeys > len(config.Current.APIKeys) {
fmt.Printf("Removed the API Key %s\n", utility.Green(index))
ow := utility.NewOutputWriter()
ow.StartLine()
ow.AppendDataWithLabel("name", index, "Name")

switch common.OutputFormat {
case "json":
ow.WriteSingleObjectJSON(common.PrettySet)
case "custom":
ow.WriteCustomOutput(common.OutputFields)
default:
fmt.Printf("Removed the API Key %s\n", utility.Green(index))
}
} else {
utility.Error("The API Key %q couldn't be found", args[0])
os.Exit(1)
Expand Down
21 changes: 17 additions & 4 deletions cmd/instance/instance_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,23 @@ var instancePublicIPCmd = &cobra.Command{
utility.Error("%s", err)
}

if args[0] == "disable" {
fmt.Printf("Instance %s has been updated to NOT have a Public IP\n", utility.Green(instance.Hostname))
} else {
fmt.Printf("Instance %s has been updated to have a Public IP. IP addressed will be assigned shortly.\n", utility.Green(instance.Hostname))
ow := utility.NewOutputWriter()
ow.StartLine()
ow.AppendDataWithLabel("id", instance.ID, "ID")
ow.AppendDataWithLabel("hostname", instance.Hostname, "Hostname")
ow.AppendDataWithLabel("public_ip", args[0], "Public IP")

switch common.OutputFormat {
case "json":
ow.WriteSingleObjectJSON(common.PrettySet)
case "custom":
ow.WriteCustomOutput(common.OutputFields)
default:
if args[0] == "disable" {
fmt.Printf("Instance %s has been updated to NOT have a Public IP\n", utility.Green(instance.Hostname))
} else {
fmt.Printf("Instance %s has been updated to have a Public IP. IP addressed will be assigned shortly.\n", utility.Green(instance.Hostname))
}
}
},
}
23 changes: 17 additions & 6 deletions cmd/instance/instance_recovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ Example:
utility.Error("%s", err)
os.Exit(1)
}
fmt.Println("Instance ID is: ", instance.ID)
Copy link
Copy Markdown
Member

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


if args[0] == "enable" {
_, err := client.EnableRecoveryMode(instance.ID)
if err != nil {
Expand All @@ -63,10 +61,23 @@ Example:
}
}

if args[0] == "enable" {
fmt.Printf("Recovery mode has been enabled for instance %s\n", utility.Green(instance.Hostname))
} else {
fmt.Printf("Recovery mode has been disabled for instance %s\n", utility.Green(instance.Hostname))
ow := utility.NewOutputWriter()
ow.StartLine()
ow.AppendDataWithLabel("id", instance.ID, "ID")
ow.AppendDataWithLabel("hostname", instance.Hostname, "Hostname")
ow.AppendDataWithLabel("recovery_mode", args[0], "Recovery Mode")

switch common.OutputFormat {
case "json":
ow.WriteSingleObjectJSON(common.PrettySet)
case "custom":
ow.WriteCustomOutput(common.OutputFields)
default:
if args[0] == "enable" {
fmt.Printf("Recovery mode has been enabled for instance %s\n", utility.Green(instance.Hostname))
} else {
fmt.Printf("Recovery mode has been disabled for instance %s\n", utility.Green(instance.Hostname))
}
}
},
}
15 changes: 14 additions & 1 deletion cmd/kubernetes/kubernetes_nodepool_instance_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,20 @@ var kubernetesNodePoolInstanceDeleteCmd = &cobra.Command{
os.Exit(1)
}

fmt.Printf("Instance %s has been deleted from node pool %s in cluster %s\n", instanceID, nodePoolID, kubernetesFindCluster.Name)
ow := utility.NewOutputWriter()
ow.StartLine()
ow.AppendDataWithLabel("instance_id", instanceID, "Instance ID")
ow.AppendDataWithLabel("node_pool_id", nodePoolID, "Node Pool ID")
ow.AppendDataWithLabel("cluster_name", kubernetesFindCluster.Name, "Cluster Name")

switch common.OutputFormat {
case "json":
ow.WriteSingleObjectJSON(common.PrettySet)
case "custom":
ow.WriteCustomOutput(common.OutputFields)
default:
fmt.Printf("Instance %s has been deleted from node pool %s in cluster %s\n", instanceID, nodePoolID, kubernetesFindCluster.Name)
}
} else {
fmt.Println("Operation aborted.")
}
Expand Down
1 change: 1 addition & 0 deletions cmd/kubernetes/kubernetes_remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ var kubernetesRemoveCmd = &cobra.Command{
} else {
ow.WriteMultipleObjectsJSON(common.PrettySet)
}
case "custom":
ow.WriteCustomOutput(common.OutputFields)
default:
fmt.Printf("The Kubernetes %s (%s) %s been deleted\n",
Expand Down
14 changes: 13 additions & 1 deletion cmd/kubernetes/kubernetes_update_kubeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ var kubernetesUpdateKubeconfigCmd = &cobra.Command{
os.Exit(1)
}

fmt.Printf("Updated kubeconfig with cluster %s configuration\n", utility.Green(cluster.Name))
ow := utility.NewOutputWriter()
ow.StartLine()
ow.AppendDataWithLabel("id", cluster.ID, "ID")
ow.AppendDataWithLabel("name", cluster.Name, "Name")

switch common.OutputFormat {
case "json":
ow.WriteSingleObjectJSON(common.PrettySet)
case "custom":
ow.WriteCustomOutput(common.OutputFields)
default:
fmt.Printf("Updated kubeconfig with cluster %s configuration\n", utility.Green(cluster.Name))
}
},
}
76 changes: 49 additions & 27 deletions cmd/network/network_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fields vlan_id, physical_interface, allocation_pool_v4_start and allocation_pool_v4_end should only be displayed if the network is VLAN-enabled.

This way, vlan_id is shown in the JSON output as "vlan_id":"0", whereas the other fields are silently dropped because they're empty. I would add a guard here to prevent vlan_id from appearing in the JSON output as it's happening in the human formatting.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also a minor nitpick, we're using strconv.Itoa(network.VlanID) in network_list.go, we should probably stick to that for consistency.

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)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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))
}
}
}
},
Expand Down
Loading