-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
61 lines (51 loc) · 1.55 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
61
package main
import (
"flag"
"fmt"
"log/slog"
"os"
"github.com/saveweb/aixifan/pkg/downloader"
"github.com/saveweb/aixifan/pkg/uploader"
"github.com/saveweb/aixifan/pkg/utils"
)
func rootHelp() {
fmt.Println("aixifan - " + utils.GetVersion().Version + " (" + utils.GetVersion().GoVersion + ")")
fmt.Println("")
fmt.Println(
`Usage: aixifan COMMAND [ARGS]...
Commands:
down Download
up Upload to IA
version Show version`)
}
func main() {
flag.Usage = rootHelp
flag.Parse()
downCmd := flag.NewFlagSet("down", flag.ExitOnError)
downNoVersionCheck := downCmd.Bool("no-version-check", false, "Do not check aixifan's version")
downDougaId := downCmd.String("i", "", "Douga ID (int-string, NOT contain 'ac' or '_')")
downSkipIACheck := downCmd.Bool("s", false, "Do not check if the item already exists on IA")
upCmd := flag.NewFlagSet("up", flag.ExitOnError)
upDougaId := upCmd.String("i", "", "Douga ID (int-string, NOT contain 'ac' or '_')")
upDelete := upCmd.Bool("d", false, "Delete the dougaDir after uploading successfully")
versionCmd := flag.NewFlagSet("version", flag.ExitOnError)
if len(os.Args) < 2 {
rootHelp()
os.Exit(2)
}
switch os.Args[1] {
case "down":
downCmd.Parse(os.Args[2:])
os.Exit(downloader.Main(downCmd, *downNoVersionCheck, *downDougaId, *downSkipIACheck))
case "up":
upCmd.Parse(os.Args[2:])
os.Exit(uploader.Main(upCmd, *upDougaId, *upDelete))
case "version":
versionCmd.Parse(os.Args[2:])
fmt.Println(utils.GetVersion().Version)
default:
slog.Error("Invalid action")
rootHelp()
os.Exit(2)
}
}