-
Notifications
You must be signed in to change notification settings - Fork 0
/
edit.go
40 lines (33 loc) · 760 Bytes
/
edit.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package cli_config
import (
"errors"
"fmt"
"github.com/herryg91/localhost-proxy/entity"
"github.com/spf13/cobra"
)
type CmdConfigEdit struct {
*cobra.Command
}
func newConfigEdit() *CmdConfigEdit {
c := &CmdConfigEdit{}
c.Command = &cobra.Command{
Use: "edit",
Short: "Edit dply configuration & preferences",
Long: "Edit dply configuration & preferences",
}
c.RunE = c.runCommand
return c
}
func (c *CmdConfigEdit) runCommand(cmd *cobra.Command, args []string) error {
cfg := entity.Config{}.FromFile()
err := cfg.UpdateByEditor()
if err != nil {
if errors.Is(err, entity.ErrConfigNothingChange) {
fmt.Println("Nothing to change")
return nil
}
return err
}
fmt.Println("Config file successfully saved")
return nil
}