forked from TrueCloudLab/frostfs-locode-db
[#7] Add local tool for building database file
Added frostfs-locode-db CLI utility that can generate and view UN/LOCODE database files. Go package git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/locode copied to this repository to eliminate interdependency between frostfs-node and frostfs-locode-db projects. The process of building database files reduced to starting make command. Signed-off-by: George Bartolomey <george@bh4.ru>
This commit is contained in:
parent
7e523f1a28
commit
840b20538b
30 changed files with 2317 additions and 4 deletions
55
locode_info.go
Normal file
55
locode_info.go
Normal file
|
@ -0,0 +1,55 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
locodedb "git.frostfs.info/TrueCloudLab/frostfs-locode-db/pkg/locode/db"
|
||||
locodebolt "git.frostfs.info/TrueCloudLab/frostfs-locode-db/pkg/locode/db/boltdb"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
const (
|
||||
locodeInfoDBFlag = "db"
|
||||
locodeInfoCodeFlag = "locode"
|
||||
)
|
||||
|
||||
var (
|
||||
locodeInfoDBPath string
|
||||
locodeInfoCode string
|
||||
|
||||
locodeInfoCmd = &cobra.Command{
|
||||
Use: "info",
|
||||
Short: "Print information about UN/LOCODE from FrostFS database",
|
||||
Run: func(cmd *cobra.Command, _ []string) {
|
||||
targetDB := locodebolt.New(locodebolt.Prm{
|
||||
Path: locodeInfoDBPath,
|
||||
}, locodebolt.ReadOnly())
|
||||
|
||||
err := targetDB.Open()
|
||||
ExitOnErr(cmd, "", err)
|
||||
|
||||
defer targetDB.Close()
|
||||
|
||||
record, err := locodedb.LocodeRecord(targetDB, locodeInfoCode)
|
||||
ExitOnErr(cmd, "", err)
|
||||
|
||||
cmd.Printf("Country: %s\n", record.CountryName())
|
||||
cmd.Printf("Location: %s\n", record.LocationName())
|
||||
cmd.Printf("Continent: %s\n", record.Continent())
|
||||
if subDivCode := record.SubDivCode(); subDivCode != "" {
|
||||
cmd.Printf("Subdivision: [%s] %s\n", subDivCode, record.SubDivName())
|
||||
}
|
||||
|
||||
geoPoint := record.GeoPoint()
|
||||
cmd.Printf("Coordinates: %0.2f, %0.2f\n", geoPoint.Latitude(), geoPoint.Longitude())
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
func initUtilLocodeInfoCmd() {
|
||||
flags := locodeInfoCmd.Flags()
|
||||
|
||||
flags.StringVar(&locodeInfoDBPath, locodeInfoDBFlag, "", "Path to FrostFS UN/LOCODE database")
|
||||
_ = locodeInfoCmd.MarkFlagRequired(locodeInfoDBFlag)
|
||||
|
||||
flags.StringVar(&locodeInfoCode, locodeInfoCodeFlag, "", "UN/LOCODE")
|
||||
_ = locodeInfoCmd.MarkFlagRequired(locodeInfoCodeFlag)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue