@@ -14,6 +14,7 @@ import (
1414 "net/http"
1515 "os"
1616 "path/filepath"
17+ "strings"
1718 "time"
1819
1920 "github.com/spf13/cobra"
@@ -130,35 +131,59 @@ func createConfigurationFiles(tools []tools.Tool, cliLocalMode bool) error {
130131}
131132
132133func configFileTemplate (tools []tools.Tool ) string {
134+ // Maps to track which tools are enabled
135+ toolsMap := make (map [string ]bool )
136+ toolVersions := make (map [string ]string )
133137
134138 // Default versions
135- eslintVersion := "9.3.0"
136- trivyVersion := "0.59.1" // Latest stable version
137- pylintVersion := "3.3.6"
138- pmdVersion := "6.55.0"
139+ defaultVersions := map [string ]string {
140+ ESLint : "9.3.0" ,
141+ Trivy : "0.59.1" ,
142+ PyLint : "3.3.6" ,
143+ PMD : "6.55.0" ,
144+ }
139145
146+ // Build map of enabled tools with their versions
140147 for _ , tool := range tools {
141- switch tool .Uuid {
142- case ESLint :
143- eslintVersion = tool .Version
144- case Trivy :
145- trivyVersion = tool .Version
146- case PyLint :
147- pylintVersion = tool .Version
148- case PMD :
149- pmdVersion = tool .Version
148+ toolsMap [tool .Uuid ] = true
149+ if tool .Version != "" {
150+ toolVersions [tool .Uuid ] = tool .Version
151+ } else {
152+ toolVersions [tool .Uuid ] = defaultVersions [tool .Uuid ]
153+ }
154+ }
155+
156+ // Start building the YAML content
157+ var sb strings.Builder
158+ sb .WriteString ("runtimes:\n " )
159+ sb .
WriteString (
" - [email protected] \n " )
160+ sb .
WriteString (
" - [email protected] \n " )
161+ sb .WriteString ("tools:\n " )
162+
163+ // If we have tools from the API (enabled tools), use only those
164+ if len (tools ) > 0 {
165+ // Add only the tools that are in the API response (enabled tools)
166+ uuidToName := map [string ]string {
167+ ESLint : "eslint" ,
168+ Trivy : "trivy" ,
169+ PyLint : "pylint" ,
170+ PMD : "pmd" ,
150171 }
172+
173+ for uuid , name := range uuidToName {
174+ if toolsMap [uuid ] {
175+ sb .WriteString (fmt .Sprintf (" - %s@%s\n " , name , toolVersions [uuid ]))
176+ }
177+ }
178+ } else {
179+ // If no tools were specified (local mode), include all defaults
180+ sb .WriteString (fmt .Sprintf (" - eslint@%s\n " , defaultVersions [ESLint ]))
181+ sb .WriteString (fmt .Sprintf (" - trivy@%s\n " , defaultVersions [Trivy ]))
182+ sb .WriteString (fmt .Sprintf (" - pylint@%s\n " , defaultVersions [PyLint ]))
183+ sb .WriteString (fmt .Sprintf (" - pmd@%s\n " , defaultVersions [PMD ]))
151184 }
152185
153- return fmt .Sprintf (`runtimes:
154- 155- 156- tools:
157- - eslint@%s
158- - trivy@%s
159- - pylint@%s
160- - pmd@%s
161- ` , eslintVersion , trivyVersion , pylintVersion , pmdVersion )
186+ return sb .String ()
162187}
163188
164189func cliConfigFileTemplate (cliLocalMode bool ) string {
0 commit comments