forked from TrueCloudLab/frostfs-locode-db
[#13] locode: Add command to list all locodes
Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
This commit is contained in:
parent
c7cb68f1f7
commit
1c14038948
4 changed files with 63 additions and 4 deletions
37
locode_list.go
Normal file
37
locode_list.go
Normal file
|
@ -0,0 +1,37 @@
|
|||
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"
|
||||
)
|
||||
|
||||
var (
|
||||
locodeListCmd = &cobra.Command{
|
||||
Use: "list",
|
||||
Short: "Print all locodes 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()
|
||||
|
||||
err = targetDB.IterateOverLocodes(func(locode string, geoPoint locodedb.Point) {
|
||||
cmd.Printf("%s\t %0.2f %0.2f\n", locode, geoPoint.Latitude(), geoPoint.Longitude())
|
||||
})
|
||||
ExitOnErr(cmd, "", err)
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
func initUtilLocodeListCmd() {
|
||||
flags := locodeListCmd.Flags()
|
||||
|
||||
flags.StringVar(&locodeInfoDBPath, locodeInfoDBFlag, "", locodeInfoDBFlagDesc)
|
||||
_ = locodeListCmd.MarkFlagRequired(locodeInfoDBFlag)
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue