Skip to content

Commit 173770b

Browse files
authored
Merge pull request #399 from DefangLabs/lio-track-login-terms
track implicit login/terms events
2 parents 96f3939 + c026e57 commit 173770b

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/cmd/cli/command/commands.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,8 @@ var RootCmd = &cobra.Command{
269269
Args: cobra.NoArgs,
270270
Short: "Defang CLI manages services on the Defang cluster",
271271
PersistentPreRunE: func(cmd *cobra.Command, args []string) (err error) {
272-
// Don't track the completion commands
273-
if cmd.Name() == "__complete" || (cmd.Parent() != nil && cmd.Parent().Name() == "completion") {
272+
// Don't track/connect the completion commands
273+
if IsCompletionCommand(cmd) {
274274
return nil
275275
}
276276

@@ -338,6 +338,7 @@ var RootCmd = &cobra.Command{
338338
if connect.CodeOf(err) == connect.CodeUnauthenticated {
339339
term.Warn(" !", prettyError(err))
340340

341+
defer trackCmd(nil, "Login", P{"reason", err})
341342
if err = cli.InteractiveLogin(cmd.Context(), client, gitHubClientId, cluster); err != nil {
342343
return err
343344
}
@@ -352,6 +353,8 @@ var RootCmd = &cobra.Command{
352353
// Check if the user has agreed to the terms of service and show a prompt if needed
353354
if connect.CodeOf(err) == connect.CodeFailedPrecondition {
354355
term.Warn(" !", prettyError(err))
356+
357+
defer trackCmd(nil, "Terms", P{"reason", err})
355358
if err = cli.InteractiveAgreeToS(cmd.Context(), client); err != nil {
356359
return err
357360
}

src/cmd/cli/command/track.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,19 @@ func FlushAllTracking() {
3939
trackWG.Wait()
4040
}
4141

42+
func IsCompletionCommand(cmd *cobra.Command) bool {
43+
return cmd.Name() == cobra.ShellCompRequestCmd || (cmd.Parent() != nil && cmd.Parent().Name() == "completion")
44+
}
45+
4246
// trackCmd sends a tracking event for a Cobra command and its arguments.
4347
func trackCmd(cmd *cobra.Command, verb string, props ...P) {
44-
command := "Unknown"
48+
command := "Implicit"
4549
if cmd != nil {
46-
command = cmd.Name()
4750
// Ignore tracking for shell completion requests
48-
if command == cobra.ShellCompRequestCmd {
51+
if IsCompletionCommand(cmd) {
4952
return
5053
}
54+
command = cmd.Name()
5155
calledAs := cmd.CalledAs()
5256
cmd.VisitParents(func(c *cobra.Command) {
5357
calledAs = c.CalledAs() + " " + calledAs

0 commit comments

Comments
 (0)