Skip to content

Commit

Permalink
Show Region in case of no resources
Browse files Browse the repository at this point in the history
  • Loading branch information
uzaxirr committed Apr 27, 2024
1 parent ae2bfa4 commit 2167b76
Show file tree
Hide file tree
Showing 17 changed files with 35 additions and 133 deletions.
10 changes: 1 addition & 9 deletions cmd/apikey/apikey_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package apikey
import (
"sort"

"github.com/civo/cli/common"
"github.com/civo/cli/config"
"github.com/civo/cli/utility"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -42,13 +41,6 @@ Example: civo apikey ls -o custom -f "Name: Key"`,

}

switch common.OutputFormat {
case "json":
ow.WriteMultipleObjectsJSON(common.PrettySet)
case "custom":
ow.WriteCustomOutput(common.OutputFields)
default:
ow.WriteTable()
}
ow.FinishAndPrintOutput()
},
}
10 changes: 1 addition & 9 deletions cmd/database/database_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,6 @@ var dbListCmd = &cobra.Command{
}
}

switch common.OutputFormat {
case "json":
ow.WriteMultipleObjectsJSON(common.PrettySet)
case "custom":
ow.WriteCustomOutput(common.OutputFields)
default:
ow.WriteTable()
fmt.Println("To get the credentials for a database, use `civo db credential <name/ID>`")
}
ow.FinishAndPrintOutput()
},
}
10 changes: 1 addition & 9 deletions cmd/domain/domain_list.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package domain

import (
"github.com/civo/cli/common"
"github.com/civo/cli/config"
"github.com/civo/cli/utility"

Expand Down Expand Up @@ -42,13 +41,6 @@ Example: civo domain ls -o custom -f "ID: Name"`,
ow.AppendDataWithLabel("name", domain.Name, "Name")
}

switch common.OutputFormat {
case "json":
ow.WriteMultipleObjectsJSON(common.PrettySet)
case "custom":
ow.WriteCustomOutput(common.OutputFields)
default:
ow.WriteTable()
}
ow.FinishAndPrintOutput()
},
}
10 changes: 1 addition & 9 deletions cmd/domain/domain_record_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"os"
"strconv"

"github.com/civo/cli/common"
"github.com/civo/cli/config"
"github.com/civo/cli/utility"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -63,14 +62,7 @@ If you wish to use a custom format, the available fields are:

}

switch common.OutputFormat {
case "json":
ow.WriteMultipleObjectsJSON(common.PrettySet)
case "custom":
ow.WriteCustomOutput(common.OutputFields)
default:
ow.WriteTable()
}
ow.FinishAndPrintOutput()
},
}

