-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcommand.go
55 lines (49 loc) · 1.14 KB
/
command.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
package syncbox
import (
"crypto/md5"
"flag"
"os"
"path"
"path/filepath"
)
// Cmd command line options for client program
type Cmd struct {
RootDir string
TmpDir string
Username string
Password string
}
// ParseCommand parse commands for client program
func ParseCommand() (*Cmd, error) {
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
return nil, err
}
tempDir := path.Join(getSystemTempDir(), "syncbox")
dir += TestDir
rootDirPtr := flag.String("root_dir", dir, "the root directory to watch")
tmpDirPtr := flag.String("tmp_dir", tempDir, "the temporary folder to put files that deleted")
usernamePtr := flag.String("Username", "hello", "username to login")
passwordPtr := flag.String("Password", "world", "password to login")
flag.Parse()
var pwdSlice []byte
copy(pwdSlice, *passwordPtr)
hash := md5.Sum(pwdSlice)
pwd := string(hash[:])
return &Cmd{
RootDir: *rootDirPtr,
TmpDir: *tmpDirPtr,
Username: *usernamePtr,
Password: pwd,
}, nil
}
func (c *Cmd) String() string {
return ToString(c)
}
func getSystemTempDir() string {
tmp := os.Getenv("TMPDIR")
if tmp == "" {
tmp = "/tmp"
}
return tmp
}