49 lines
915 B
Go
49 lines
915 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var rootCmd = &cobra.Command{
|
|
Use: "frostfs-locode-db",
|
|
Short: "Command Line Tool to work with FrostFS' UN/LOCODE databases",
|
|
Long: "This tool can be used for generating or accessing FrostFS UN/LOCODE databases.",
|
|
}
|
|
|
|
func ExitOnErr(cmd *cobra.Command, errFmt string, err error) {
|
|
if err == nil {
|
|
return
|
|
}
|
|
|
|
if errFmt != "" {
|
|
err = fmt.Errorf(errFmt, err)
|
|
}
|
|
|
|
const (
|
|
_ = iota
|
|
internal
|
|
aclDenied
|
|
)
|
|
cmd.PrintErrln(err)
|
|
if cmd.PersistentPostRun != nil {
|
|
cmd.PersistentPostRun(cmd, nil)
|
|
}
|
|
os.Exit(internal)
|
|
}
|
|
|
|
func main() {
|
|
// use stdout as default output for cmd.Print()
|
|
rootCmd.SetOut(os.Stdout)
|
|
|
|
initUtilLocodeGenerateCmd()
|
|
initUtilLocodeInfoCmd()
|
|
initUtilLocodeListCmd()
|
|
rootCmd.AddCommand(locodeGenerateCmd, locodeInfoCmd, locodeListCmd)
|
|
err := rootCmd.Execute()
|
|
if err != nil {
|
|
ExitOnErr(rootCmd, "", err)
|
|
}
|
|
}
|