Skip to content

Commit

Permalink
Merge pull request #164 from ninech/fix-token-gathering-when-not-needed
Browse files Browse the repository at this point in the history
only get token if tab completion was executed
  • Loading branch information
thirdeyenick authored Sep 18, 2024
2 parents 1fdf9ab + f25b93d commit c461d6e
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions predictor/predictor.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,26 @@ var argResourceMap = map[string]string{
}

type Resource struct {
client *api.Client
clientCreator func() (*api.Client, error)
client *api.Client
}

func NewResourceName(clientCreator func() (*api.Client, error)) *Resource {
c, err := clientCreator()
if err != nil {
return &Resource{}
return &Resource{
clientCreator: clientCreator,
}

return &Resource{client: c}
}

func (r *Resource) Predict(args complete.Args) []string {
if r.client == nil {
if r.clientCreator == nil {
return []string{}
}
if r.client == nil {
var err error
if r.client, err = r.clientCreator(); err != nil {
return []string{}
}
}

u := &unstructured.UnstructuredList{}
u.SetGroupVersionKind(r.findKind(args.LastCompleted))
Expand Down

0 comments on commit c461d6e

Please sign in to comment.