-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
59 lines (51 loc) · 1.26 KB
/
main.go
File metadata and controls
59 lines (51 loc) · 1.26 KB
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
package main
import (
"fmt"
"log"
"os"
"github.com/bakurits/fshare-cli/pkg/cfg"
"github.com/bakurits/fshare-cli/pkg/cmdutil"
"github.com/bakurits/fshare-cli/pkg/root"
"github.com/bakurits/fshare-common/auth"
"github.com/spf13/cobra"
)
// Execute executes cmd command
func Execute(rootCmd *cobra.Command) {
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}
func readConfig() *cmdutil.Config {
var conf cmdutil.Config
err := cfg.GetConfig(&conf)
if err != nil {
log.Fatal("Can't find config")
}
cred, err := cfg.LoadGoogleCredentials(conf.GoogleCredentialsPath, cfg.CredentialTypeDesktop)
if err != nil {
log.Fatal("Unable to parse credentials")
}
conf.GoogleCredentials = cred
return &conf
}
func getAuthClient(conf *cmdutil.Config) *auth.Client {
var err error
authClient, err := auth.
GetConfig(conf.GoogleCredentials.ClientID, conf.GoogleCredentials.ClientSecret, "http://localhost").
ClientFromTokenFile(conf.TokenPath)
if err != nil {
return nil
}
return authClient
}
func initConfig() (*cmdutil.Config, *auth.Client) {
conf := readConfig()
authClient := getAuthClient(conf)
return conf, authClient
}
func main() {
conf, authClient := initConfig()
rootCmd := root.NewCmdRoot(conf, authClient)
Execute(rootCmd)
}