mirror of
https://git.sr.ht/~phw/scotty
synced 2025-04-25 05:47:57 +02:00
Prevent adding duplicate services
This commit is contained in:
parent
8743a9d81c
commit
091b3c2f49
2 changed files with 57 additions and 5 deletions
15
cmd/add.go
15
cmd/add.go
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue