Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Copy link
Member Author

Choose a reason for hiding this comment

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

note: clients.CLIVersion was set to version.Raw().

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 {
Expand Down Expand Up @@ -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
Copy link
Member Author

Choose a reason for hiding this comment

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

note: clients.CLIVersion was set to version.Raw().

clients.Config.Version = version.Raw()
Copy link
Member

Choose a reason for hiding this comment

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

🔍 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!

Copy link
Member

Choose a reason for hiding this comment

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

🗣️ ramble: Forgive me if the TODO of "slackcontext" above is meant to capture similar changes!

Copy link
Member Author

Choose a reason for hiding this comment

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

thought: I have a branch that removes clients.Config.Version entirely. I'll give it a second look, but my first impression is that it simplifies how we pass version around.


// 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)
Expand Down
14 changes: 0 additions & 14 deletions internal/shared/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -92,13 +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 internal/version would cause a circular dependency
// 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 = ""

// Custom values set by functional options
// Learn more: https://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis
for _, option := range options {
Expand Down Expand Up @@ -322,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 == "" {
Expand Down
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member Author

Choose a reason for hiding this comment

The 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 (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.

Copy link
Member

Choose a reason for hiding this comment

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

🔭 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!


var ctx = context.Background()
ctx = slackcontext.SetSessionID(ctx, uuid.New().String())
Expand Down
Loading