-
Notifications
You must be signed in to change notification settings - Fork 34
refactor: remove legacy CLIVersion field and SetVersion() function #429
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
Changes from 2 commits
a164d25
24e129b
1483592
048099b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -148,7 +148,7 @@ func Init(ctx context.Context) (*cobra.Command, *shared.ClientFactory) { | |
| // updateNotification will check for an update in the background and print a message after the command runs | ||
| var updateNotification *update.UpdateNotification | ||
|
|
||
| clients = shared.NewClientFactory(shared.SetVersion(version.Raw())) | ||
| clients = shared.NewClientFactory() | ||
| rootCmd := NewRootCommand(clients, updateNotification) | ||
|
|
||
| // Support `--version` by setting root command's `Version` and custom template. | ||
|
|
@@ -265,7 +265,7 @@ func InitConfig(ctx context.Context, clients *shared.ClientFactory, rootCmd *cob | |
|
|
||
| // 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) | ||
| clients.Config.LogstashHostResolved = clients.Auth().ResolveLogstashHost(ctx, clients.Config.APIHostResolved, version.Raw()) | ||
|
|
||
| // Init System ID | ||
| if systemID, err := clients.Config.SystemConfig.InitSystemID(ctx); err != nil { | ||
|
|
@@ -297,7 +297,7 @@ func InitConfig(ctx context.Context, clients *shared.ClientFactory, rootCmd *cob | |
| 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 | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: |
||
| clients.Config.Version = version.Raw() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔍 thought(non-blocking): Would setting this version above - before 👾 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!
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗣️ ramble: Forgive me if the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thought: I have a branch that removes |
||
|
|
||
| // The domain auths (token->domain) shouldn't change for the execution of the CLI so preload them into config! | ||
| clients.Config.DomainAuthTokens = clients.Auth().MapAuthTokensToDomains(ctx) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,7 +45,6 @@ type ClientFactory struct { | |
| API func() api.APIInterface | ||
| AppClient func() *app.Client | ||
| Auth func() auth.AuthInterface | ||
| CLIVersion string | ||
| Config *config.Config | ||
| EventTracker tracking.TrackingManager | ||
| HookExecutor hooks.HookExecutor | ||
|
|
@@ -92,14 +91,6 @@ func NewClientFactory(options ...func(*ClientFactory)) *ClientFactory { | |
| clients.Auth = clients.defaultAuthFunc | ||
| clients.Browser = clients.defaultBrowserFunc | ||
|
|
||
| // 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 = "" | ||
|
|
||
|
Comment on lines
-95
to
-101
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🪓
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🌲 praise: This has bothered me more than I understood. Thanks for making change that improves the code @mwbrooks! |
||
| // Custom values set by functional options | ||
| // Learn more: https://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis | ||
| for _, option := range options { | ||
|
|
@@ -323,12 +314,6 @@ func DebugMode(c *ClientFactory) { | |
| c.Config.DebugEnabled = true | ||
| } | ||
|
|
||
| // SetVersion is a functional option that sets the Cli version that the API Client references | ||
| // Learn more: https://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis | ||
| func SetVersion(version string) func(c *ClientFactory) { | ||
| return func(c *ClientFactory) { c.CLIVersion = version } | ||
| } | ||
|
|
||
| // getDevHostname returns the hostname of the given URL if it is dev or a numbered dev instance | ||
| func getDevHostname(host string) string { | ||
| if host == "" { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,7 +80,8 @@ func main() { | |
| func recoveryFunc() { | ||
| // in the event of a panic, log panic | ||
| if r := recover(); r != nil { | ||
| var clients = shared.NewClientFactory(shared.SetVersion(version.Raw())) | ||
| var clients = shared.NewClientFactory() | ||
| clients.Config.Version = version.Raw() | ||
|
Comment on lines
+83
to
+84
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thought: I still don't like that we're setting the version in multiple places, instead of just referencing the source of truth (
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔭 thought: For this 🌟 praise: Thanks for catching this in these updates still! |
||
|
|
||
| var ctx = context.Background() | ||
| ctx = slackcontext.SetSessionID(ctx, uuid.New().String()) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note:
clients.CLIVersionwas set toversion.Raw().