-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
88 lines (72 loc) · 2.36 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
package main
import (
"errors"
"flag"
"fmt"
"github.com/sirupsen/logrus"
"log"
"os"
)
var Log = logrus.New()
var Version string
func main() {
if err := run(); err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
}
func run() error {
config, err := parseFlags()
if err != nil {
return err
}
provider, err := config.getProvider()
if err != nil {
log.Fatalf("failed to the provider")
}
inputs, err := provider.FetchData()
if err != nil {
return fmt.Errorf("failed to fetch data: %w", err)
}
return InputProcessor{
config: config,
}.Process(inputs)
}
func parseFlags() (config Config, err error) {
flag.StringVar(&config.providerKey, "p", "", "Specify the data provider (e.g., aws).")
flag.StringVar(&config.providerKey, "provider", "", "Specify the data provider (e.g., aws).")
flag.BoolVar(&config.version, "version", false, "Output the current version")
flag.BoolVar(&config.verbose, "v", false, "Output debug information from the process")
flag.BoolVar(&config.verbose, "verbose", false, "Output debug information from the process")
flag.StringVar(&config.outputDir, "o", "output", "Specify the output directory within your working directory.")
flag.StringVar(&config.outputDir, "output-dir", "output", "Specify the output directory within your working directory.")
flag.Usage = func() {
fmt.Println("Usages:")
fmt.Println(" udd [OPTIONS] : Specify options for data provider and output directory.")
fmt.Println(" udd [CONTENT_TO_DECODE] : Specify the content to decode as the first argument.")
fmt.Println("\nOptions:")
fmt.Println(" -o, --output-dir: Specify the output directory within your working directory. (default \"output\")")
fmt.Println(" -p, --provider: Specify the data provider (e.g., aws).")
fmt.Println(" -v, --verbose: Output debug information from the process")
fmt.Println(" --version: OOutput the current version")
os.Exit(0)
}
flag.Parse()
args := flag.Args()
Log.Formatter = new(logrus.JSONFormatter)
Log.Out = os.Stdout
if config.version {
fmt.Println("Version: " + Version)
os.Exit(0)
}
if config.verbose {
Log.Level = logrus.DebugLevel
} else {
Log.Level = logrus.ErrorLevel
}
if config.providerKey == "" && len(args) < 1 {
return Config{}, errors.New("Either supply content directly or use a provider")
}
config.args = args
return config, nil
}