-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathln_unix.go
55 lines (48 loc) · 986 Bytes
/
ln_unix.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
//+build !windows
package someutils
import (
"errors"
"github.com/laher/uggo"
"io"
"os"
)
type SomeLn struct {
target string
linkName string
IsForce bool
IsSymbolic bool
}
/*
func init() {
Register({
"ln",
Ln})
}
*/
func (ln *SomeLn) ParseFlags(call []string, errPipe io.Writer) error {
flagSet := uggo.NewFlagSetDefault("ln", "[options] TARGET LINK_NAME", VERSION)
flagSet.BoolVar(&ln.IsSymbolic, "s", false, "Symbolic")
flagSet.BoolVar(&ln.IsForce, "f", false, "Force")
e := flagSet.Parse(call[1:])
if e != nil {
return e
}
if flagSet.ProcessHelpOrVersion() {
return nil
}
args := flagSet.Args()
if len(args) < 2 {
flagSet.Usage()
return errors.New("Not enough args!")
}
ln.target = args[0]
ln.linkName = args[1]
return nil
}
func (ln *SomeLn) Exec(inPipe io.Reader, outPipe io.Writer, errPipe io.Writer) error {
if ln.IsSymbolic {
return os.Symlink(ln.target, ln.linkName)
} else {
return os.Link(ln.target, ln.linkName)
}
}