Skip to content
Merged
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
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ GO_LDFLAGS=-X cloudamqp-cli/cmd.Version=$(VERSION) \
-X cloudamqp-cli/cmd.BuildDate=$(BUILD_DATE) \
-X cloudamqp-cli/cmd.GitCommit=$(GIT_COMMIT)


bin/cloudamqp:
$(MAKE) build BINARY_NAME="bin/cloudamqp"

# Default target
.PHONY: all
all: build
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ Note: Dynamic completions (instance IDs, plans, regions) require a configured AP

## Commands

#### Output
You can output either as JSON via `-o json` or Table format using `-o table`

### Instance Management

Manage CloudAMQP instances using your main API key.
Expand All @@ -115,6 +118,9 @@ cloudamqp instance create --name=my-instance --plan=bunny-1 --region=amazon-web-
# List all instances
cloudamqp instance list

# List all instances with more details
cloudamqp instance list --details

# Get instance details
cloudamqp instance get --id 1234

Expand Down
17 changes: 8 additions & 9 deletions cmd/instance_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,17 @@ var instanceConfigListCmd = &cobra.Command{
return nil
}

// Print table header
fmt.Printf("%-40s %-30s\n", "KEY", "VALUE")
fmt.Printf("%-40s %-30s\n", "---", "-----")
p, err := getPrinter(cmd)
if err != nil {
return err
}

// Print configuration data
headers := []string{"KEY", "VALUE"}
rows := make([][]string, 0, len(config))
for key, value := range config {
valueStr := fmt.Sprintf("%v", value)
if len(valueStr) > 30 {
valueStr = valueStr[:27] + "..."
}
fmt.Printf("%-40s %-30s\n", key, valueStr)
rows = append(rows, []string{key, fmt.Sprintf("%v", value)})
}
p.PrintRecords(headers, rows)

return nil
},
Expand Down
36 changes: 23 additions & 13 deletions cmd/instance_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,35 @@ var instanceGetCmd = &cobra.Command{
return err
}

// Format output as "Name = Value"
fmt.Printf("Name = %s\n", instance.Name)
fmt.Printf("Plan = %s\n", instance.Plan)
fmt.Printf("Region = %s\n", instance.Region)
fmt.Printf("Tags = %s\n", strings.Join(instance.Tags, ","))

showURL, _ := cmd.Flags().GetBool("show-url")
if showURL {
fmt.Printf("URL = %s\n", instance.URL)
} else {
fmt.Printf("URL = %s\n", maskPassword(instance.URL))
p, err := getPrinter(cmd)
if err != nil {
return err
}

fmt.Printf("Hostname = %s\n", instance.HostnameExternal)
showURL, _ := cmd.Flags().GetBool("show-url")
ready := "No"
if instance.Ready {
ready = "Yes"
}
fmt.Printf("Ready = %s\n", ready)

urlVal := maskPassword(instance.URL)
if showURL {
urlVal = instance.URL
}

p.PrintRecord(
[]string{"ID", "NAME", "PLAN", "REGION", "TAGS", "URL", "HOSTNAME", "READY"},
[]string{
strconv.Itoa(instance.ID),
instance.Name,
instance.Plan,
instance.Region,
strings.Join(instance.Tags, ","),
urlVal,
instance.HostnameExternal,
ready,
},
)

return nil
},
Expand Down
83 changes: 75 additions & 8 deletions cmd/instance_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package cmd

import (
"fmt"
"os"
"strconv"
"strings"
"sync"

"cloudamqp-cli/client"
"cloudamqp-cli/internal/table"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -35,18 +35,85 @@ var instanceListCmd = &cobra.Command{
return nil
}

// Create table and populate data
t := table.New(os.Stdout, "ID", "NAME", "PLAN", "REGION")
for _, instance := range instances {
t.AddRow(
p, err := getPrinter(cmd)
if err != nil {
return err
}

details, _ := cmd.Flags().GetBool("details")

if details {
showURL, _ := cmd.Flags().GetBool("show-url")
detailed := make([]*client.Instance, len(instances))
headers := []string{"ID", "NAME", "PLAN", "REGION", "TAGS", "URL", "HOSTNAME", "READY"}
rows := make([][]string, len(instances))
var (
mu sync.Mutex
firstErr error
wg sync.WaitGroup
)
for i, instance := range instances {
wg.Add(1)
go func(idx, id int) {
defer wg.Done()
det, err := c.GetInstance(id)
mu.Lock()
defer mu.Unlock()
if err != nil {
if firstErr == nil {
firstErr = fmt.Errorf("error fetching instance %d: %w", id, err)
}
return
}
detailed[idx] = det
}(i, instance.ID)
}
wg.Wait()
if firstErr != nil {
return firstErr
}

for i, inst := range detailed {
ready := "No"
if inst.Ready {
ready = "Yes"
}
urlVal := maskPassword(inst.URL)
if showURL {
urlVal = inst.URL
}
rows[i] = []string{
strconv.Itoa(inst.ID),
inst.Name,
inst.Plan,
inst.Region,
strings.Join(inst.Tags, ","),
urlVal,
inst.HostnameExternal,
ready,
}
}
p.PrintRecords(headers, rows)
return nil
}

headers := []string{"ID", "NAME", "PLAN", "REGION"}
rows := make([][]string, len(instances))
for i, instance := range instances {
rows[i] = []string{
strconv.Itoa(instance.ID),
instance.Name,
instance.Plan,
instance.Region,
)
}
}
t.Print()
p.PrintRecords(headers, rows)

return nil
},
}

