-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
main.go
51 lines (44 loc) · 1 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
package main
import (
"flag"
"fmt"
"os"
"path"
"runtime/debug"
"github.com/c-bata/go-prompt"
"github.com/chyroc/aliyundrive-cli/internal"
)
var (
printVersion bool
dir string
)
func init() {
home, _ := os.UserHomeDir()
downloadDir := path.Join(home, "/Downloads/aliyundrive-cli")
flag.BoolVar(&printVersion, "version", false, "Print program version")
flag.StringVar(&dir, "dir", downloadDir, "File download directory")
if !flag.Parsed() {
flag.Parse()
}
if printVersion {
info, ok := debug.ReadBuildInfo()
if ok {
println(info.Main.Version)
}
os.Exit(0)
}
}
func main() {
oldTermiosPtr := internal.IoctlGetTermios()
defer internal.IoctlSetTermios(oldTermiosPtr)
os.Stdout.Sync()
cli := internal.NewCli(dir)
fmt.Println("阿里云盘命令行客户端")
p := prompt.New(cli.Executor, cli.Completer, prompt.OptionLivePrefix(cli.Prefix), prompt.OptionAddKeyBind(prompt.KeyBind{
Key: prompt.ControlC,
Fn: func(b *prompt.Buffer) {
internal.Cancel()
},
}))
p.Run()
}