44package cmd
55
66import (
7- "context"
87 "encoding/json"
98 "fmt"
109 "os"
@@ -15,9 +14,8 @@ import (
1514
1615 "github.com/pterm/pterm"
1716 "github.com/snowdreamtech/unirtm/internal/config"
18- "github.com/snowdreamtech/unirtm/internal/database"
1917 "github.com/snowdreamtech/unirtm/internal/pkg/env"
20- "github.com/snowdreamtech/unirtm/internal/repository/sqlite "
18+ "github.com/snowdreamtech/unirtm/internal/provider "
2119 "github.com/spf13/cobra"
2220 "golang.org/x/term"
2321)
@@ -70,7 +68,6 @@ func runEnv(cmd *cobra.Command, args []string) error {
7068 return runEnvInfoWithStyle ()
7169 }
7270
73- ctx := context .Background ()
7471 cfg , _ := config .LoadFull ()
7572
7673 // Collect environment data
@@ -83,27 +80,78 @@ func runEnv(cmd *cobra.Command, args []string) error {
8380 var sources []string
8481 isRedacted := make (map [string ]bool )
8582
86- // Load tools from database
87- dbPath := env .GetDatabasePath ()
88- db , err := database .Open (ctx , database.Config {Path : dbPath , WALMode : true })
89- if err == nil {
90- defer db .Close ()
91- installRepo , _ := sqlite .NewInstallationRepository (db .Conn ())
92- installations , _ := installRepo .List (ctx )
93-
94- seen := make (map [string ]bool )
95- for _ , inst := range installations {
96- binDir := filepath .Join (installsDir , inst .Tool , inst .Version , "bin" )
97- if _ , statErr := os .Stat (binDir ); statErr == nil && ! seen [binDir ] {
98- pathDirs = append (pathDirs , binDir )
99- seen [binDir ] = true
83+ // Get active tools from configuration
84+ toolVersions := make (map [string ]string )
85+ if cfg != nil {
86+ for name , tc := range cfg .Tools {
87+ toolVersions [name ] = tc .Version
88+ }
89+ }
90+
91+ registry := provider .DefaultRegistry
92+ seen := make (map [string ]bool )
93+ providerEnvVars := make (map [string ]string )
94+
95+ for toolNameKey , version := range toolVersions {
96+ toolName := toolNameKey
97+ backendName := ""
98+
99+ if idx := strings .Index (toolNameKey , ":" ); idx != - 1 {
100+ backendName = toolNameKey [:idx ]
101+ toolName = toolNameKey [idx + 1 :]
102+ } else if strings .Contains (toolNameKey , "/" ) {
103+ backendName = "github"
104+ }
105+
106+ if backendName == "go" || strings .HasPrefix (toolNameKey , "go:" ) {
107+ backendName = "go-pkg"
108+ if strings .HasPrefix (toolNameKey , "go:" ) {
109+ toolName = strings .TrimPrefix (toolNameKey , "go:" )
110+ }
111+ }
112+
113+ p := registry .GetWithBackend (toolName , backendName )
114+ if p == nil {
115+ continue
116+ }
117+ fsToolName := env .GetFSToolName (toolName , backendName )
118+ installPath := filepath .Join (installsDir , fsToolName , version )
119+
120+ // Add bin paths
121+ binPaths , err := p .GetBinPaths (toolName , installPath , version )
122+ if err == nil {
123+ for _ , binDir := range binPaths {
124+ if _ , statErr := os .Stat (binDir ); statErr == nil && ! seen [binDir ] {
125+ pathDirs = append (pathDirs , binDir )
126+ seen [binDir ] = true
127+ }
128+ }
129+ }
130+
131+ // Add version variables
132+ varName := "UNIRTM_" + strings .ToUpper (strings .ReplaceAll (fsToolName , "-" , "_" )) + "_VERSION"
133+ vars = append (vars , envVarEntry {Name : varName , Value : version , Source : "tool:" + toolNameKey })
134+
135+ // Add provider env vars
136+ toolEnvVars , err := p .GetEnvVars (toolName , installPath , version )
137+ if err == nil {
138+ for k , v := range toolEnvVars {
139+ if existing , exists := providerEnvVars [k ]; ! exists {
140+ providerEnvVars [k ] = v
141+ } else if k == "NODE_PATH" {
142+ sep := string (os .PathListSeparator )
143+ if ! strings .Contains (existing + sep , v + sep ) {
144+ providerEnvVars [k ] = existing + sep + v
145+ }
146+ }
100147 }
101- // Add version variables
102- varName := "UNIRTM_" + strings .ToUpper (strings .ReplaceAll (inst .Tool , "-" , "_" )) + "_VERSION"
103- vars = append (vars , envVarEntry {Name : varName , Value : inst .Version , Source : "tool:" + inst .Tool })
104148 }
105149 }
106150
151+ for k , v := range providerEnvVars {
152+ vars = append (vars , envVarEntry {Name : k , Value : v , Source : "provider" })
153+ }
154+
107155 // Load config [env] variables
108156 if cfg != nil {
109157 resolved , src , redacted , err := cfg .ResolveEnvironment ()
0 commit comments