Skip to content

Commit 37629c1

Browse files
committed
Rename to idiomatic-go: commandWithTelemetry
1 parent 0f3d6eb commit 37629c1

File tree

7 files changed

+9
-9
lines changed

7 files changed

+9
-9
lines changed

.claude/skills/add-command/SKILL.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ Create `test/integration/<name>_test.go` with:
9696

9797
## Telemetry
9898

99-
Every new command must emit an `lstk_command` telemetry event. Wrap the command's `RunE` with `withCommandTelemetry(name, tel, func() string { return cfg.AuthToken }, fn)` — this handles timing, exit code, and error message automatically. The token resolver is called after the command runs, allowing commands like `login` to resolve the post-execution token.
99+
Every new command must emit an `lstk_command` telemetry event. Wrap the command's `RunE` with `commandWithTelemetry(name, tel, func() string { return cfg.AuthToken }, fn)` — this handles timing, exit code, and error message automatically. The token resolver is called after the command runs, allowing commands like `login` to resolve the post-execution token.
100100

101-
Start and stop are exceptions: they emit `lstk_lifecycle` events in addition to `lstk_command`, so they manage their own telemetry manually instead of using `withCommandTelemetry`.
101+
Start and stop are exceptions: they emit `lstk_lifecycle` events in addition to `lstk_command`, so they manage their own telemetry manually instead of using `commandWithTelemetry`.
102102

103103
## Anti-patterns to avoid
104104

cmd/login.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func newLoginCmd(cfg *env.Env, tel *telemetry.Client, logger log.Logger) *cobra.
1919
Short: "Manage login",
2020
Long: "Manage login and store credentials in system keyring",
2121
PreRunE: initConfig,
22-
RunE: withCommandTelemetry("login", tel, func() string {
22+
RunE: commandWithTelemetry("login", tel, func() string {
2323
tokenStorage, err := auth.NewTokenStorage(cfg.ForceFileKeyring, logger)
2424
if err != nil {
2525
return cfg.AuthToken

cmd/logout.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func newLogoutCmd(cfg *env.Env, tel *telemetry.Client, logger log.Logger) *cobra
2323
Use: "logout",
2424
Short: "Remove stored authentication credentials",
2525
PreRunE: initConfig,
26-
RunE: withCommandTelemetry("logout", tel, func() string { return cfg.AuthToken }, func(cmd *cobra.Command, args []string) error {
26+
RunE: commandWithTelemetry("logout", tel, func() string { return cfg.AuthToken }, func(cmd *cobra.Command, args []string) error {
2727
platformClient := api.NewPlatformClient(cfg.APIEndpoint, logger)
2828
appConfig, err := config.Get()
2929
if err != nil {

cmd/logs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func newLogsCmd(cfg *env.Env, tel *telemetry.Client) *cobra.Command {
1919
Short: "Show emulator logs",
2020
Long: "Show logs from the emulator. Use --follow to stream in real-time.",
2121
PreRunE: initConfig,
22-
RunE: withCommandTelemetry("logs", tel, func() string { return cfg.AuthToken }, func(cmd *cobra.Command, args []string) error {
22+
RunE: commandWithTelemetry("logs", tel, func() string { return cfg.AuthToken }, func(cmd *cobra.Command, args []string) error {
2323
follow, err := cmd.Flags().GetBool("follow")
2424
if err != nil {
2525
return err

cmd/root.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,11 @@ func runStart(cmd *cobra.Command, rt runtime.Runtime, cfg *env.Env, tel *telemet
153153
return runErr
154154
}
155155

156-
// withCommandTelemetry wraps a RunE function so that an lstk_command event is
156+
// commandWithTelemetry wraps a RunE function so that an lstk_command event is
157157
// emitted after every invocation. Use this for commands that do not emit
158158
// lstk_lifecycle events (i.e. everything except start/stop, which manage their
159159
// own telemetry).
160-
func withCommandTelemetry(name string, tel *telemetry.Client, resolveAuthToken func() string, fn func(*cobra.Command, []string) error) func(*cobra.Command, []string) error {
160+
func commandWithTelemetry(name string, tel *telemetry.Client, resolveAuthToken func() string, fn func(*cobra.Command, []string) error) func(*cobra.Command, []string) error {
161161
return func(cmd *cobra.Command, args []string) error {
162162
startTime := time.Now()
163163
runErr := fn(cmd, args)

cmd/status.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func newStatusCmd(cfg *env.Env, tel *telemetry.Client) *cobra.Command {
2222
Short: "Show emulator status and deployed resources",
2323
Long: "Show the status of a running emulator and its deployed resources",
2424
PreRunE: initConfig,
25-
RunE: withCommandTelemetry("status", tel, func() string { return cfg.AuthToken }, func(cmd *cobra.Command, args []string) error {
25+
RunE: commandWithTelemetry("status", tel, func() string { return cfg.AuthToken }, func(cmd *cobra.Command, args []string) error {
2626
rt, err := runtime.NewDockerRuntime(cfg.DockerHost)
2727
if err != nil {
2828
return err

cmd/update.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func newUpdateCmd(cfg *env.Env, tel *telemetry.Client) *cobra.Command {
1919
Short: "Update lstk to the latest version",
2020
Long: "Check for and apply updates to the lstk CLI. Respects the original installation method (Homebrew, npm, or direct binary).",
2121
PreRunE: initConfig,
22-
RunE: withCommandTelemetry("update", tel, func() string { return cfg.AuthToken }, func(cmd *cobra.Command, args []string) error {
22+
RunE: commandWithTelemetry("update", tel, func() string { return cfg.AuthToken }, func(cmd *cobra.Command, args []string) error {
2323
if isInteractiveMode(cfg) {
2424
return ui.RunUpdate(cmd.Context(), checkOnly, cfg.GitHubToken)
2525
}

0 commit comments

Comments
 (0)