Skip to content

Commit

Permalink
Use fork that is able to correctly parse comma separated strings into…
Browse files Browse the repository at this point in the history
… slices
  • Loading branch information
Lun4m committed Nov 13, 2024
1 parent c98411f commit 2b5ebf9
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 48 deletions.
2 changes: 2 additions & 0 deletions migrations/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ require (
golang.org/x/term v0.25.0 // indirect
golang.org/x/text v0.16.0 // indirect
)

replace github.com/jessevdk/go-flags => github.com/Lun4m/go-flags v0.0.0-20241113125827-68757125e949
4 changes: 2 additions & 2 deletions migrations/go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
github.com/Lun4m/go-flags v0.0.0-20241113125827-68757125e949 h1:7xyEGIr1X5alOjBjlNTDF+aRBcRIo60YX5sdlziLE5w=
github.com/Lun4m/go-flags v0.0.0-20241113125827-68757125e949/go.mod h1:42/L0FDbP0qe91I+81tBqjU3uoz1tn1GDMZAhcCE2PE=
github.com/chengxilo/virtualterm v1.0.4 h1:Z6IpERbRVlfB8WkOmtbHiDbBANU7cimRIof7mk9/PwM=
github.com/chengxilo/virtualterm v1.0.4/go.mod h1:DyxxBZz/x1iqJjFxTFcr6/x+jSpqN0iwWCOK1q10rlY=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down Expand Up @@ -35,8 +37,6 @@ github.com/rickb777/plural v1.4.2 h1:Kl/syFGLFZ5EbuV8c9SVud8s5HI2HpCCtOMw2U1kS+A
github.com/rickb777/plural v1.4.2/go.mod h1:kdmXUpmKBJTS0FtG/TFumd//VBWsNTD7zOw7x4umxNw=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/schollz/progressbar v1.0.0 h1:gbyFReLHDkZo8mxy/dLWMr+Mpb1MokGJ1FqCiqacjZM=
github.com/schollz/progressbar v1.0.0/go.mod h1:/l9I7PC3L3erOuz54ghIRKUEFcosiWfLvJv+Eq26UMs=
github.com/schollz/progressbar/v3 v3.16.1 h1:RnF1neWZFzLCoGx8yp1yF7SDl4AzNDI5y4I0aUJRrZQ=
github.com/schollz/progressbar/v3 v3.16.1/go.mod h1:I2ILR76gz5VXqYMIY/LdLecvMHDPVcQm3W/MSKi1TME=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down
30 changes: 6 additions & 24 deletions migrations/kdvh/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,15 @@ import (
)

type DumpConfig struct {
BaseDir string `short:"p" long:"path" default:"./dumps/kdvh" description:"Location the dumped data will be stored in"`
TablesCmd string `short:"t" long:"table" default:"" description:"Optional comma separated list of table names. By default all available tables are processed"`
StationsCmd string `short:"s" long:"stnr" default:"" description:"Optional comma separated list of stations IDs. By default all station IDs are processed"`
ElementsCmd string `short:"e" long:"elem" default:"" description:"Optional comma separated list of element codes. By default all element codes are processed"`
Overwrite bool `long:"overwrite" description:"Overwrite any existing dumped files"`
Email []string `long:"email" description:"Optional email address used to notify if the program crashed"`

Tables []string
Stations []string
Elements []string
}

func (config *DumpConfig) setup() {
if config.TablesCmd != "" {
config.Tables = strings.Split(config.TablesCmd, ",")
}
if config.StationsCmd != "" {
config.Stations = strings.Split(config.StationsCmd, ",")
}
if config.ElementsCmd != "" {
config.Elements = strings.Split(config.ElementsCmd, ",")
}
BaseDir string `short:"p" long:"path" default:"./dumps/kdvh" description:"Location the dumped data will be stored in"`
Tables []string `short:"t" delimiter:"," long:"table" default:"" description:"Optional comma separated list of table names. By default all available tables are processed"`
Stations []string `short:"s" delimiter:"," long:"stnr" default:"" description:"Optional comma separated list of stations IDs. By default all station IDs are processed"`
Elements []string `short:"e" delimiter:"," long:"elem" default:"" description:"Optional comma separated list of element codes. By default all element codes are processed"`
Overwrite bool `long:"overwrite" description:"Overwrite any existing dumped files"`
Email []string `long:"email" delimiter:"," description:"Optional comma separated list of email addresses used to notify if the program crashed"`
}

func (config *DumpConfig) Execute([]string) error {
config.setup()

conn, err := sql.Open("pgx", os.Getenv("KDVH_PROXY_CONN"))
if err != nil {
slog.Error(err.Error())
Expand Down
31 changes: 9 additions & 22 deletions migrations/kdvh/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,15 @@ import (
)

type ImportConfig struct {
Verbose bool `short:"v" description:"Increase verbosity level"`
BaseDir string `short:"p" long:"path" default:"./dumps/kdvh" description:"Location the dumped data will be stored in"`
TablesCmd string `short:"t" long:"table" default:"" description:"Optional comma separated list of table names. By default all available tables are processed"`
StationsCmd string `short:"s" long:"station" default:"" description:"Optional comma separated list of stations IDs. By default all station IDs are processed"`
ElementsCmd string `short:"e" long:"elemcode" default:"" description:"Optional comma separated list of element codes. By default all element codes are processed"`
Sep string `long:"sep" default:"," description:"Separator character in the dumped files. Needs to be quoted"`
HasHeader bool `long:"header" description:"Add this flag if the dumped files have a header row"`
Skip string `long:"skip" choice:"data" choice:"flags" description:"Skip import of data or flags"`
Email []string `long:"email" description:"Optional email address used to notify if the program crashed"`

Tables []string
Stations []string
Elements []string
Verbose bool `short:"v" description:"Increase verbosity level"`
BaseDir string `short:"p" long:"path" default:"./dumps/kdvh" description:"Location the dumped data will be stored in"`
Tables []string `short:"t" long:"table" delimiter:"," default:"" description:"Optional comma separated list of table names. By default all available tables are processed"`
Stations []string `short:"s" long:"station" delimiter:"," default:"" description:"Optional comma separated list of stations IDs. By default all station IDs are processed"`
Elements []string `short:"e" long:"elemcode" delimiter:"," default:"" description:"Optional comma separated list of element codes. By default all element codes are processed"`
Sep string `long:"sep" default:"," description:"Separator character in the dumped files. Needs to be quoted"`
HasHeader bool `long:"header" description:"Add this flag if the dumped files have a header row"`
Skip string `long:"skip" choice:"data" choice:"flags" description:"Skip import of data or flags"`
Email []string `long:"email" delimiter:"," description:"Optional comma separated list of email addresses used to notify if the program crashed"`

OffsetMap map[StinfoKey]period.Period // Map of offsets used to correct (?) KDVH times for specific parameters
StinfoMap map[StinfoKey]StinfoParam // Map of metadata used to query timeseries ID in LARD
Expand All @@ -46,15 +42,6 @@ func (config *ImportConfig) setup() {
fmt.Printf("Error: '--sep' only accepts single-byte characters. Got %s", config.Sep)
os.Exit(1)
}
if config.TablesCmd != "" {
config.Tables = strings.Split(config.TablesCmd, ",")
}
if config.StationsCmd != "" {
config.Stations = strings.Split(config.StationsCmd, ",")
}
if config.ElementsCmd != "" {
config.Elements = strings.Split(config.ElementsCmd, ",")
}
config.CacheMetadata()
}

Expand Down

0 comments on commit 2b5ebf9

Please sign in to comment.