-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.go
71 lines (67 loc) · 1.56 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
package main
import (
"errors"
"fmt"
"os"
"path/filepath"
"runtime"
"github.com/rvflash/awql/conf"
"github.com/rvflash/awql/ui"
)
// main launches the AWQL Command-Line Tool.
//
// Usage of awql:
// -A Disables automatic rehashing
// -B Enables printing of results using comma as the column separator
// -D string
// Google OAuth developer token
// -T string
// Google OAuth access token
// -V string
// Google Adwords API version (default "v201809")
// -c Enables data caching
// -e string
// Execute AWQL statement, disables interactive use
// -i string
// Google Adwords account ID
// -v Enables verbose mode
// -z Enables fetching of reports with the support of zero impressions
//
func main() {
// Gets the workspace directory (used to known the tool location after go install)
_, file, _, ok := runtime.Caller(0)
if !ok {
exit(errors.New("unable to retrieve the tool's location"))
}
// Initializes all environment properties.
conf := conf.New(filepath.Dir(file))
if err := conf.Init(); err != nil {
exit(err)
}
// Launch the environment.
var src ui.Scanner
if conf.IsInteractive() {
src = ui.NewTerminal(conf)
} else {
src = ui.NewCommandLine(conf)
}
if err := src.Scan(); err != nil {
exit(err)
}
}
// exit causes the current program to exit with the appropriate status code.
func exit(err error) {
if err == nil {
// See you soon.
os.Exit(0)
}
// An error occurred, exits with the appropriate behavior.
switch err.(type) {
case *conf.FlagError:
fmt.Println(err)
conf.Usage()
default:
fmt.Println(err)
}
os.Exit(1)
}