|
9 | 9 | "sort" |
10 | 10 | "strings" |
11 | 11 |
|
| 12 | + "codacy/cli-v2/cmd/cmdutils" |
12 | 13 | "codacy/cli-v2/cmd/configsetup" |
13 | 14 | codacyclient "codacy/cli-v2/codacy-client" |
14 | 15 | "codacy/cli-v2/config" |
@@ -258,15 +259,38 @@ func detectLanguagesInPath(rootPath string, toolLangMap map[string]domain.ToolLa |
258 | 259 | return nil, fmt.Errorf("failed to detect file extensions in path %s: %w", rootPath, err) |
259 | 260 | } |
260 | 261 |
|
261 | | - // Map extensions to languages |
| 262 | + // Map only found extensions to languages |
262 | 263 | for ext := range extCount { |
263 | 264 | if langs, ok := extToLang[ext]; ok { |
| 265 | + // Log which extensions map to which languages for debugging |
| 266 | + logger.Debug("Found files with extension", logrus.Fields{ |
| 267 | + "extension": ext, |
| 268 | + "count": extCount[ext], |
| 269 | + "languages": langs, |
| 270 | + }) |
264 | 271 | for _, lang := range langs { |
265 | 272 | detectedLangs[lang] = struct{}{} |
266 | 273 | } |
267 | 274 | } |
268 | 275 | } |
269 | 276 |
|
| 277 | + // Log the final set of detected languages with their corresponding extensions |
| 278 | + if len(detectedLangs) > 0 { |
| 279 | + langToExts := make(map[string][]string) |
| 280 | + for ext, count := range extCount { |
| 281 | + if langs, ok := extToLang[ext]; ok { |
| 282 | + for _, lang := range langs { |
| 283 | + langToExts[lang] = append(langToExts[lang], fmt.Sprintf("%s (%d files)", ext, count)) |
| 284 | + } |
| 285 | + } |
| 286 | + } |
| 287 | + |
| 288 | + logger.Debug("Detected languages in path", logrus.Fields{ |
| 289 | + "languages_with_files": langToExts, |
| 290 | + "path": discoverPath, |
| 291 | + }) |
| 292 | + } |
| 293 | + |
270 | 294 | return detectedLangs, nil |
271 | 295 | } |
272 | 296 |
|
@@ -623,22 +647,13 @@ func getRecognizableExtensions(extCount map[string]int, toolLangMap map[string]d |
623 | 647 | } |
624 | 648 |
|
625 | 649 | func init() { |
626 | | - // Define flags for the config reset command. These are the same flags used by the init command. |
627 | | - configResetCmd.Flags().StringVar(&configResetInitFlags.ApiToken, "api-token", "", "Optional Codacy API token. If defined, configurations will be fetched from Codacy.") |
628 | | - configResetCmd.Flags().StringVar(&configResetInitFlags.Provider, "provider", "", "Provider (e.g., gh, bb, gl) to fetch configurations from Codacy. Required when api-token is provided.") |
629 | | - configResetCmd.Flags().StringVar(&configResetInitFlags.Organization, "organization", "", "Remote organization name to fetch configurations from Codacy. Required when api-token is provided.") |
630 | | - configResetCmd.Flags().StringVar(&configResetInitFlags.Repository, "repository", "", "Remote repository name to fetch configurations from Codacy. Required when api-token is provided.") |
631 | | - |
632 | | - // Add the reset subcommand to the config command |
633 | | - configCmd.AddCommand(configResetCmd) |
634 | | - // Add the discover subcommand to the config command |
635 | | - configCmd.AddCommand(configDiscoverCmd) |
636 | | - // Add the config command to the root command |
637 | | - rootCmd.AddCommand(configCmd) |
| 650 | + // Add cloud-related flags to both commands |
| 651 | + cmdutils.AddCloudFlags(configResetCmd, &configResetInitFlags) |
| 652 | + cmdutils.AddCloudFlags(configDiscoverCmd, &configResetInitFlags) |
638 | 653 |
|
639 | | - // Add cloud-related flags to the discover command |
640 | | - configDiscoverCmd.Flags().StringVar(&configResetInitFlags.ApiToken, "api-token", "", "Optional Codacy API token. If defined, configurations will be fetched from Codacy.") |
641 | | - configDiscoverCmd.Flags().StringVar(&configResetInitFlags.Provider, "provider", "", "Provider (e.g., gh, bb, gl) to fetch configurations from Codacy. Required when api-token is provided.") |
642 | | - configDiscoverCmd.Flags().StringVar(&configResetInitFlags.Organization, "organization", "", "Remote organization name to fetch configurations from Codacy. Required when api-token is provided.") |
643 | | - configDiscoverCmd.Flags().StringVar(&configResetInitFlags.Repository, "repository", "", "Remote repository name to fetch configurations from Codacy. Required when api-token is provided.") |
| 654 | + // Add subcommands to config command |
| 655 | + configCmd.AddCommand(configResetCmd, configDiscoverCmd) |
| 656 | + |
| 657 | + // Add config command to root |
| 658 | + rootCmd.AddCommand(configCmd) |
644 | 659 | } |
0 commit comments