Expand Down
9 changes: 1 addition & 8 deletions cmd/firewall/firewall_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,6 @@ Example: civo firewall ls -o custom -f "ID: Name"`,
ow.AppendDataWithLabel("loadbalancer_count", strconv.Itoa(firewall.LoadBalancerCount), "Total LoadBalancer")
}

switch common.OutputFormat {
case "json":
ow.WriteMultipleObjectsJSON(common.PrettySet)
case "custom":
ow.WriteCustomOutput(common.OutputFields)
default:
ow.WriteTable()
}
ow.FinishAndPrintOutput()
},
}
9 changes: 1 addition & 8 deletions cmd/firewall/firewall_rule_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,6 @@ If you wish to use a custom format, the available fields are:
ow.AppendDataWithLabel("label", firewallRule.Label, "Label")
}

switch common.OutputFormat {
case "json":
ow.WriteMultipleObjectsJSON(common.PrettySet)
case "custom":
ow.WriteCustomOutput(common.OutputFields)
default:
ow.WriteTable()
}
ow.FinishAndPrintOutput()
},
}
9 changes: 1 addition & 8 deletions cmd/instance/instance_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,6 @@ If you wish to use a custom format, the available fields are:
}
}

switch common.OutputFormat {
case "json":
ow.WriteMultipleObjectsJSON(common.PrettySet)
case "custom":
ow.WriteCustomOutput(common.OutputFields)
default:
ow.WriteTable()
}
ow.FinishAndPrintOutput()
},
}
9 changes: 1 addition & 8 deletions cmd/ip/ip_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,6 @@ var ipListCmd = &cobra.Command{
}
}

switch common.OutputFormat {
case "json":
ow.WriteMultipleObjectsJSON(common.PrettySet)
case "custom":
ow.WriteCustomOutput(common.OutputFields)
default:
ow.WriteTable()
}
ow.FinishAndPrintOutput()
},
}
9 changes: 1 addition & 8 deletions cmd/kfcluster/kfcluster_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,6 @@ var kfcListCmd = &cobra.Command{
ow.AppendDataWithLabel("dashboard_url", kfc.DashboardURL, "Dashboard URL")
}

switch common.OutputFormat {
case "json":
ow.WriteMultipleObjectsJSON(common.PrettySet)
case "custom":
ow.WriteCustomOutput(common.OutputFields)
default:
ow.WriteTable()
}
ow.FinishAndPrintOutput()
},
}
9 changes: 1 addition & 8 deletions cmd/kubernetes/kubernetes_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,6 @@ If you wish to use a custom format, the available fields are:
}
}

switch common.OutputFormat {
case "json":
ow.WriteMultipleObjectsJSON(common.PrettySet)
case "custom":
ow.WriteCustomOutput(common.OutputFields)
default:
ow.WriteTable()
}
ow.FinishAndPrintOutput()
},
}
9 changes: 1 addition & 8 deletions cmd/loadbalancer/loadbalancer_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,6 @@ If you wish to use a custom format, the available fields are:
ow.AppendData("Backends", strings.Join(backendList, ", "))
}

switch common.OutputFormat {
case "json":
ow.WriteMultipleObjectsJSON(common.PrettySet)
case "custom":
ow.WriteCustomOutput(common.OutputFields)
default:
ow.WriteTable()
}
ow.FinishAndPrintOutput()
},
}
9 changes: 1 addition & 8 deletions cmd/network/network_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,6 @@ If you wish to use a custom format, the available fields are:
}
}

switch common.OutputFormat {
case "json":
ow.WriteMultipleObjectsJSON(common.PrettySet)
case "custom":
ow.WriteCustomOutput(common.OutputFields)
default:
ow.WriteTable()
}
ow.FinishAndPrintOutput()
},
}
9 changes: 1 addition & 8 deletions cmd/objectstore/objectstore_credential_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,6 @@ var objectStoreCredentialListCmd = &cobra.Command{
ow.AppendDataWithLabel("status", credential.Status, "Status")
}

switch common.OutputFormat {
case "json":
ow.WriteMultipleObjectsJSON(common.PrettySet)
case "custom":
ow.WriteCustomOutput(common.OutputFields)
default:
ow.WriteTable()
}
ow.FinishAndPrintOutput()
},
}
9 changes: 1 addition & 8 deletions cmd/objectstore/objectstore_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,6 @@ var objectStoreListCmd = &cobra.Command{
ow.AppendDataWithLabel("status", objectStore.Status, "Status")
}

switch common.OutputFormat {
case "json":
ow.WriteMultipleObjectsJSON(common.PrettySet)
case "custom":
ow.WriteCustomOutput(common.OutputFields)
default:
ow.WriteTable()
}
ow.FinishAndPrintOutput()
},
}
10 changes: 1 addition & 9 deletions cmd/sshkey/ssh_key_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package sshkey
import (
"os"

"github.com/civo/cli/common"
"github.com/civo/cli/config"
"github.com/civo/cli/utility"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -44,13 +43,6 @@ Example: civo ssh ls -o custom -f "id: name"`,
ow.AppendDataWithLabel("fingerprint", sshkey.Fingerprint, "Finger Print")
}

switch common.OutputFormat {
case "json":
ow.WriteMultipleObjectsJSON(common.PrettySet)
case "custom":
ow.WriteCustomOutput(common.OutputFields)
default:
ow.WriteTable()
}
ow.FinishAndPrintOutput()
},
}
9 changes: 1 addition & 8 deletions cmd/volume/volume_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,6 @@ Example: civo volume ls -o custom -f "ID: Name (SizeGigabytes)`,
ow.AppendDataWithLabel("status", volume.Status, "Status")
}

switch common.OutputFormat {
case "json":
ow.WriteMultipleObjectsJSON(common.PrettySet)
case "custom":
ow.WriteCustomOutput(common.OutputFields)
default:
ow.WriteTable()
}
ow.FinishAndPrintOutput()
},
}
19 changes: 19 additions & 0 deletions utility/output_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"bytes"
"encoding/json"
"fmt"
"github.com/civo/cli/common"
"github.com/civo/cli/config"
"os"
"regexp"
"sort"
Expand Down Expand Up @@ -280,3 +282,20 @@ func prettyprint(b []byte) ([]byte, error) {
err := json.Indent(&out, b, "", " ")
return out.Bytes(), err
}

func (ow *OutputWriter) FinishAndPrintOutput() {
ow.finishExistingLine()
if len(ow.Values) == 0 {
region := config.Current.Meta.DefaultRegion // Ensure this fetches the correct current region.
fmt.Fprintf(os.Stderr, "No resources found in region %s. For a list of regions use the command 'civo region ls'\n", region)
} else {
switch common.OutputFormat {
case "json":
ow.WriteMultipleObjectsJSON(common.PrettySet)
case "custom":
ow.WriteCustomOutput(common.OutputFields)
default:
ow.WriteTable()
}
}
}

0 comments on commit 2167b76

Please sign in to comment.