@@ -10,7 +10,9 @@ import (
1010 "codacy/cli-v2/version"
1111
1212 "github.com/fatih/color"
13+ "github.com/sirupsen/logrus"
1314 "github.com/spf13/cobra"
15+ "github.com/spf13/pflag"
1416)
1517
1618var rootCmd = & cobra.Command {
@@ -24,6 +26,37 @@ var rootCmd = &cobra.Command{
2426 if err := logger .Initialize (logsDir ); err != nil {
2527 fmt .Printf ("Warning: Failed to initialize file logger: %v\n " , err )
2628 }
29+
30+ // Create a map to store all flags and their values
31+ flags := make (map [string ]string )
32+ cmd .Flags ().VisitAll (func (flag * pflag.Flag ) {
33+ if flag .Changed {
34+ // Mask sensitive values
35+ value := flag .Value .String ()
36+ switch flag .Name {
37+ case "api-token" , "repository-token" , "project-token" , "codacy-api-token" :
38+ value = "***"
39+ }
40+ flags [flag .Name ] = value
41+ }
42+ })
43+
44+ // Create a masked version of the full command for logging
45+ maskedArgs := make ([]string , len (os .Args ))
46+ copy (maskedArgs , os .Args )
47+ for i , arg := range maskedArgs {
48+ if i > 0 && (arg == "--api-token" || arg == "--repository-token" ||
49+ arg == "--project-token" || arg == "--codacy-api-token" ) && i < len (maskedArgs )- 1 {
50+ maskedArgs [i + 1 ] = "***"
51+ }
52+ }
53+
54+ // Log the command being executed with its arguments and flags
55+ logger .Info ("Executing CLI command" , logrus.Fields {
56+ "command" : cmd .Name (),
57+ "full_command" : maskedArgs ,
58+ "args" : args ,
59+ })
2760 },
2861 Run : func (cmd * cobra.Command , args []string ) {
2962 // Check if .codacy directory exists
0 commit comments