mirror of
https://github.com/k8sgpt-ai/k8sgpt.git
synced 2025-08-12 13:11:42 +00:00
feat: auth remove: add -b flag (#711)
* feat: auth remove: add -b flag Signed-off-by: Pavel Sturc <psturc@redhat.com> * fix: address comment Signed-off-by: Pavel Sturc <psturc@redhat.com> --------- Signed-off-by: Pavel Sturc <psturc@redhat.com> Co-authored-by: Alex Jones <alexsimonjones@gmail.com>
This commit is contained in:
parent
3bff9cbe7b
commit
9dadd186c8
@ -246,7 +246,7 @@ k8sgpt auth update $MY_BACKEND1,$MY_BACKEND2..
|
|||||||
_Remove configured backends_
|
_Remove configured backends_
|
||||||
|
|
||||||
```
|
```
|
||||||
k8sgpt auth remove $MY_BACKEND1,$MY_BACKEND2..
|
k8sgpt auth remove -b $MY_BACKEND1,$MY_BACKEND2..
|
||||||
```
|
```
|
||||||
|
|
||||||
_List integrations_
|
_List integrations_
|
||||||
|
@ -23,23 +23,26 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var removeCmd = &cobra.Command{
|
var removeCmd = &cobra.Command{
|
||||||
Use: "remove [backend(s)]",
|
Use: "remove",
|
||||||
Short: "Remove a provider",
|
Short: "Remove provider(s)",
|
||||||
Long: "The command to remove an AI backend provider",
|
Long: "The command to remove AI backend provider(s)",
|
||||||
Args: cobra.ExactArgs(1),
|
PreRun: func(cmd *cobra.Command, args []string) {
|
||||||
|
_ = cmd.MarkFlagRequired("backends")
|
||||||
|
},
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
inputBackends := strings.Split(args[0], ",")
|
if backend == "" {
|
||||||
|
color.Red("Error: backends must be set.")
|
||||||
|
_ = cmd.Help()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
inputBackends := strings.Split(backend, ",")
|
||||||
|
|
||||||
err := viper.UnmarshalKey("ai", &configAI)
|
err := viper.UnmarshalKey("ai", &configAI)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
color.Red("Error: %v", err)
|
color.Red("Error: %v", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(inputBackends) == 0 {
|
|
||||||
color.Red("Error: backend must be set.")
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, b := range inputBackends {
|
for _, b := range inputBackends {
|
||||||
foundBackend := false
|
foundBackend := false
|
||||||
for i, provider := range configAI.Providers {
|
for i, provider := range configAI.Providers {
|
||||||
@ -54,11 +57,11 @@ var removeCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !foundBackend {
|
if !foundBackend {
|
||||||
color.Red("Error: %s does not exist in configuration file. Please use k8sgpt auth new.", backend)
|
color.Red("Error: %s does not exist in configuration file. Please use k8sgpt auth new.", b)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
viper.Set("ai", configAI)
|
viper.Set("ai", configAI)
|
||||||
if err := viper.WriteConfig(); err != nil {
|
if err := viper.WriteConfig(); err != nil {
|
||||||
color.Red("Error writing config file: %s", err.Error())
|
color.Red("Error writing config file: %s", err.Error())
|
||||||
@ -67,3 +70,8 @@ var removeCmd = &cobra.Command{
|
|||||||
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
// add flag for backends
|
||||||
|
removeCmd.Flags().StringVarP(&backend, "backends", "b", "", "Backend AI providers to remove (separated by a comma)")
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user