@@ -28,6 +28,7 @@ import (
2828 "github.com/codefresh-io/cli-v2/pkg/store"
2929 "github.com/codefresh-io/cli-v2/pkg/util"
3030 "github.com/manifoldco/promptui"
31+ "k8s.io/client-go/tools/clientcmd"
3132
3233 "github.com/spf13/cobra"
3334 "github.com/spf13/pflag"
@@ -222,19 +223,21 @@ func getGitTokenFromUserInput(cmd *cobra.Command, cloneOpts *git.CloneOptions) e
222223 return nil
223224}
224225
225- func getApprovalFromUser (ctx context.Context , finalParameters map [string ]string , description string ) (bool , error ) {
226- if ! store .Get ().Silent {
227- isApproved , err := promptSummaryToUser (ctx , finalParameters , description )
228- if err != nil {
229- return false , fmt .Errorf ("%w" , err )
230- }
226+ func getApprovalFromUser (ctx context.Context , finalParameters map [string ]string , description string ) error {
227+ if store .Get ().Silent {
228+ return nil
229+ }
231230
232- if ! isApproved {
233- log .G (ctx ).Printf ("%v command was cancelled by user" , description )
234- return false , nil
235- }
231+ isApproved , err := promptSummaryToUser (ctx , finalParameters , description )
232+ if err != nil {
233+ return fmt .Errorf ("%w" , err )
236234 }
237- return true , nil
235+
236+ if ! isApproved {
237+ return fmt .Errorf ("%v command was cancelled by user" , description )
238+ }
239+
240+ return nil
238241}
239242
240243func promptSummaryToUser (ctx context.Context , finalParameters map [string ]string , description string ) (bool , error ) {
@@ -265,6 +268,75 @@ func promptSummaryToUser(ctx context.Context, finalParameters map[string]string,
265268 return false , nil
266269}
267270
271+ func getKubeContextNameFromUserSelect (cmd * cobra.Command , kubeContextName * string ) error {
272+ if store .Get ().Silent {
273+ return nil
274+ }
275+
276+ configAccess := clientcmd .NewDefaultPathOptions ()
277+ conf , err := configAccess .GetStartingConfig ()
278+ if err != nil {
279+ return err
280+ }
281+
282+ contextsList := conf .Contexts
283+ currentContext := conf .CurrentContext
284+ var contextsNamesToShowUser []string
285+ var contextsIndex []string
286+
287+ for key := range contextsList {
288+ contextsIndex = append (contextsIndex , key )
289+ if key == currentContext {
290+ key = key + " (current)"
291+ }
292+ contextsNamesToShowUser = append (contextsNamesToShowUser , key )
293+ }
294+
295+ templates := & promptui.SelectTemplates {
296+ Selected : "{{ . | yellow }} " ,
297+ }
298+
299+ labelStr := fmt .Sprintf ("%vSelect kube context%v" , CYAN , COLOR_RESET )
300+
301+ prompt := promptui.Select {
302+ Label : labelStr ,
303+ Items : contextsNamesToShowUser ,
304+ Templates : templates ,
305+ }
306+
307+ index , _ , err := prompt .Run ()
308+ if err != nil {
309+ return fmt .Errorf ("Prompt error: %w" , err )
310+ }
311+
312+ result := contextsIndex [index ]
313+
314+ die (cmd .Flags ().Set ("context" , result ))
315+ * kubeContextName = result
316+
317+ return nil
318+ }
319+
320+ func getIngressHostFromUserInput (cmd * cobra.Command , ingressHost * string ) error {
321+ if store .Get ().Silent {
322+ return nil
323+ }
324+
325+ ingressHostPrompt := promptui.Prompt {
326+ Label : "Ingress host" ,
327+ }
328+
329+ ingressHostInput , err := ingressHostPrompt .Run ()
330+ if err != nil {
331+ return fmt .Errorf ("Prompt error: %w" , err )
332+ }
333+
334+ die (cmd .Flags ().Set ("ingress-host" , ingressHostInput ))
335+ * ingressHost = ingressHostInput
336+
337+ return nil
338+ }
339+
268340func verifyLatestVersion (ctx context.Context ) error {
269341 latestVersionString , err := cfConfig .NewClient ().V2 ().CliReleases ().GetLatest (ctx )
270342 if err != nil {
0 commit comments