/
remove.go
46 lines (37 loc) · 1000 Bytes
/
remove.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
package cmd
import (
"context"
"fmt"
"github.com/spf13/cobra"
)
func init() {
rootCmd.AddCommand(removeCmd)
}
var removeCmd = &cobra.Command{
Use: "remove <package>",
Short: "Removes supplied package from the current directory & package",
Aliases: []string{"delete", "un", "uninstall", "rm"},
RunE: func(cmd *cobra.Command, args []string) error {
instance, err := root.LocalInstance()
if err != nil {
return err
}
// we validate the local manifest
if err := root.validateManifest(instance.Manifest); err != nil {
return err
}
if instance.Manifest == nil {
return fmt.Errorf("no manifest found in current directory")
}
if len(args) == 0 {
return fmt.Errorf("no package name supplied")
}
fmt.Printf("Removing %s\n", args[0])
instance.Manifest.RemoveDependency(args[0])
instance.Manifest.RemoveDevDependency(args[0])
instance.UpdateLockfileDependencies(context.TODO())
instance.SaveManifest()
instance.SaveLockfile()
return nil
},
}