Skip to content

Commit 8a2915d

Browse files
CalvinAllenclaude
andcommitted
feat(list): show all runtimes without argument and indicate global version
- Make runtime argument optional for list command - Show all installed versions grouped by runtime when no argument given - Display "(global)" indicator next to the global default version - Maintain backward compatibility with `dtvem list <runtime>` Fixes #54 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent cc82c20 commit 8a2915d

1 file changed

Lines changed: 74 additions & 19 deletions

File tree

src/cmd/list.go

Lines changed: 74 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,41 +7,96 @@ import (
77
)
88

99
var listCmd = &cobra.Command{
10-
Use: "list <runtime>",
11-
Short: "List installed versions of a runtime",
12-
Long: `List all installed versions of a specific runtime.
10+
Use: "list [runtime]",
11+
Short: "List installed versions",
12+
Long: `List all installed versions of a specific runtime, or all runtimes if none specified.
1313
1414
Examples:
15-
dtvem list python
16-
dtvem list node`,
17-
Args: cobra.ExactArgs(1),
15+
dtvem list # List all installed versions
16+
dtvem list python # List installed Python versions
17+
dtvem list node # List installed Node.js versions`,
18+
Args: cobra.MaximumNArgs(1),
1819
Run: func(cmd *cobra.Command, args []string) {
19-
runtimeName := args[0]
20-
21-
provider, err := runtime.Get(runtimeName)
22-
if err != nil {
23-
ui.Error("%v", err)
24-
ui.Info("Available runtimes: %v", runtime.List())
25-
return
20+
if len(args) == 0 {
21+
listAllRuntimes()
22+
} else {
23+
listSingleRuntime(args[0])
2624
}
25+
},
26+
}
27+
28+
// listAllRuntimes lists installed versions for all runtimes
29+
func listAllRuntimes() {
30+
providers := runtime.GetAll()
2731

28-
ui.Header("Installed %s versions:", provider.DisplayName())
32+
if len(providers) == 0 {
33+
ui.Info("No runtime providers registered")
34+
return
35+
}
2936

37+
ui.Header("Installed versions:")
38+
39+
hasAny := false
40+
for _, provider := range providers {
3041
versions, err := provider.ListInstalled()
3142
if err != nil {
32-
ui.Error("%v", err)
33-
return
43+
ui.Error(" %s: %v", provider.DisplayName(), err)
44+
continue
3445
}
3546

3647
if len(versions) == 0 {
37-
ui.Info("No versions installed")
38-
return
48+
continue
3949
}
4050

51+
hasAny = true
52+
globalVersion, _ := provider.GlobalVersion()
53+
54+
ui.Printf(" %s:\n", ui.Highlight(provider.DisplayName()))
4155
for _, v := range versions {
56+
if v.String() == globalVersion {
57+
ui.Printf(" %s (global)\n", ui.HighlightVersion(v.String()))
58+
} else {
59+
ui.Printf(" %s\n", ui.HighlightVersion(v.String()))
60+
}
61+
}
62+
}
63+
64+
if !hasAny {
65+
ui.Info("No versions installed")
66+
}
67+
}
68+
69+
// listSingleRuntime lists installed versions for a specific runtime
70+
func listSingleRuntime(runtimeName string) {
71+
provider, err := runtime.Get(runtimeName)
72+
if err != nil {
73+
ui.Error("%v", err)
74+
ui.Info("Available runtimes: %v", runtime.List())
75+
return
76+
}
77+
78+
ui.Header("Installed %s versions:", provider.DisplayName())
79+
80+
versions, err := provider.ListInstalled()
81+
if err != nil {
82+
ui.Error("%v", err)
83+
return
84+
}
85+
86+
if len(versions) == 0 {
87+
ui.Info("No versions installed")
88+
return
89+
}
90+
91+
globalVersion, _ := provider.GlobalVersion()
92+
93+
for _, v := range versions {
94+
if v.String() == globalVersion {
95+
ui.Printf(" %s (global)\n", ui.HighlightVersion(v.String()))
96+
} else {
4297
ui.Printf(" %s\n", ui.HighlightVersion(v.String()))
4398
}
44-
},
99+
}
45100
}
46101

47102
func init() {

0 commit comments

Comments
 (0)