func init() {
instanceListCmd.Flags().BoolP("details", "", false, "Fetch full details for each instance (one GET request per instance)")
instanceListCmd.Flags().BoolP("show-url", "", false, "Show full connection URL with credentials (requires --details)")
}
19 changes: 11 additions & 8 deletions cmd/instance_nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ package cmd

import (
"fmt"
"os"

"cloudamqp-cli/client"
"cloudamqp-cli/internal/table"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -50,9 +48,14 @@ var instanceNodesListCmd = &cobra.Command{
return nil
}

// Create table and populate data
t := table.New(os.Stdout, "NAME", "CONFIGURED", "RUNNING", "DISK_SIZE", "RABBITMQ_VERSION")
for _, node := range nodes {
p, err := getPrinter(cmd)
if err != nil {
return err
}

headers := []string{"NAME", "CONFIGURED", "RUNNING", "DISK_SIZE", "RABBITMQ_VERSION"}
rows := make([][]string, len(nodes))
for i, node := range nodes {
configured := "No"
if node.Configured {
configured = "Yes"
Expand All @@ -62,15 +65,15 @@ var instanceNodesListCmd = &cobra.Command{
running = "Yes"
}
totalDisk := node.DiskSize + node.AdditionalDiskSize
t.AddRow(
rows[i] = []string{
node.Name,
configured,
running,
fmt.Sprintf("%d GB", totalDisk),
node.RabbitMQVersion,
)
}
}
t.Print()
p.PrintRecords(headers, rows)

return nil
},
Expand Down
17 changes: 10 additions & 7 deletions cmd/instance_plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ package cmd

import (
"fmt"
"os"

"cloudamqp-cli/client"
"cloudamqp-cli/internal/table"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -50,16 +48,21 @@ var instancePluginsListCmd = &cobra.Command{
return nil
}

// Create table and populate data
t := table.New(os.Stdout, "NAME", "ENABLED")
for _, plugin := range plugins {
p, err := getPrinter(cmd)
if err != nil {
return err
}

headers := []string{"NAME", "ENABLED"}
rows := make([][]string, len(plugins))
for i, plugin := range plugins {
enabled := "No"
if plugin.Enabled {
enabled = "Yes"
}
t.AddRow(plugin.Name, enabled)
rows[i] = []string{plugin.Name, enabled}
}
t.Print()
p.PrintRecords(headers, rows)

return nil
},
Expand Down
23 changes: 11 additions & 12 deletions cmd/plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ package cmd

import (
"fmt"
"os"

"cloudamqp-cli/client"
"cloudamqp-cli/internal/table"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -37,9 +35,14 @@ var plansCmd = &cobra.Command{
return nil
}

// Create table and populate data
t := table.New(os.Stdout, "NAME", "PRICE", "BACKEND", "SHARED")
for _, plan := range plans {
p, err := getPrinter(cmd)
if err != nil {
return err
}

headers := []string{"NAME", "PRICE", "BACKEND", "SHARED"}
rows := make([][]string, len(plans))
for i, plan := range plans {
shared := "No"
if plan.Shared {
shared = "Yes"
Expand All @@ -48,14 +51,10 @@ var plansCmd = &cobra.Command{
if plan.Price == 0 {
price = "Free"
}
t.AddRow(
plan.Name,
price,
plan.Backend,
shared,
)
rows[i] = []string{plan.Name, price, plan.Backend, shared}
}
t.Print()
p.PrintRecords(headers, rows)

return nil
},
}
Expand Down
16 changes: 10 additions & 6 deletions cmd/regions.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ package cmd

import (
"fmt"
"os"

"cloudamqp-cli/client"
"cloudamqp-cli/internal/table"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -37,11 +35,17 @@ var regionsCmd = &cobra.Command{
return nil
}

t := table.New(os.Stdout, "PROVIDER", "REGION", "NAME")
for _, region := range regions {
t.AddRow(region.Provider, region.Region, region.Name)
p, err := getPrinter(cmd)
if err != nil {
return err
}

headers := []string{"PROVIDER", "REGION", "NAME"}
rows := make([][]string, len(regions))
for i, region := range regions {
rows[i] = []string{region.Provider, region.Region, region.Name}
}
t.Print()
p.PrintRecords(headers, rows)

return nil
},
Expand Down
Loading
Loading