/
unlink.go
53 lines (42 loc) · 961 Bytes
/
unlink.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
package cmd
import (
"fmt"
"os"
"path/filepath"
"github.com/urfave/cli"
"github.com/manifoldco/torus-cli/dirprefs"
"github.com/manifoldco/torus-cli/errs"
)
func init() {
unlink := cli.Command{
Name: "unlink",
Usage: "Remove the link between this project and Torus",
Category: "PROJECT STRUCTURE",
Action: unlinkCmd,
}
Cmds = append(Cmds, unlink)
}
func unlinkCmd(ctx *cli.Context) error {
dPrefs, err := dirprefs.Load(true)
if err != nil {
return err
}
if dPrefs.Path == "" {
fmt.Println("No context link exists.")
return nil
}
err = dPrefs.Remove()
if err != nil {
return errs.NewErrorExitError("Could not remove link", err)
}
cwd, err := os.Getwd()
if err != nil {
return err
}
if filepath.Dir(dPrefs.Path) == cwd {
fmt.Println("Your current working directory has been unlinked.")
} else {
fmt.Printf("The parent directory '%s' has been unlinked.\n", filepath.Dir(dPrefs.Path))
}
return nil
}