new way to group all arguments of the same class together

This commit is contained in:
Matthew Stidham
2021-02-09 16:22:33 -08:00
parent 69cf7b6b7b
commit 96ac1da9b8
2 changed files with 30 additions and 27 deletions

View File

@@ -494,7 +494,9 @@ class LFCliBase:
def create_basic_argparse(prog=None, def create_basic_argparse(prog=None,
formatter_class=None, formatter_class=None,
epilog=None, epilog=None,
description=None): description=None,
more_optional=None,
more_required=None):
if (prog is not None) or (formatter_class is not None) or (epilog is not None) or (description is not None): if (prog is not None) or (formatter_class is not None) or (epilog is not None) or (description is not None):
parser = argparse.ArgumentParser(prog=prog, parser = argparse.ArgumentParser(prog=prog,
formatter_class=formatter_class, formatter_class=formatter_class,
@@ -516,6 +518,12 @@ class LFCliBase:
optional.add_argument('--debug', help='Enable debugging', default=False, action="store_true") optional.add_argument('--debug', help='Enable debugging', default=False, action="store_true")
optional.add_argument('--proxy', nargs='?', default=None, optional.add_argument('--proxy', nargs='?', default=None,
help='Connection proxy like http://proxy.localnet:80 or https://user:pass@proxy.localnet:3128') help='Connection proxy like http://proxy.localnet:80 or https://user:pass@proxy.localnet:3128')
if more_optional is not None:
for x in more_optional:
if 'default' in x.keys():
optional.add_argument(x['name'], help=x['help'], default=x['default'])
else:
optional.add_argument(x['name'], help=x['help'])
#Required Args #Required Args
required.add_argument('--radio', help='radio EID, e.g: 1.wiphy2') required.add_argument('--radio', help='radio EID, e.g: 1.wiphy2')
@@ -523,6 +531,13 @@ class LFCliBase:
required.add_argument('--ssid', help='WiFi SSID for script objects to associate to') required.add_argument('--ssid', help='WiFi SSID for script objects to associate to')
required.add_argument('--passwd', '--password' ,'--key', help='WiFi passphrase/password/key', default="[BLANK]") required.add_argument('--passwd', '--password' ,'--key', help='WiFi passphrase/password/key', default="[BLANK]")
if more_required is not None:
for x in more_required:
if 'default' in x.keys():
required.add_argument(x['name'], help=x['help'], default=x['default'])
else:
required.add_argument(x['name'], help=x['help'])
return parser return parser
# use this function to add an event You can see these events when watching websocket_client at 8081 port # use this function to add an event You can see these events when watching websocket_client at 8081 port

View File

@@ -129,13 +129,22 @@ class IPV4VariableTime(Realm):
self._pass("PASS: Station build finished") self._pass("PASS: Station build finished")
def main(): def main():
optional=[]
optional.append({'name':'--mode','help':'Used to force mode of stations'})
optional.append({'name':'--ap','help':'Used to force a connection to a particular AP'})
optional.append({'name':'--output_format','help':'choose either csv or xlsx'})
optional.append({'name':'--report_file','help':'where you want to store results', 'default':None})
optional.append({'name':'--a_min','help':'--a_min bps rate minimum for side_a', 'default':256000})
optional.append({'name':'--b_min','help':'--b_min bps rate minimum for side_b', 'default':256000})
optional.append({'name':'--test_duration','help':'--test_duration sets the duration of the test', 'default':"2m"})
optional.append({'name':'--col_names','help':'Columns wished to be monitor', 'default':['name','tx bytes','rx bytes']})
optional.append({'name':'--compared_report','help':'report path and file which is wished to be compared with new report', 'default':None})
parser = LFCliBase.create_basic_argparse( parser = LFCliBase.create_basic_argparse(
prog='test_ipv4_variable_time.py', prog='test_ipv4_variable_time.py',
formatter_class=argparse.RawTextHelpFormatter, formatter_class=argparse.RawTextHelpFormatter,
epilog='''\ epilog='''\
Create stations to test connection and traffic on VAPs of varying security types (WEP, WPA, WPA2, WPA3, Open) Create stations to test connection and traffic on VAPs of varying security types (WEP, WPA, WPA2, WPA3, Open)
''', ''',
description='''\ description='''\
test_ipv4_variable_time.py: test_ipv4_variable_time.py:
-------------------- --------------------
@@ -236,30 +245,9 @@ python3 ./test_ipv4_variable_time.py
Elapsed | 'elapsed' Elapsed | 'elapsed'
Destination Addr | 'destination addr' Destination Addr | 'destination addr'
Source Addr | 'source addr' Source Addr | 'source addr'
''') ''',
more_optional=optional)
required_args=None
for group in parser._action_groups:
if group.title == "required arguments":
required_args=group
break
#if required_args is not None:
optional_args=None
for group in parser._action_groups:
if group.title == "optional arguments":
optional_args=group
break
if optional_args is not None:
optional_args.add_argument('--mode',help='Used to force mode of stations')
optional_args.add_argument('--ap',help='Used to force a connection to a particular AP')
optional_args.add_argument('--output_format', help='choose either csv or xlsx')
optional_args.add_argument('--report_file',help='where you want to store results', default=None)
optional_args.add_argument('--a_min', help='--a_min bps rate minimum for side_a', default=256000)
optional_args.add_argument('--b_min', help='--b_min bps rate minimum for side_b', default=256000)
optional_args.add_argument('--test_duration', help='--test_duration sets the duration of the test', default="2m")
optional_args.add_argument('--col_names', help='Columns wished to be monitor', default=['name','tx bytes','rx bytes'])
optional_args.add_argument('--compared_report',help='report path and file which is wished to be compared with new report', default=None)
args = parser.parse_args() args = parser.parse_args()
num_sta = 2 num_sta = 2