File tree Expand file tree Collapse file tree 1 file changed +23
-5
lines changed
Expand file tree Collapse file tree 1 file changed +23
-5
lines changed Original file line number Diff line number Diff line change @@ -65,11 +65,8 @@ func (r *Resource) Predict(args complete.Args) []string {
6565 ns = org
6666 }
6767 // if there is a project set in the args use this
68- for i , arg := range args .All {
69- if (arg == "-p" || arg == "--project" ) && i + 1 < len (args .All ) {
70- ns = args .All [i + 1 ]
71- break
72- }
68+ if p := findProject (args ); p != "" {
69+ ns = p
7370 }
7471
7572 if err := r .client .List (ctx , u , client .InNamespace (ns )); err != nil {
@@ -106,6 +103,27 @@ func listKindToResource(kind string) string {
106103 return flect .Pluralize (strings .TrimSuffix (strings .ToLower (kind ), listSuffix ))
107104}
108105
106+ func findProject (_ complete.Args ) string {
107+ // try to find it in the full command line.
108+ if line := os .Getenv ("COMP_LINE" ); line != "" {
109+ parts := strings .Fields (line )
110+ if p := findProjectInSlice (parts ); p != "" {
111+ return p
112+ }
113+ }
114+
115+ return ""
116+ }
117+
118+ func findProjectInSlice (args []string ) string {
119+ for i , arg := range args {
120+ if (arg == "-p" || arg == "--project" ) && i + 1 < len (args ) {
121+ return args [i + 1 ]
122+ }
123+ }
124+ return ""
125+ }
126+
109127func NewClient (ctx context.Context , defaultAPICluster string ) (* api.Client , error ) {
110128 // the client for the predictor requires a static token in the client config
111129 // since dynamic exec config seems to break with some shells during completion.
You can’t perform that action at this time.
0 commit comments