-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
60 lines (53 loc) · 1.25 KB
/
main.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
55
56
57
58
59
60
package main
import (
"flag"
"fmt"
"os"
"github.com/mattetti/cocoa"
)
var (
flagSrc = flag.String("from", "", "Path of the file to link from")
flagDest = flag.String("to", "", "Path of the file to link to")
flagParse = flag.String("parse", "", "debugging option")
flagDebug = flag.Bool("debug", false, "print more logs ")
)
func main() {
flag.Parse()
if *flagParse != "" {
parse(*flagParse)
return
}
if *flagSrc == "" {
fmt.Println("You have to pass the source path: -src=<path> (file you want to create a bookmark for)")
os.Exit(1)
}
if *flagDest == "" {
fmt.Println("You have to define the destination path, where you want to save the bookmark: -dst=<dst>")
os.Exit(1)
}
if *flagDebug {
cocoa.Debug = true
}
if cocoa.IsAlias(*flagSrc) {
fmt.Println("let's not alias to an alias")
os.Exit(1)
}
if err := cocoa.Alias(*flagSrc, *flagDest); err != nil {
panic(err)
}
}
func parse(src string) {
f, err := os.Open(src)
if err != nil {
panic(err)
}
defer f.Close()
b, err := cocoa.AliasFromReader(f)
fmt.Printf("%#v\n", b)
if err != nil {
panic(err)
}
if len(b.Path) != len(b.CNIDPath) {
fmt.Printf("The lenght of the path (%d) doesn't match the length of the CNID path (%d)\n", len(b.Path), len(b.CNIDPath))
}
}