Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow rename equals to target config filename on kubecm add #1060

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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: 8 additions & 7 deletions cmd/add.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cmd

import (
"errors"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -171,17 +170,20 @@ func (kc *KubeConfigOption) handleContexts(oldConfig *clientcmdapi.Config, conte
}
}

if checkContextName(newName, oldConfig) {
var quitNewName bool
for checkContextName(newName, oldConfig) {
nameConfirm := BoolUI(fmt.Sprintf("「%s」 Name already exists, do you want to rename it? (If you select `False`, this context will not be merged)", newName))
if nameConfirm == "True" {
newName = PromptUI("Rename", newName)
if newName == kc.fileName {
return nil, errors.New("need to rename")
}
} else {
continue
} else {
quitNewName = true
break
}
}
if quitNewName {
continue
}
itemConfig := kc.handleContext(oldConfig, newName, ctx)
newConfig = appendConfig(newConfig, itemConfig)
fmt.Printf("Add Context: %s \n", newName)
Expand Down Expand Up @@ -229,7 +231,6 @@ func checkClusterAndUserName(oldConfig *clientcmdapi.Config, newClusterName, new
for _, ctx := range oldConfig.Contexts {
if ctx.Cluster == newClusterName && ctx.AuthInfo == newUserName {
clusterAndUserNameExistInSameContext = true
break
}
if ctx.Cluster == newClusterName {
justClusterNameExist = true
Expand Down
Loading