@@ -260,6 +260,23 @@ func getToolName(toolName string, version string) string {
260260 return toolName
261261}
262262
263+ func validateToolName (toolName string ) error {
264+ if toolName == "" {
265+ return fmt .Errorf ("tool name cannot be empty" )
266+ }
267+
268+ // Get plugin manager to access the tools filesystem
269+ pluginManager := plugins .GetPluginManager ()
270+
271+ // Try to get the tool configuration - this will fail if the tool doesn't exist
272+ _ , err := pluginManager .GetToolConfig (toolName )
273+ if err != nil {
274+ return fmt .Errorf ("tool '%s' is not supported" , toolName )
275+ }
276+
277+ return nil
278+ }
279+
263280func runToolByTooName (toolName string , workDirectory string , pathsToCheck []string , autoFix bool , outputFile string , outputFormat string , tool * plugins.ToolInfo , runtime * plugins.RuntimeInfo ) error {
264281 switch toolName {
265282 case "eslint" :
@@ -291,7 +308,14 @@ func runToolByTooName(toolName string, workDirectory string, pathsToCheck []stri
291308 return fmt .Errorf ("unsupported tool: %s" , toolName )
292309}
293310
294- func genericRunTool (toolName string , workDirectory string , pathsToCheck []string , autoFix bool , outputFile string , outputFormat string ) error {
311+ func runTool (workDirectory string , toolName string , pathsToCheck []string , outputFile string , autoFix bool , outputFormat string ) error {
312+ err := validateToolName (toolName )
313+ if err != nil {
314+ return err
315+ }
316+ log .Println ("Running tools for the specified file(s)..." )
317+ log .Printf ("Running %s...\n " , toolName )
318+
295319 tool := config .Config .Tools ()[toolName ]
296320 var isToolInstalled bool
297321 if tool == nil {
@@ -302,6 +326,11 @@ func genericRunTool(toolName string, workDirectory string, pathsToCheck []string
302326 var isRuntimeInstalled bool
303327
304328 var runtime * plugins.RuntimeInfo
329+
330+ if toolName == "codacy-enigma-cli" {
331+ isToolInstalled = true
332+ }
333+
305334 if tool == nil || ! isToolInstalled {
306335 fmt .Println ("Tool configuration not found, adding and installing..." )
307336 err := config .InstallTool (toolName , tool , "" )
@@ -369,8 +398,6 @@ var analyzeCmd = &cobra.Command{
369398 return
370399 }
371400
372- log .Println ("Running tools for the specified file(s)..." )
373-
374401 if outputFormat == "sarif" {
375402 // Create temporary directory for individual tool outputs
376403 tmpDir , err := os .MkdirTemp ("" , "codacy-analysis-*" )
@@ -381,10 +408,9 @@ var analyzeCmd = &cobra.Command{
381408
382409 var sarifOutputs []string
383410 for toolName := range toolsToRun {
384- log .Printf ("Running %s...\n " , toolName )
385411 tmpFile := filepath .Join (tmpDir , fmt .Sprintf ("%s.sarif" , toolName ))
386- if err := runTool (workDirectory , toolName , args , tmpFile ); err != nil {
387- log .Printf ("Tool failed to run: %s: % v\n " , toolName , err )
412+ if err := runTool (workDirectory , toolName , args , tmpFile , autoFix , outputFormat ); err != nil {
413+ log .Printf ("Tool failed to run: %v\n " , err )
388414 }
389415 sarifOutputs = append (sarifOutputs , tmpFile )
390416 }
@@ -418,19 +444,10 @@ var analyzeCmd = &cobra.Command{
418444 } else {
419445 // Run tools without merging outputs
420446 for toolName := range toolsToRun {
421- log .Printf ("Running %s...\n " , toolName )
422- if err := runTool (workDirectory , toolName , args , outputFile ); err != nil {
423- log .Printf ("Tool failed to run: %s: %v\n " , toolName , err )
447+ if err := runTool (workDirectory , toolName , args , outputFile , autoFix , outputFormat ); err != nil {
448+ log .Printf ("Tool failed to run: %v\n " , err )
424449 }
425450 }
426451 }
427452 },
428453}
429-
430- func runTool (workDirectory string , toolName string , args []string , outputFile string ) error {
431- err := genericRunTool (toolName , workDirectory , args , autoFix , outputFile , outputFormat )
432- if err != nil {
433- return err
434- }
435- return nil
436- }
0 commit comments