-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfig.go
91 lines (73 loc) · 3.2 KB
/
Config.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
package main
import (
"flag"
"fmt"
"os"
)
type ColumnInfo struct {
Tags []string
}
func (c *ColumnInfo) Init() {}
type GroupInfo struct {
Kind string
Fields []string
}
type Config struct {
// scanner config
Scanner string
InputFile string
// CSV Scanner config
ScanCsvDelimiter string
ScanCsvQuote string
ScanCsvAsNull []string
ScanCsvNoNull bool
ScanCsvStrip bool
ScanCsvColumnNames string
ScanCsvStripBy string
// Formatters config
Formater string
DatasetName string
DatasetDescription string
DatasetMeta map[string]string
// SQL Formatters config
FmtSQLTable string
FmtSQLMaxQuerySize int64
// Analyzer config
ColumnInfos map[string]*ColumnInfo
GroupInfos []GroupInfo
}
var config = Config{}
func ParseConfig() {
config.ColumnInfos = make(map[string]*ColumnInfo)
config.DatasetMeta = make(map[string]string)
// scanner config
flag.StringVar(&config.Scanner, "scanner", "csv", "What scanner to use (default: csv)")
// CSV config
flag.StringVar(&config.ScanCsvDelimiter, "csv-delimiter", ",", "CSV delimiter (commas by default)")
// TODO: currently disabled since the golang csv reader doesn't support it (i guess i'm going to recode it)
//flag.StringVar(&config.ScanCsvSeparator, "csv-quote", "\"", "CSV quotes, empty to disable it (double quotes bu default)")
flag.BoolVar(&config.ScanCsvStrip, "csv-strip", true, "Strip columns (default: true)")
flag.BoolVar(&config.ScanCsvNoNull, "csv-no-null", false, "Disable nullation of csv columns")
flag.Var(MultipleVars{&config.ScanCsvAsNull}, "csv-null", "Values that should be parsed as null (default: empty values, overwritten by this or --csv-no-null)")
flag.StringVar(&config.ScanCsvColumnNames, "csv-column-names", "", "Name of columns in the CSV file, columns `_` are ignored (by default the scanner reads the first row)")
flag.StringVar(&config.ScanCsvStripBy, "csv-strip-by", " \n\f\r\t\v", "Character used to strip values (default: ASCII spaces (isspace + C_LOCAL))")
// Formatters config
flag.StringVar(&config.Formater, "formatter", "MySQL", "What formatter to use (default: MySQL)")
flag.StringVar(&config.DatasetName, "dataset-name", "", "Specify dataset's name")
flag.StringVar(&config.DatasetDescription, "dataset-description", "", "Specify dataset's description")
flag.Var(DatasetMetaVar{&config.DatasetMeta}, "dataset-meta", "Specify dataset meta (format: <key>:<value>)")
// SQL Formatters config
flag.StringVar(&config.FmtSQLTable, "sql-table", "", "Output table name")
flag.Int64Var(&config.FmtSQLMaxQuerySize, "sql-max-query-size", 1048576, "Max SQL query size")
// Analyzer config
flag.Var(&ColumnTagsVar{&config.ColumnInfos}, "column-tags", "Specify column's tags, format: <column name>:<tags>:...")
flag.Var(&GroupVar{&config.GroupInfos}, "group", "Specify group of column, format: <column name>:<tags>:...")
flag.Parse()
if len(flag.Args()) == 0 {
fmt.Println("Usage:", os.Args[0], "[FLAGS...] <subcommand>")
fmt.Println("subcommands:")
fmt.Println(" - hint: analyze columns and try to guess columns' types (takes input file)")
fmt.Println(" - analyze: analyze columns and use `formater` to store it (takes input and output folder)")
os.Exit(0)
}
}