-
Notifications
You must be signed in to change notification settings - Fork 1
/
cmd_del.go
54 lines (51 loc) · 1.31 KB
/
cmd_del.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package kpm
import (
"errors"
"github.com/orangebees/kpm/pkg/kpm/go-oneutils/PathHandle"
"github.com/urfave/cli/v2"
"io/fs"
"os"
)
func NewDelCmd() *cli.Command {
return &cli.Command{
Hidden: false,
Name: "del",
Usage: "del dependencies pkg",
Action: func(c *cli.Context) error {
if c.NArg() == 0 {
cli.ShowAppHelpAndExit(c, 0)
}
println("del...")
kf, err := kpmC.LoadKpmFileStructInWorkdir()
if err != nil {
return err
}
shortname := c.Args().Slice()[c.Args().Len()-1]
rb, ok := kf.Direct[shortname]
if !ok {
e := errors.New("this package does not exists")
return e
}
delete(kf.Direct, shortname)
var targetPath string
if kpmC.NestedMode {
targetPath = kpmC.WorkDir + PathHandle.Separator + "external" + PathHandle.Separator + shortname
} else {
//待开发
targetPath = kpmC.WorkDir + PathHandle.Separator + "external" + PathHandle.Separator + PathHandle.URLToLocalDirPath(rb.Name) + "@" + string(rb.Version)
}
err = os.Remove(targetPath)
if err != nil {
if !(errors.Is(err, os.ErrNotExist) || errors.Is(err, &fs.PathError{Op: "remove", Path: targetPath})) {
return err
}
}
println("delete", shortname, "success")
err = kpmC.SaveKpmFileInWorkdir(kf)
if err != nil {
return err
}
return nil
},
}
}