github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/dm/debug-tools/binlog-event-blackhole/config.go (about)

     1  // Copyright 2019 PingCAP, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // See the License for the specific language governing permissions and
    12  // limitations under the License.
    13  
    14  package main
    15  
    16  import (
    17  	"flag"
    18  
    19  	"github.com/pingcap/errors"
    20  )
    21  
    22  // config is the configuration used by this binlog-event-blackhole.
    23  type config struct {
    24  	*flag.FlagSet
    25  
    26  	logLevel  string
    27  	logFile   string
    28  	logFormat string
    29  
    30  	mode int
    31  
    32  	addr       string
    33  	username   string
    34  	password   string
    35  	serverID   int
    36  	binlogName string
    37  	binlogPos  int
    38  }
    39  
    40  // newConfig creates a new config instance.
    41  func newConfig() *config {
    42  	cfg := &config{
    43  		FlagSet: flag.NewFlagSet("binlog-event-blackhole", flag.ContinueOnError),
    44  	}
    45  	fs := cfg.FlagSet
    46  
    47  	fs.StringVar(&cfg.logLevel, "L", "info", "log level: debug, info, warn, error, fatal")
    48  	fs.StringVar(&cfg.logFile, "log-file", "", "log file path")
    49  	fs.StringVar(&cfg.logFormat, "log-format", "text", `the format of the log, "text" or "json"`)
    50  
    51  	fs.IntVar(&cfg.mode, "mode", 0, "event read mode.\n1: read packet with go-mysql;\n2: read packet without go-mysql;\n3: read binary data but do nothing")
    52  
    53  	fs.StringVar(&cfg.addr, "addr", "", "master's address")
    54  	fs.StringVar(&cfg.username, "u", "", "master's username")
    55  	fs.StringVar(&cfg.password, "p", "", "password for `username`")
    56  	fs.IntVar(&cfg.serverID, "server-id", 0, "slave's server-id")
    57  	fs.StringVar(&cfg.binlogName, "binlog-name", "", "startup binlog filename")
    58  	fs.IntVar(&cfg.binlogPos, "binlog-pos", 4, "startup binlog position")
    59  
    60  	return cfg
    61  }
    62  
    63  // parse parses flag definitions from the argument list.
    64  func (c *config) parse(args []string) error {
    65  	err := c.FlagSet.Parse(args)
    66  	return errors.Trace(err)
    67  }