Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions cmd/compute.cloudserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,12 @@ var cloudserverCreateCmd = &cobra.Command{
return
}

format, err := GetOutputFormat(cmd)
if err != nil {
fmt.Println(err.Error())
return
}

if response != nil && response.Data != nil {
headers := []TableColumn{
{Header: "ID", Width: 30},
Expand Down Expand Up @@ -298,7 +304,11 @@ var cloudserverCreateCmd = &cobra.Command{
fmt.Sprintf("%d", hd),
regionValue,
}
PrintTable(headers, [][]string{row})
if err := RenderOutput(format, response.Data, func() {
PrintTable(headers, [][]string{row})
}); err != nil {
fmt.Println(err.Error())
}
} else {
fmt.Println("Cloud server created, but no data returned.")
}
Expand Down Expand Up @@ -572,6 +582,12 @@ var cloudserverListCmd = &cobra.Command{
Use: "list",
Short: "List all cloud servers",
Run: func(cmd *cobra.Command, args []string) {
format, err := GetOutputFormat(cmd)
if err != nil {
fmt.Println(err.Error())
return
}

projectID, err := GetProjectID(cmd)
if err != nil {
fmt.Printf("Error: %v\n", err)
Expand Down Expand Up @@ -651,7 +667,11 @@ var cloudserverListCmd = &cobra.Command{
})
}

PrintTable(headers, rows)
if err := RenderOutput(format, response.Data.Values, func() {
PrintTable(headers, rows)
}); err != nil {
fmt.Println(err.Error())
}
} else {
fmt.Println("No cloud servers found")
}
Expand Down
23 changes: 21 additions & 2 deletions cmd/compute.keypair.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ var keypairCreateCmd = &cobra.Command{
}

if response != nil && response.Data != nil {
format, err := GetOutputFormat(cmd)
if err != nil {
fmt.Println(err.Error())
return
}
headers := []TableColumn{
{Header: "NAME", Width: 40},
{Header: "PUBLIC_KEY", Width: 60},
Expand All @@ -157,7 +162,11 @@ var keypairCreateCmd = &cobra.Command{
}(),
publicKeyValue,
}
PrintTable(headers, [][]string{row})
if err := RenderOutput(format, response.Data, func() {
PrintTable(headers, [][]string{row})
}); err != nil {
fmt.Println(err.Error())
}
} else {
fmt.Println("Keypair created, but no data returned.")
}
Expand Down Expand Up @@ -311,6 +320,12 @@ var keypairListCmd = &cobra.Command{
Use: "list",
Short: "List all keypairs",
Run: func(cmd *cobra.Command, args []string) {
format, err := GetOutputFormat(cmd)
if err != nil {
fmt.Println(err.Error())
return
}

projectID, err := GetProjectID(cmd)
if err != nil {
fmt.Printf("Error: %v\n", err)
Expand Down Expand Up @@ -384,7 +399,11 @@ var keypairListCmd = &cobra.Command{
rows = append(rows, []string{name, id, publicKey, status})
}

PrintTable(headers, rows)
if err := RenderOutput(format, response.Data.Values, func() {
PrintTable(headers, rows)
}); err != nil {
fmt.Println(err.Error())
}
} else {
fmt.Println("No keypairs found")
}
Expand Down
11 changes: 10 additions & 1 deletion cmd/container.containerregistry.go
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,11 @@ var containerregistryListCmd = &cobra.Command{
}

if response.Data != nil && len(response.Data.Values) > 0 {
format, err := GetOutputFormat(cmd)
if err != nil {
fmt.Println(err.Error())
return
}
headers := []TableColumn{
{Header: "NAME", Width: 40},
{Header: "ID", Width: 30},
Expand Down Expand Up @@ -649,7 +654,11 @@ var containerregistryListCmd = &cobra.Command{
})
}

PrintTable(headers, rows)
if err := RenderOutput(format, response.Data.Values, func() {
PrintTable(headers, rows)
}); err != nil {
fmt.Println(err.Error())
}
} else {
fmt.Println("No container registries found")
}
Expand Down
23 changes: 21 additions & 2 deletions cmd/container.kaas.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,11 @@ var kaasCreateCmd = &cobra.Command{
}

if response != nil && response.Data != nil {
format, err := GetOutputFormat(cmd)
if err != nil {
fmt.Println(err.Error())
return
}
headers := []TableColumn{
{Header: "ID", Width: 30},
{Header: "NAME", Width: 40},
Expand Down Expand Up @@ -315,7 +320,11 @@ var kaasCreateCmd = &cobra.Command{
return ""
}(),
}
PrintTable(headers, [][]string{row})
if err := RenderOutput(format, response.Data, func() {
PrintTable(headers, [][]string{row})
}); err != nil {
fmt.Println(err.Error())
}
} else {
fmt.Println("KaaS cluster created, but no data returned.")
}
Expand Down Expand Up @@ -693,6 +702,12 @@ var kaasListCmd = &cobra.Command{
Use: "list",
Short: "List all KaaS clusters",
Run: func(cmd *cobra.Command, args []string) {
format, err := GetOutputFormat(cmd)
if err != nil {
fmt.Println(err.Error())
return
}

projectID, err := GetProjectID(cmd)
if err != nil {
fmt.Printf("Error: %v\n", err)
Expand Down Expand Up @@ -753,7 +768,11 @@ var kaasListCmd = &cobra.Command{
})
}

PrintTable(headers, rows)
if err := RenderOutput(format, response.Data.Values, func() {
PrintTable(headers, rows)
}); err != nil {
fmt.Println(err.Error())
}
} else {
fmt.Println("No KaaS clusters found")
}
Expand Down
82 changes: 64 additions & 18 deletions cmd/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,20 @@ import (

// Context represents the CLI context configuration
type Context struct {
CurrentContext string `yaml:"current-context"`
Contexts map[string]CtxInfo `yaml:"contexts"`
CurrentContext string `yaml:"current-context" json:"current_context"`
Contexts map[string]CtxInfo `yaml:"contexts" json:"contexts"`
}

// CtxInfo represents a single context
type CtxInfo struct {
ProjectID string `yaml:"project-id"`
Name string `yaml:"name,omitempty"`
ProjectID string `yaml:"project-id" json:"project_id"`
Name string `yaml:"name,omitempty" json:"name,omitempty"`
}

// contextCurrentOutput is the structured output for the current context command
type contextCurrentOutput struct {
Name string `yaml:"name" json:"name"`
ProjectID string `yaml:"project_id" json:"project_id"`
}

var contextCmd = &cobra.Command{
Expand Down Expand Up @@ -71,6 +77,12 @@ var contextUseCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
contextName := args[0]

format, err := GetOutputFormat(cmd)
if err != nil {
fmt.Println(err.Error())
return
}

// Load context
ctx, err := LoadContext()
if err != nil {
Expand All @@ -97,15 +109,30 @@ var contextUseCmd = &cobra.Command{
return
}

fmt.Printf("Switched to context '%s'\n", contextName)
fmt.Printf("Project ID: %s\n", ctx.Contexts[contextName].ProjectID)
output := contextCurrentOutput{
Name: contextName,
ProjectID: ctx.Contexts[contextName].ProjectID,
}

if err := RenderOutput(format, output, func() {
fmt.Printf("Switched to context '%s'\n", contextName)
fmt.Printf("Project ID: %s\n", ctx.Contexts[contextName].ProjectID)
}); err != nil {
fmt.Println(err.Error())
}
},
}

var contextListCmd = &cobra.Command{
Use: "list",
Short: "List all contexts",
Run: func(cmd *cobra.Command, args []string) {
format, err := GetOutputFormat(cmd)
if err != nil {
fmt.Println(err.Error())
return
}

// Load context
ctx, err := LoadContext()
if err != nil {
Expand All @@ -118,17 +145,21 @@ var contextListCmd = &cobra.Command{
return
}

fmt.Println("\nContexts:")
fmt.Println("=========")
for name, info := range ctx.Contexts {
current := ""
if name == ctx.CurrentContext {
current = " *"
if err := RenderOutput(format, ctx, func() {
fmt.Println("\nContexts:")
fmt.Println("=========")
for name, info := range ctx.Contexts {
current := ""
if name == ctx.CurrentContext {
current = " *"
}
fmt.Printf("%-20s Project ID: %s%s\n", name, info.ProjectID, current)
}
fmt.Printf("%-20s Project ID: %s%s\n", name, info.ProjectID, current)
}
if ctx.CurrentContext != "" {
fmt.Printf("\n* = current context\n")
if ctx.CurrentContext != "" {
fmt.Printf("\n* = current context\n")
}
}); err != nil {
fmt.Println(err.Error())
}
},
}
Expand All @@ -137,6 +168,12 @@ var contextCurrentCmd = &cobra.Command{
Use: "current",
Short: "Show current context",
Run: func(cmd *cobra.Command, args []string) {
format, err := GetOutputFormat(cmd)
if err != nil {
fmt.Println(err.Error())
return
}

// Load context
ctx, err := LoadContext()
if err != nil || ctx.CurrentContext == "" {
Expand All @@ -150,8 +187,17 @@ var contextCurrentCmd = &cobra.Command{
return
}

fmt.Printf("Current context: %s\n", ctx.CurrentContext)
fmt.Printf("Project ID: %s\n", info.ProjectID)
output := contextCurrentOutput{
Name: ctx.CurrentContext,
ProjectID: info.ProjectID,
}

if err := RenderOutput(format, output, func() {
fmt.Printf("Current context: %s\n", ctx.CurrentContext)
fmt.Printf("Project ID: %s\n", info.ProjectID)
}); err != nil {
fmt.Println(err.Error())
}
},
}

Expand Down
23 changes: 21 additions & 2 deletions cmd/database.backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,11 @@ var backupCreateCmd = &cobra.Command{
}

if response != nil && response.Data != nil {
format, err := GetOutputFormat(cmd)
if err != nil {
fmt.Println(err.Error())
return
}
headers := []TableColumn{
{Header: "ID", Width: 30},
{Header: "NAME", Width: 40},
Expand Down Expand Up @@ -221,7 +226,11 @@ var backupCreateCmd = &cobra.Command{
return ""
}(),
}
PrintTable(headers, [][]string{row})
if err := RenderOutput(format, response.Data, func() {
PrintTable(headers, [][]string{row})
}); err != nil {
fmt.Println(err.Error())
}
} else {
fmt.Println("Backup created, but no data returned.")
}
Expand Down Expand Up @@ -308,6 +317,12 @@ var backupListCmd = &cobra.Command{
Use: "list",
Short: "List all database backups",
Run: func(cmd *cobra.Command, args []string) {
format, err := GetOutputFormat(cmd)
if err != nil {
fmt.Println(err.Error())
return
}

projectID, err := GetProjectID(cmd)
if err != nil {
fmt.Printf("Error: %v\n", err)
Expand Down Expand Up @@ -376,7 +391,11 @@ var backupListCmd = &cobra.Command{
}
rows = append(rows, row)
}
PrintTable(headers, rows)
if err := RenderOutput(format, resp.Data.Values, func() {
PrintTable(headers, rows)
}); err != nil {
fmt.Println(err.Error())
}
} else {
fmt.Println("No backups found")
}
Expand Down
11 changes: 10 additions & 1 deletion cmd/database.dbaas.database.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,11 @@ var dbaasDatabaseListCmd = &cobra.Command{
}

if resp != nil && resp.Data != nil && len(resp.Data.Values) > 0 {
format, err := GetOutputFormat(cmd)
if err != nil {
fmt.Println(err.Error())
return
}
headers := []TableColumn{
{Header: "NAME", Width: 40},
{Header: "CREATION DATE", Width: 25},
Expand All @@ -265,7 +270,11 @@ var dbaasDatabaseListCmd = &cobra.Command{
}
rows = append(rows, row)
}
PrintTable(headers, rows)
if err := RenderOutput(format, resp.Data.Values, func() {
PrintTable(headers, rows)
}); err != nil {
fmt.Println(err.Error())
}
} else {
fmt.Println("No databases found")
}
Expand Down
Loading