2018-04-17 14:30:34 -07:00
|
|
|
import argparse
|
|
|
|
|
|
|
|
DEFAULT_NODES = 2
|
|
|
|
DEFAULT_TIME = 10
|
|
|
|
DEFAULT_STEP = 1
|
|
|
|
|
|
|
|
|
2019-10-22 15:13:28 -07:00
|
|
|
def parse(name):
|
2019-10-18 10:33:31 -07:00
|
|
|
parser = argparse.ArgumentParser(description=f"Run {name} example")
|
2019-09-10 15:10:24 -07:00
|
|
|
parser.add_argument(
|
|
|
|
"-n",
|
|
|
|
"--nodes",
|
|
|
|
type=int,
|
|
|
|
default=DEFAULT_NODES,
|
|
|
|
help="number of nodes to create in this example",
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
2020-02-04 09:48:37 -08:00
|
|
|
"-c",
|
|
|
|
"--count",
|
2019-09-10 15:10:24 -07:00
|
|
|
type=int,
|
|
|
|
default=DEFAULT_TIME,
|
2020-02-04 09:48:37 -08:00
|
|
|
help="number of time to ping node",
|
2019-09-10 15:10:24 -07:00
|
|
|
)
|
2018-04-17 14:30:34 -07:00
|
|
|
|
2019-10-22 15:13:28 -07:00
|
|
|
args = parser.parse_args()
|
2018-04-17 14:30:34 -07:00
|
|
|
|
2019-10-22 15:13:28 -07:00
|
|
|
if args.nodes < 2:
|
|
|
|
parser.error(f"invalid min number of nodes: {args.nodes}")
|
2020-02-04 09:48:37 -08:00
|
|
|
if args.count < 1:
|
|
|
|
parser.error(f"invalid ping count({args.count}), count must be greater than 0")
|
2018-04-17 14:30:34 -07:00
|
|
|
|
2019-10-22 15:13:28 -07:00
|
|
|
return args
|