imposm3/cmd/imposm/main.go

85 lines
1.7 KiB
Go
Raw Normal View History

2016-11-25 15:53:58 +03:00
package main
2013-11-19 18:39:57 +04:00
import (
"fmt"
golog "log"
"os"
"runtime"
2018-04-17 22:06:55 +03:00
"strings"
2013-11-19 18:39:57 +04:00
2016-11-25 15:53:58 +03:00
"github.com/omniscale/imposm3"
2014-08-04 17:19:35 +04:00
"github.com/omniscale/imposm3/cache/query"
"github.com/omniscale/imposm3/config"
"github.com/omniscale/imposm3/import_"
"github.com/omniscale/imposm3/logging"
"github.com/omniscale/imposm3/stats"
2016-12-06 13:00:52 +03:00
"github.com/omniscale/imposm3/update"
2013-11-19 18:39:57 +04:00
)
var log = logging.NewLogger("")
func PrintCmds() {
fmt.Fprintf(os.Stderr, "Usage: %s COMMAND [args]\n\n", os.Args[0])
fmt.Println("Available commands:")
fmt.Println("\timport")
fmt.Println("\tdiff")
2016-11-25 15:53:58 +03:00
fmt.Println("\trun")
2013-11-19 18:39:57 +04:00
fmt.Println("\tquery-cache")
fmt.Println("\tversion")
}
func Main(usage func()) {
golog.SetFlags(golog.LstdFlags | golog.Lshortfile)
if os.Getenv("GOMAXPROCS") == "" {
runtime.GOMAXPROCS(runtime.NumCPU())
}
if len(os.Args) <= 1 {
usage()
logging.Shutdown()
os.Exit(1)
}
2018-04-17 22:06:55 +03:00
if strings.HasSuffix(os.Args[0], "imposm3") {
fmt.Println("WARNING: Use imposm binary instead of imposm3!")
}
2013-11-19 18:39:57 +04:00
switch os.Args[1] {
case "import":
2018-06-07 21:23:06 +03:00
opts := config.ParseImport(os.Args[2:])
if opts.Base.Httpprofile != "" {
stats.StartHttpPProf(opts.Base.Httpprofile)
2013-11-19 18:39:57 +04:00
}
2018-06-07 21:23:06 +03:00
import_.Import(opts)
2013-11-19 18:39:57 +04:00
case "diff":
2018-06-07 21:23:06 +03:00
opts, files := config.ParseDiffImport(os.Args[2:])
2013-11-19 18:39:57 +04:00
2018-06-07 21:23:06 +03:00
if opts.Httpprofile != "" {
stats.StartHttpPProf(opts.Httpprofile)
2013-11-19 18:39:57 +04:00
}
2018-06-07 21:23:06 +03:00
update.Diff(opts, files)
2016-11-25 15:53:58 +03:00
case "run":
2018-06-07 21:23:06 +03:00
opts := config.ParseRunImport(os.Args[2:])
2013-11-19 18:39:57 +04:00
2018-06-07 21:23:06 +03:00
if opts.Httpprofile != "" {
stats.StartHttpPProf(opts.Httpprofile)
2016-11-25 15:53:58 +03:00
}
2018-06-07 21:23:06 +03:00
update.Run(opts)
2013-11-19 18:39:57 +04:00
case "query-cache":
query.Query(os.Args[2:])
case "version":
2016-11-25 15:53:58 +03:00
fmt.Println(imposm3.Version)
2013-11-19 18:39:57 +04:00
os.Exit(0)
default:
usage()
log.Fatalf("invalid command: '%s'", os.Args[1])
}
logging.Shutdown()
os.Exit(0)
}
2016-11-25 15:53:58 +03:00
func main() {
Main(PrintCmds)
}