forked from v8platform/oneget
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
96 lines (86 loc) · 2.11 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package main
import (
"fmt"
"github.com/khorevaa/logos"
"github.com/urfave/cli/v2"
"github.com/v8platform/oneget/cmd"
"os"
)
var (
version = "dev"
commit = ""
date = ""
builtBy = ""
)
var log = logos.New("github.com/v8platform/oneget").Sugar()
func setFlags() []cli.Flag {
return []cli.Flag{
&cli.StringFlag{
Name: "user",
Aliases: []string{"u"},
EnvVars: []string{"ONEGET_USER", "ONEC_USERNAME"},
Usage: "Пользователь портала 1С",
Required: true,
},
&cli.StringFlag{
Name: "pwd",
Aliases: []string{"p"},
EnvVars: []string{"ONEGET_PASSWORD", "ONEC_PASSWORD"},
Usage: "Пароль пользователя портала 1С",
Required: true,
},
&cli.BoolFlag{
Name: "debug",
EnvVars: []string{"ONEGET_DEBUG"},
Usage: "Режим отладки приложения",
},
&cli.StringFlag{
Name: "logs",
DefaultText: "oneget.log",
Value: "oneget.log",
Usage: "Файл лога загрузки",
},
&cli.BoolFlag{
Name: "enableHttp",
Aliases: []string{"s"},
Value: false,
EnvVars: []string{"ONEGET_ENABLE_HTTP_SERVER"},
Usage: "Запустить http сервер для доступа к скачаным файлам",
},
&cli.StringFlag{
Name: "serverPort",
Aliases: []string{"sp"},
Value: "8080",
EnvVars: []string{"ONEGET_HTTP_SERVER_PORT"},
},
}
}
func main() {
app := &cli.App{
Name: "oneget",
Usage: "Приложение для загрузки релизов сайта релизов 1С",
Version: buildVersion(),
Flags: setFlags(),
}
for _, command := range cmd.Commands {
app.Commands = append(app.Commands, command.Cmd())
}
err := app.Run(os.Args)
defer log.Sync()
if err != nil {
log.Fatal(err.Error())
}
}
func buildVersion() string {
var result = version
if commit != "" {
result = fmt.Sprintf("%s\ncommit: %s", result, commit)
}
if date != "" {
result = fmt.Sprintf("%s\nbuilt at: %s", result, date)
}
if builtBy != "" {
result = fmt.Sprintf("%s\nbuilt by: %s", result, builtBy)
}
return result
}