-
Notifications
You must be signed in to change notification settings - Fork 243
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pass the env config into the context passed to CLI methods
- Loading branch information
Showing
2 changed files
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package context | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/redhat-developer/odo/pkg/config" | ||
) | ||
|
||
type contextKey struct{} | ||
|
||
var key = contextKey{} | ||
|
||
// WithEnvConfig sets the environment configuration in ctx | ||
func WithEnvConfig(ctx context.Context, val config.Configuration) context.Context { | ||
return context.WithValue(ctx, key, val) | ||
} | ||
|
||
// GetEnvConfig returns the environment configuration from ctx | ||
func GetEnvConfig(ctx context.Context) config.Configuration { | ||
value := ctx.Value(key) | ||
if cast, ok := value.(config.Configuration); ok { | ||
return cast | ||
} | ||
panic("GetEnvConfig can be called only after WithEnvConfig has been called") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters