Prevent adding duplicate services

This commit is contained in:
Philipp Wolfer 2023-12-07 23:09:16 +01:00
parent 8743a9d81c
commit 091b3c2f49
No known key found for this signature in database
GPG key ID: 8FDF744D4919943B
2 changed files with 57 additions and 5 deletions

View file

@ -22,6 +22,7 @@ THE SOFTWARE.
package cmd
import (
"errors"
"fmt"
"github.com/manifoldco/promptui"
@ -48,14 +49,20 @@ var addCmd = &cobra.Command{
// Set service name
prompt := promptui.Prompt{
Label: "Service name",
Validate: config.ValidateKey,
Default: backend,
Label: "Service name",
Default: backend,
Validate: func(s string) error {
srv, _ := config.GetService(s)
if srv != nil {
return errors.New("a service with this name already exists")
}
return config.ValidateKey(s)
},
}
name, err := prompt.Run()
cobra.CheckErr(err)
// Prepate service config
// Prepare service config
service := config.ServiceConfig{
Name: name,
Backend: backend,