Skip to content

Commit

Permalink
fix: use nil as unset value for proper lazy init
Browse files Browse the repository at this point in the history
  • Loading branch information
metacosm committed Sep 1, 2020
1 parent aae01c3 commit 990986f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions pkg/odo/genericclioptions/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,19 +414,20 @@ type Context struct {
internalCxt
}

func (c *Context) GetProject() string {
if c.project == "" {
c.project = resolveProject(c.command, c.Client, c.LocalConfigInfo)
func (o *Context) GetProject() string {
if o.project == nil {
project := resolveProject(o.command, o.Client, o.LocalConfigInfo)
o.project = &project
}
return c.project
return *o.project
}

// internalCxt holds the actual context values and is not exported so that it cannot be instantiated outside of this package.
// This ensures that Context objects are always created properly via NewContext factory functions.
type internalCxt struct {
Client *occlient.Client
command *cobra.Command
project string
project *string
Application string
cmp string
OutputFlag string
Expand Down
2 changes: 1 addition & 1 deletion pkg/odo/genericclioptions/fakecontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ func NewFakeContext(project, application, component string, client *occlient.Cli
internalCxt{
Client: client,
KClient: kclient,
project: project,
project: &project,
Application: application,
cmp: component,
},
Expand Down

0 comments on commit 990986f

Please sign in to comment.