-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
61 lines (51 loc) · 1.33 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 github.com/mfederowicz/trakt-sync.
package main
import (
"flag"
"github.com/mfederowicz/trakt-sync/cfg"
"github.com/mfederowicz/trakt-sync/cli"
"github.com/mfederowicz/trakt-sync/cmds"
"github.com/mfederowicz/trakt-sync/consts"
"github.com/mfederowicz/trakt-sync/internal"
"github.com/mfederowicz/trakt-sync/printer"
"github.com/mfederowicz/trakt-sync/str"
"github.com/spf13/afero"
)
var (
options = &str.Options{}
_verbose = flag.Bool("v", false, consts.VerboseUsage)
_version = flag.Bool("version", false, consts.VersionUsage)
_configPath = flag.String("c", cfg.DefaultConfig().ConfigPath, consts.ConfigUsage)
)
func main() {
fs := afero.NewOsFs()
config, err := cfg.InitConfig(fs)
if err != nil {
printer.Printf("Error: %v\n", err)
return
}
client := internal.NewClient(nil)
options, err := cfg.OptionsFromConfig(fs, config)
if err != nil {
printer.Printf("Error: %v\n", err)
return
}
client.UpdateHeaders(options.Headers)
flag.Usage = func() {
cmds.HelpFunc(cmds.HelpCmd)
}
flag.Parse()
if *_version {
printer.Println(cli.GenAppVersion())
return
}
args := flag.Args()
if len(args) == consts.ZeroValue {
flag.Usage()
return
}
if !cli.ValidAccessToken(config, client.Oauth) {
cli.PoolNewDeviceCode(config, client.Oauth)
}
cmds.ModulesRuntime(args, config, client, fs)
}