2022-05-25 16:15:27 +00:00
|
|
|
package util
|
|
|
|
|
|
|
|
import (
|
2023-01-16 09:20:16 +00:00
|
|
|
commonCmd "github.com/TrueCloudLab/frostfs-node/cmd/internal/common"
|
2022-12-23 17:35:35 +00:00
|
|
|
locodedb "github.com/TrueCloudLab/frostfs-node/pkg/util/locode/db"
|
|
|
|
locodebolt "github.com/TrueCloudLab/frostfs-node/pkg/util/locode/db/boltdb"
|
2022-05-25 16:15:27 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
locodeInfoDBFlag = "db"
|
|
|
|
locodeInfoCodeFlag = "locode"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
locodeInfoDBPath string
|
|
|
|
locodeInfoCode string
|
|
|
|
|
|
|
|
locodeInfoCmd = &cobra.Command{
|
|
|
|
Use: "info",
|
2023-01-27 10:44:39 +00:00
|
|
|
Short: "Print information about UN/LOCODE from FrostFS database",
|
2022-05-25 16:15:27 +00:00
|
|
|
Run: func(cmd *cobra.Command, _ []string) {
|
|
|
|
targetDB := locodebolt.New(locodebolt.Prm{
|
|
|
|
Path: locodeInfoDBPath,
|
|
|
|
}, locodebolt.ReadOnly())
|
|
|
|
|
|
|
|
err := targetDB.Open()
|
2023-01-16 09:20:16 +00:00
|
|
|
commonCmd.ExitOnErr(cmd, "", err)
|
2022-05-25 16:15:27 +00:00
|
|
|
|
|
|
|
defer targetDB.Close()
|
|
|
|
|
|
|
|
record, err := locodedb.LocodeRecord(targetDB, locodeInfoCode)
|
2023-01-16 09:20:16 +00:00
|
|
|
commonCmd.ExitOnErr(cmd, "", err)
|
2022-05-25 16:15:27 +00:00
|
|
|
|
|
|
|
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()
|
|
|
|
|
2023-01-27 10:44:39 +00:00
|
|
|
flags.StringVar(&locodeInfoDBPath, locodeInfoDBFlag, "", "Path to FrostFS UN/LOCODE database")
|
2022-05-25 16:15:27 +00:00
|
|
|
_ = locodeInfoCmd.MarkFlagRequired(locodeInfoDBFlag)
|
|
|
|
|
|
|
|
flags.StringVar(&locodeInfoCode, locodeInfoCodeFlag, "", "UN/LOCODE")
|
|
|
|
_ = locodeInfoCmd.MarkFlagRequired(locodeInfoCodeFlag)
|
|
|
|
}
|