refactor: remove legacy CLIVersion field and SetVersion() function#429
refactor: remove legacy CLIVersion field and SetVersion() function#429
Conversation
The CLIVersion field and SetVersion functional option on ClientFactory were a workaround for a circular dependency that no longer exists. The API client reads version from context via slackcontext.Version(ctx), making this indirection unnecessary. Replace with direct version.Raw() calls.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #429 +/- ##
==========================================
- Coverage 70.24% 70.21% -0.04%
==========================================
Files 220 220
Lines 18446 18444 -2
==========================================
- Hits 12957 12950 -7
- Misses 4317 4318 +1
- Partials 1172 1176 +4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
mwbrooks
left a comment
There was a problem hiding this comment.
A few comments for those reviewers eager to see the Slack CLI code improve little by little.
|
|
||
| // Init clients that use flags | ||
| clients.Config.APIHostResolved = clients.Auth().ResolveAPIHost(ctx, clients.Config.APIHostFlag, nil) | ||
| clients.Config.LogstashHostResolved = clients.Auth().ResolveLogstashHost(ctx, clients.Config.APIHostResolved, clients.CLIVersion) |
There was a problem hiding this comment.
note: clients.CLIVersion was set to version.Raw().
| clients.Config.LoadExperiments(ctx, clients.IO.PrintDebug) | ||
| style.ToggleLipgloss(clients.Config.WithExperimentOn(experiment.Lipgloss)) | ||
| // TODO(slackcontext) Consolidate storing CLI version to slackcontext | ||
| clients.Config.Version = clients.CLIVersion |
There was a problem hiding this comment.
note: clients.CLIVersion was set to version.Raw().
| // TODO: Temporary hack to get around circular dependency in internal/api/client.go since that imports version | ||
| // Follows pattern demonstrated by the GitHub CLI here https://github.com/cli/cli/blob/5a46c1cab601a3394caa8de85adb14f909b811e9/pkg/cmd/factory/default.go#L29 | ||
| // Used by the APIClient for its userAgent | ||
| // Currently needed because trying to get the version of the CLI from pkg/version/version.go would cause a circular dependency | ||
| // We can get rid of this once we refactor the code relationship between pkg/ and internal/ | ||
| // userAgent can get Slack CLI version from context which is defined in main.go, this approach bypass circular dependency. The clients.CLIVersion is retained for future code refactor purpose and serve SetVersion function | ||
| clients.CLIVersion = "" | ||
|
|
There was a problem hiding this comment.
🌲 praise: This has bothered me more than I understood. Thanks for making change that improves the code @mwbrooks!
| var clients = shared.NewClientFactory() | ||
| clients.Config.Version = version.Raw() |
There was a problem hiding this comment.
thought: I still don't like that we're setting the version in multiple places, instead of just referencing the source of truth (version.Raw() or version.Get()). However, I think this PR is a step toward simpler code with fewer indirect references. We can follow-up further in more PRs if we want.
There was a problem hiding this comment.
🔭 thought: For this panic catching I think it's alright to forgive some duplication and strange logic.
🌟 praise: Thanks for catching this in these updates still!
zimeg
left a comment
There was a problem hiding this comment.
📚 Amazing changes to start the week with! Thanks for untangling some of the more intricate logic here. I left a few notes of optional reading!
| var clients = shared.NewClientFactory() | ||
| clients.Config.Version = version.Raw() |
There was a problem hiding this comment.
🔭 thought: For this panic catching I think it's alright to forgive some duplication and strange logic.
🌟 praise: Thanks for catching this in these updates still!
| style.ToggleLipgloss(clients.Config.WithExperimentOn(experiment.Lipgloss)) | ||
| // TODO(slackcontext) Consolidate storing CLI version to slackcontext | ||
| clients.Config.Version = clients.CLIVersion | ||
| clients.Config.Version = version.Raw() |
There was a problem hiding this comment.
🔍 thought(non-blocking): Would setting this version above - before L268 above - let us reuse the configuration version instead of calling to the version package twice?
👾 ramble: I'm unsure if this value is set here due to dependencies above, but I might expect the version to remain stable during execution here!
There was a problem hiding this comment.
🗣️ ramble: Forgive me if the TODO of "slackcontext" above is meant to capture similar changes!
| // TODO: Temporary hack to get around circular dependency in internal/api/client.go since that imports version | ||
| // Follows pattern demonstrated by the GitHub CLI here https://github.com/cli/cli/blob/5a46c1cab601a3394caa8de85adb14f909b811e9/pkg/cmd/factory/default.go#L29 | ||
| // Used by the APIClient for its userAgent | ||
| // Currently needed because trying to get the version of the CLI from pkg/version/version.go would cause a circular dependency | ||
| // We can get rid of this once we refactor the code relationship between pkg/ and internal/ | ||
| // userAgent can get Slack CLI version from context which is defined in main.go, this approach bypass circular dependency. The clients.CLIVersion is retained for future code refactor purpose and serve SetVersion function | ||
| clients.CLIVersion = "" | ||
|
|
There was a problem hiding this comment.
🌲 praise: This has bothered me more than I understood. Thanks for making change that improves the code @mwbrooks!
Changelog
Summary
This pull request removes the legacy version references from
ClientFactory, including theClientFactory.CLIVersionfield andshared.SetVersion()function.CLIVersionfield fromClientFactory.SetVersion()functional fromClientFactory.TODOcomment referencing a circular dependency that no longer exists. This was solved byslackcontext.Version(ctx).clients.CLIVersion) with directversion.Raw()calls. Theclients.CLIVersionwas previously set to the raw version value, so the functionality is unchanged.Context:
The
ClientFactory.CLIVersionandshared.SetVersion()were a workaround for a circular dependency betweeninternal/api/client.goandpackage version. That dependency no longer exists -internal/api/client.godoes not import the version package and the API client now reads the CLI version from context withslackcontext.Version(ctx).Open Questions:
logincommand in our Test Steps.Test Steps
1. Test Version:
2. Test Version Override with Environment Variable:
$ SLACK_TEST_VERSION=v0.0.1 lack version # → Expect: "Using slack v0.0.1"3. Test Doctor Command (confirms
Config.Versionis set):4. Test Debug Output (confirms version reaches context)
5. Test Login (confirms version accepted by API)
Requirements