Skip to content
21 changes: 17 additions & 4 deletions cmd/devenv/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,11 +309,24 @@ func printConfigSummary(cfg *config.DevEnvConfig) {
fmt.Printf(" Git: %s <%s>\n", cfg.Git.Name, cfg.Git.Email)
}

if cfg.Resources.CPU != nil || cfg.Resources.Memory != "" {
cpuStr := formatCPU(cfg.Resources.CPU)
fmt.Printf(" Resources: CPU=%s, Memory=%s, GPU=%d\n",
cpuStr, cfg.Resources.Memory, cfg.Resources.GPU)
cpuStr := cfg.CPU() // e.g., "4000m" or "0"
memStr := cfg.Memory() // e.g., "16Gi" or ""

hasCPU := cpuStr != "0"
hasMem := memStr != ""

if hasCPU || hasMem {
fmt.Printf(" Resources:")
if hasCPU {
fmt.Printf(" CPU=%s", cpuStr)
}
if hasMem {
if hasCPU {
fmt.Printf(",")
}
fmt.Printf(" Memory=%s", memStr)
}
fmt.Println()
}

if len(cfg.Volumes) > 0 {
Expand Down
82 changes: 3 additions & 79 deletions internal/config/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,91 +25,15 @@ func ExampleLoadDeveloperConfig() {
// Access SSH keys
sshKeys, err := cfg.GetSSHKeys()
if err != nil {
log.Fatal(err)
fmt.Println("error:", err)
return
}
fmt.Printf("SSH Keys: %d configured\n", len(sshKeys))

// Output:
// Developer: testuser
// CPU: 4
// CPU: 4000m
// Memory: 16Gi
// User ID: 2000
// SSH Keys: 1 configured
}

// ExampleDevEnvConfig_CPU demonstrates flexible CPU resource handling
// with different input types and default values.
func ExampleDevEnvConfig_CPU() {
// Example with string CPU value
cfg1 := &config.DevEnvConfig{
Name: "alice",
BaseConfig: config.BaseConfig{
Resources: config.ResourceConfig{
CPU: "8", // String value
},
},
}
fmt.Printf("String CPU: %s\n", cfg1.CPU())

// Example with integer CPU value
cfg2 := &config.DevEnvConfig{
Name: "bob",
BaseConfig: config.BaseConfig{
Resources: config.ResourceConfig{
CPU: 4, // Integer value
},
},
}
fmt.Printf("Integer CPU: %s\n", cfg2.CPU())

// Example with no CPU specified (uses default)
cfg3 := &config.DevEnvConfig{
Name: "charlie",
// No Resources specified
}
fmt.Printf("Default CPU: %s\n", cfg3.CPU())

// Output:
// String CPU: 8
// Integer CPU: 4
// Default CPU: 0
}

// ExampleDevEnvConfig_GetSSHKeys demonstrates SSH key handling with
// both single string and multiple string array formats.
func ExampleDevEnvConfig_GetSSHKeys() {
// Single SSH key as string
cfg1 := &config.DevEnvConfig{
Name: "alice",
BaseConfig: config.BaseConfig{
SSHPublicKey: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQAB [email protected]",
},
}

keys1, err := cfg1.GetSSHKeys()
if err != nil {
log.Fatal(err)
}
fmt.Printf("Single key: %d SSH key(s)\n", len(keys1))

// Multiple SSH keys as slice
cfg2 := &config.DevEnvConfig{
Name: "bob",
BaseConfig: config.BaseConfig{
SSHPublicKey: []interface{}{
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQAB [email protected]",
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI [email protected]",
},
},
}

keys2, err := cfg2.GetSSHKeys()
if err != nil {
log.Fatal(err)
}
fmt.Printf("Multiple keys: %d SSH key(s)\n", len(keys2))

// Output:
// Single key: 1 SSH key(s)
// Multiple keys: 2 SSH key(s)
}
Loading