mirror of
https://github.com/k8sgpt-ai/k8sgpt.git
synced 2025-07-31 15:13:45 +00:00
feat: add remove command to remove a backend AI provider (#395)
* feat: add remove command to remove a backend AI provider Signed-off-by: Matthis Holleville <matthish29@gmail.com> * Update cmd/auth/remove.go Co-authored-by: Alex Jones <alex@k8sgpt.ai> Signed-off-by: Matthis <99146727+matthisholleville@users.noreply.github.com> * feat: update Long remove command Signed-off-by: Matthis Holleville <matthish29@gmail.com> --------- Signed-off-by: Matthis Holleville <matthish29@gmail.com> Signed-off-by: Matthis <99146727+matthisholleville@users.noreply.github.com> Co-authored-by: Alex Jones <alex@k8sgpt.ai>
This commit is contained in:
parent
8cfb717dc1
commit
c5b72eee16
@ -232,6 +232,12 @@ _List configured backends_
|
|||||||
k8sgpt auth list
|
k8sgpt auth list
|
||||||
```
|
```
|
||||||
|
|
||||||
|
_Remove configured backends_
|
||||||
|
|
||||||
|
```
|
||||||
|
k8sgpt auth remove --backend $MY_BACKEND
|
||||||
|
```
|
||||||
|
|
||||||
_List integrations_
|
_List integrations_
|
||||||
|
|
||||||
```
|
```
|
||||||
|
@ -46,4 +46,6 @@ func init() {
|
|||||||
AuthCmd.AddCommand(listCmd)
|
AuthCmd.AddCommand(listCmd)
|
||||||
// add subcommand to create new backend provider
|
// add subcommand to create new backend provider
|
||||||
AuthCmd.AddCommand(newCmd)
|
AuthCmd.AddCommand(newCmd)
|
||||||
|
// add subcommand to remove new backend provider
|
||||||
|
AuthCmd.AddCommand(removeCmd)
|
||||||
}
|
}
|
||||||
|
59
cmd/auth/remove.go
Normal file
59
cmd/auth/remove.go
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2023 The K8sGPT Authors.
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package auth
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/fatih/color"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
)
|
||||||
|
|
||||||
|
var removeCmd = &cobra.Command{
|
||||||
|
Use: "remove",
|
||||||
|
Short: "Remove a provider",
|
||||||
|
Long: "The command to remove an AI backend provider",
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
err := viper.UnmarshalKey("ai", &configAI)
|
||||||
|
if err != nil {
|
||||||
|
color.Red("Error: %v", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
foundBackend := false
|
||||||
|
for i, provider := range configAI.Providers {
|
||||||
|
if backend == provider.Name {
|
||||||
|
foundBackend = true
|
||||||
|
configAI.Providers = append(configAI.Providers[:i], configAI.Providers[i+1:]...)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !foundBackend {
|
||||||
|
color.Red("Error: %s does not exist in configuration file. Please use k8sgpt auth new.", backend)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
viper.Set("ai", configAI)
|
||||||
|
if err := viper.WriteConfig(); err != nil {
|
||||||
|
color.Red("Error writing config file: %s", err.Error())
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
// add flag for backend
|
||||||
|
removeCmd.Flags().StringVarP(&backend, "backend", "b", "openai", "Backend AI provider")
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user