python cmd2 multiarg解析器

问题描述

我有4个参数,例如:a,b,c,d。用户可以选择输入a或b或c或d,否则a或c只能输入'a'或'd',就像所有概率一样。为此,如何编写参数解析器。

subscription_parser = argparse.ArgumentParser()
subscribe_parent =  argparse.ArgumentParser(add_help=False)
stream_parsers = subscription_parser.add_subparsers(title='subcommands',help='subcommand help')
stream_parser_sub = stream_parsers.add_parser('stream',parents=[subscribe_parent],help='callhome_port help')
stream_parser_sub.add_argument('stream',type=str,help='stream name')
# create_parser_filter = argparse.ArgumentParser()
filter_parser = stream_parser_sub.add_subparsers(title='subcommands',help='subcommand help')
filter_sub_parser = filter_parser.add_parser('filter',help='callhome_port help')
filter_sub_parser.add_argument('filter',help='filter value')
# create_parser_start = argparse.ArgumentParser()
start_parser = filter_sub_parser.add_subparsers(title='subcommands',help='subcommand help')
start_sub_parser = start_parser.add_parser('starttime',help='callhome_port help')
start_sub_parser.add_argument('start',help='starttime')
# create_parser_stop = argparse.ArgumentParser()
stop_parser = start_sub_parser.add_subparsers(title='subcommands',help='subcommand help')
stop_sub_parser = stop_parser.add_parser('stoptime',help='callhome_port help')
stop_sub_parser.add_argument('stop',help='stoptime')

感谢前进

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)