Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: track help cmd #245

Merged
merged 3 commits into from
May 7, 2024
Merged

feat: track help cmd #245

merged 3 commits into from
May 7, 2024

Conversation

dbolson
Copy link
Contributor

@dbolson dbolson commented May 6, 2024

Send analytics when showing help, either when the user asks (--help) or if it's an error and we show the help.

Here are example inputs with their respective analytics output:

go run . projects
go run . projects --help
CLI Command Run map[action:help baseURI:http://localhost:3000 flags:[help] name:projects]

go run . projects list --help
CLI Command Run map[action:help baseURI:http://localhost:3000 flags:[help] name:projects]

go run . projects list
CLI Command Run map[action:list baseURI:http://localhost:3000 flags:[access-token analytics-opt-out base-uri output] name:projects]

go run . config
go run . config --help
CLI Command Run map[action:help baseURI:http://localhost:3000 flags:[] name:config]
CLI Command Run map[action:help baseURI:http://localhost:3000 flags:[help] name:config]

These also send "CLI Command Completed" with an outcome of "help."

Requirements

  • I have added test coverage for new or changed functionality
  • I have followed the repository's pull request submission guidelines
  • I have validated my changes against all supported platform versions

Related issues

Provide links to any issues in this repository or elsewhere relating to this pull request.

Describe the solution you've provided

Provide a clear and concise description of what you expect to happen.

Describe alternatives you've considered

Provide a clear and concise description of any alternative solutions or features you've considered.

Additional context

Add any other context about the pull request here.

func CmdRunEventProperties(
cmd *cobra.Command,
name string,
overrides map[string]interface{},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add overrides so we can pass in an optional "action: help". We could make this functional options if we want to use it for more than the one-off case this introduces.

cmdAnalytics.CmdRunEventProperties(cmd, "config"),
)
// only track event if there are flags
if len(os.Args[1:]) > 1 {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if there's a better way to do this. Since we define config --list/--set/--unset with no action, we only want to send this if we're not showing help.

@@ -53,6 +56,19 @@ func NewConfigCmd(analyticsTracker analytics.Tracker) *cobra.Command {
sb.WriteString(fmt.Sprintf("- `%s`: %s\n", s, cliflags.AllFlagsHelp()[s]))
}
cmd.Long += sb.String()

analyticsTracker.SendCommandRunEvent(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is similar to what we do in the root command.

// getResourceCommand returns the command for a resource or an action's parent resource.
// ldcli projects // returns projects command
// ldcli projects list // returns projects command
func getResourceCommand(c *cobra.Command) *cobra.Command {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need this since a user could call help in various ways.

ID string
HTTPClient *http.Client
Version string
sentHelpEvent bool
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to keep state here to know if we already tracked a help event.

@dbolson dbolson requested a review from k3llymariee May 6, 2024 20:18
@dbolson dbolson merged commit 1ebc398 into main May 7, 2024
2 checks passed
@dbolson dbolson deleted the sc-241690/track-help-cmd branch May 7, 2024 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants