From ae49e0e5808161bb2eb64695d3347d6e8be8b544 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Thu, 22 Dec 2016 09:41:28 +0200 Subject: [PATCH] Add custom usage for CDC schema generator The usage prints the required arguments and describes what this tool is intended for. --- .../modules/protocol/examples/cdc_schema.go | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/server/modules/protocol/examples/cdc_schema.go b/server/modules/protocol/examples/cdc_schema.go index a6ae13814..b724d75ba 100644 --- a/server/modules/protocol/examples/cdc_schema.go +++ b/server/modules/protocol/examples/cdc_schema.go @@ -19,6 +19,7 @@ import ( "os" "regexp" "strconv" + "fmt" ) import _ "github.com/go-sql-driver/mysql" @@ -29,6 +30,19 @@ var user = flag.String("user", "", "Server user") var passwd = flag.String("password", "", "Server password") var debug = flag.Bool("debug", false, "Debug output") +func PrintUsage() { + fmt.Println(`Usage: cdc_schema [OPTIONS] + +This program generates CDC schema files for all the tables in a database. The +schema files need to be generated if the binary log files do not contain the +CREATE TABLE events that define the table layout. + +The "user" and "password" flags are required. +`) + + flag.PrintDefaults() +} + // Avro field type Field struct { Name string `json:"name"` @@ -64,12 +78,11 @@ func (f *Field) ToAvroType() { f.Type = "string" case "tinyblob", "blob", "mediumblob", "longblob", "binary", "varbinary": f.Type = "bytes" - case "int", "smallint", "mediumint", "integer", "tinyint", "short", - "decimal", "bit": + case "int", "smallint", "mediumint", "integer", "tinyint", "short", "bit": f.Type = "int" case "float": f.Type = "float" - case "double": + case "double", "decimal": f.Type = "double" case "null": f.Type = "null" @@ -118,8 +131,13 @@ func main() { log.Fatal("Error: ", err) } + flag.Usage = PrintUsage; flag.Parse() + if len(*user) == 0 || len(*passwd) == 0 { + log.Fatal("Both the -user and -password flags are mandatory. See output of -help for more details.") + } + var connect_str string = *user + ":" + *passwd + "@tcp(" + *host + ":" + strconv.Itoa(*port) + ")/" if *debug {