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
15 changes: 13 additions & 2 deletions pkg/cli/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ type ProjectOptions struct {
ProjectOnly bool
DisplayShort bool

Context string

// SkipAccessValidation means that if a specific name is requested, don't bother checking for access to the project
SkipAccessValidation bool

Expand Down Expand Up @@ -81,7 +83,7 @@ func NewCmdProject(fullName string, f kcmdutil.Factory, streams genericclioption
Example: fmt.Sprintf(projectExample, fullName),
Run: func(cmd *cobra.Command, args []string) {
o.PathOptions = cliconfig.NewPathOptions(cmd)
kcmdutil.CheckErr(o.Complete(f, args))
kcmdutil.CheckErr(o.Complete(f, cmd, args))
kcmdutil.CheckErr(o.Run())
},
}
Expand All @@ -90,7 +92,7 @@ func NewCmdProject(fullName string, f kcmdutil.Factory, streams genericclioption
return cmd
}

func (o *ProjectOptions) Complete(f genericclioptions.RESTClientGetter, args []string) error {
func (o *ProjectOptions) Complete(f genericclioptions.RESTClientGetter, cmd *cobra.Command, args []string) error {
switch argsLength := len(args); {
case argsLength > 1:
return errors.New("Only one argument is supported (project name or context name).")
Expand All @@ -99,6 +101,15 @@ func (o *ProjectOptions) Complete(f genericclioptions.RESTClientGetter, args []s
}

var err error
o.Context, err = cmd.Flags().GetString("context")
if err != nil {
return fmt.Errorf("unable to get value for --context flag: %v", err)
}

if o.Context != "" {
o.Config.CurrentContext = o.Context
}

o.Config, err = f.ToRawKubeConfigLoader().RawConfig()
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/requestproject/request_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (o *RequestProjectOptions) Complete(f kcmdutil.Factory, cmd *cobra.Command,
if !o.SkipConfigWrite {
o.ProjectOptions = ocproject.NewProjectOptions(o.IOStreams)
o.ProjectOptions.PathOptions = cliconfig.NewPathOptions(cmd)
if err := o.ProjectOptions.Complete(f, []string{""}); err != nil {
if err := o.ProjectOptions.Complete(f, cmd, []string{""}); err != nil {
return err
}
} else {
Expand Down