Skip to content

Commit

Permalink
Add new logging
Browse files Browse the repository at this point in the history
  • Loading branch information
tothszabi committed Sep 9, 2024
1 parent b9d824b commit 16991c5
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions cli/command_analytics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package cli

import (
"fmt"
"strings"

"github.com/bitrise-io/bitrise/analytics"
"github.com/urfave/cli"
)

var globalTracker analytics.Tracker

func logPluginCommandParameters(name string, _ []string) {
// Plugin command parameters are routed into the function but are not processed yet because it is complex to correctly
// parse the arguments without knowing the structure. If we notice that our users do use plugins, then we can add
// plugin specific argument parsers.
sendCommandInfo(fmt.Sprintf(":%s", name), "", []string{})
}

func logSubcommandParameters(c *cli.Context) {
if c == nil {
return
}

commandName := "unknown"
subcommandName := "unknown"

if names := strings.Split(c.Command.FullName(), " "); len(names) == 2 {
commandName = names[0]
subcommandName = names[1]
}

flags := collectFlags(c)

sendCommandInfo(commandName, subcommandName, flags)
}

func logCommandParameters(c *cli.Context) {
if c == nil {
return
}

flags := collectFlags(c)

sendCommandInfo(c.Command.Name, "", flags)
}

func collectFlags(c *cli.Context) []string {
var flags []string

for _, flag := range c.FlagNames() {
if isSet := c.IsSet(flag); isSet {
flags = append(flags, flag)
}
}

for _, flag := range c.GlobalFlagNames() {
if isSet := c.GlobalIsSet(flag); isSet {
flags = append(flags, flag)
}
}

return flags
}

func sendCommandInfo(command, subcommand string, flags []string) {
fmt.Printf("Command name: %s, subcommand: %s, flags: %s\n", command, subcommand, flags)

globalTracker.SendCommandInfo(command, subcommand, flags)
}

0 comments on commit 16991c5

Please sign in to comment.