Skip to content
Open
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
30 changes: 27 additions & 3 deletions cmd/instance_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,28 @@ package cmd

import (
"fmt"
"sort"
"strconv"
"strings"

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

// formatValue formats a configuration value, avoiding scientific notation for numbers
func formatValue(value interface{}) string {
switch v := value.(type) {
case float64:
// If it's a whole number, display as integer
if v == float64(int64(v)) {
return fmt.Sprintf("%.0f", v)
}
return fmt.Sprintf("%v", v)
default:
return fmt.Sprintf("%v", v)
}
}

var instanceConfigCmd = &cobra.Command{
Use: "config",
Short: "Manage RabbitMQ configuration",
Expand Down Expand Up @@ -55,8 +70,16 @@ var instanceConfigListCmd = &cobra.Command{
fmt.Printf("%-40s %-30s\n", "---", "-----")

// Print configuration data
for key, value := range config {
valueStr := fmt.Sprintf("%v", value)
// Extract and sort keys alphabetically
keys := make([]string, 0, len(config))
for key := range config {
keys = append(keys, key)
}
sort.Strings(keys)

// Print sorted configuration
for _, key := range keys {
valueStr := formatValue(config[key])
if len(valueStr) > 30 {
valueStr = valueStr[:27] + "..."
}
Expand Down Expand Up @@ -96,7 +119,8 @@ var instanceConfigGetCmd = &cobra.Command{
}

if value, exists := config[settingName]; exists {
fmt.Printf("%s: %v\n", settingName, value)
valueStr := formatValue(value)
fmt.Printf("%s: %s\n", settingName, valueStr)
} else {
fmt.Printf("Setting '%s' not found\n", settingName)
}
Expand Down
Loading