Skip to content
Draft
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
12 changes: 8 additions & 4 deletions pkg/cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ import (
)

type Obot struct {
Debug bool `usage:"Enable debug logging"`
Client *apiclient.Client
Debug bool `usage:"Enable debug logging"`
BaseURL string `usage:"Base URL for the OBOT API" default:"http://localhost:8080/api"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did you have to move BaseURL onto this struct rather than just leveraging the one thats already on Client?

Client *apiclient.Client
}

func (a *Obot) PersistentPre(*cobra.Command, []string) error {
Expand All @@ -27,6 +28,9 @@ func (a *Obot) PersistentPre(*cobra.Command, []string) error {
logger.SetDebug()
}

// Update the client's BaseURL from the flag/env value
a.Client.BaseURL = a.BaseURL

if a.Client.Token == "" {
a.Client = a.Client.WithTokenFetcher(internal.Token)
}
Expand All @@ -36,9 +40,9 @@ func (a *Obot) PersistentPre(*cobra.Command, []string) error {

func New() *cobra.Command {
root := &Obot{
BaseURL: env.VarOrDefault("OBOT_BASE_URL", "http://localhost:8080/api"),
Client: &apiclient.Client{
BaseURL: env.VarOrDefault("OBOT_BASE_URL", "http://localhost:8080/api"),
Token: os.Getenv("OBOT_TOKEN"),
Token: os.Getenv("OBOT_TOKEN"),
},
}
return cmd.Command(root,
Expand Down