Skip to content

Commit 33d5831

Browse files
committed
chore(lang): align registry behavior with template registry
- Implement sort.Strings in ListLangs for deterministic CLI output - Add Register function to allow language handler injection - Rename parameters to avoid package name shadowing - Ensure structural parity between pkg/lang and pkg/templates
1 parent 41ca111 commit 33d5831

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

pkg/lang/registry.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ package lang
66

77
import (
88
"fmt"
9+
"sort"
10+
911
"scbake/internal/types"
1012
golang "scbake/pkg/lang/go"
1113
"scbake/pkg/lang/spring"
@@ -18,27 +20,33 @@ type Handler interface {
1820
GetTasks(targetPath string) ([]types.Task, error)
1921
}
2022

21-
// Map of all available language handlers.
23+
// handlers Map of all available language handlers.
2224
var handlers = map[string]Handler{
2325
"go": &golang.Handler{},
2426
"svelte": &svelte.Handler{},
2527
"spring": &spring.Handler{},
2628
}
2729

30+
// Register allows external packages or tests to inject custom language handlers.
31+
func Register(name string, h Handler) {
32+
handlers[name] = h
33+
}
34+
2835
// GetHandler returns the correct language handler for the given string.
29-
func GetHandler(lang string) (Handler, error) {
30-
handler, ok := handlers[lang]
36+
func GetHandler(langName string) (Handler, error) {
37+
handler, ok := handlers[langName]
3138
if !ok {
32-
return nil, fmt.Errorf("unknown language: %s", lang)
39+
return nil, fmt.Errorf("unknown language: %s", langName)
3340
}
3441
return handler, nil
3542
}
3643

37-
// ListLangs returns the names of all supported languages.
44+
// ListLangs returns the sorted names of all supported languages.
3845
func ListLangs() []string {
3946
keys := make([]string, 0, len(handlers))
4047
for k := range handlers {
4148
keys = append(keys, k)
4249
}
50+
sort.Strings(keys)
4351
return keys
4452
}

0 commit comments

Comments
 (0)