-
Notifications
You must be signed in to change notification settings - Fork 1
/
opts.go
78 lines (65 loc) · 1.69 KB
/
opts.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
package cmd
import (
"errors"
"github.com/gnames/bhlindex/config"
"github.com/gnames/gnfmt"
"github.com/rs/zerolog/log"
"github.com/spf13/viper"
)
// getOpts imports data from the configuration file. Some of the settings can
// be overriden by command line flags.
func getOpts(cfgPath string) {
cfg := &cfgData{}
err := viper.Unmarshal(cfg)
if err != nil {
log.Fatal().Err(err).Msg("Cannot deserialize config data")
}
if cfg.BHLdir != "" {
opts = append(opts, config.OptBHLdir(cfg.BHLdir))
} else {
log.Fatal().Err(errors.New("cannot find BHL data")).Msgf(
"Tell bhlindex where to find BHL data by setting up BHLdir in %s",
cfgPath,
)
}
if cfg.OutputFormat != "" {
f := gnfmt.CSV
switch cfg.OutputFormat {
case "csv":
f = gnfmt.CSV
case "tsv":
f = gnfmt.TSV
case "json":
f = gnfmt.CompactJSON
default:
log.Warn().Msgf("Format '%s' is not supported, using default 'csv' format",
cfg.OutputFormat)
log.Warn().Msg("Supported formats are 'csv', 'tsv', 'json'")
}
opts = append(opts, config.OptOutputFormat(f))
}
if cfg.PgHost != "" {
opts = append(opts, config.OptPgHost(cfg.PgHost))
}
if cfg.PgUser != "" {
opts = append(opts, config.OptPgUser(cfg.PgUser))
}
if cfg.PgPass != "" {
opts = append(opts, config.OptPgPass(cfg.PgPass))
}
if cfg.PgDatabase != "" {
opts = append(opts, config.OptPgDatabase(cfg.PgDatabase))
}
if cfg.Jobs > 0 {
opts = append(opts, config.OptJobs(cfg.Jobs))
}
if cfg.VerifierURL != "" {
opts = append(opts, config.OptVerifierURL(cfg.VerifierURL))
}
if cfg.WithWebLogs {
opts = append(opts, config.OptWithWebLogs(true))
}
if cfg.WithoutConfirm {
opts = append(opts, config.OptWithoutConfirm(true))
}
}