replaced conditional options with subparsers
parent
8cc9574072
commit
1204338902
|
|
@ -0,0 +1,55 @@
|
|||
"""The Dazed Gerbil Connection Manager"""
|
||||
import argparse
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(prog='dgcm',
|
||||
usage='dgcm [OPTIONS]... [SUBCOMMAND [OPTIONS]]',
|
||||
description='The Dazed Gerbil Connection Manager')
|
||||
|
||||
subparsers = parser.add_subparsers(title='Subcommands')
|
||||
|
||||
parser_add = subparsers.add_parser('add',
|
||||
usage='dgcm [OPTIONS]... add [OPTIONS]',
|
||||
help='add a new connection')
|
||||
parser_add.add_argument('-U', '--user', help='the user to connect as')
|
||||
parser_add.add_argument('-H', '--host', help='specify the host for the connection')
|
||||
parser_add.add_argument('-P', '--port', help='specify the port if non-standard')
|
||||
parser_add.add_argument('-S', '--shortname', help='provide a short name for faster access')
|
||||
|
||||
parser_list = subparsers.add_parser('list',
|
||||
usage='dgcm [OPTIONS]... list [OPTIONS]',
|
||||
help='list the existing connections')
|
||||
|
||||
parser_connect = subparsers.add_parser('connect',
|
||||
usage='dgcm [OPTIONS]... connect [OPTIONS] shortname',
|
||||
help='connect to an existing connection')
|
||||
parser_connect.add_argument('shortname', help='the shortname to connect to')
|
||||
|
||||
parser_remove = subparsers.add_parser('remove',
|
||||
usage='dgcm [OPTIONS]... remove [OPTIONS] shortname',
|
||||
help='remove an existing connection')
|
||||
parser_remove.add_argument('shortname', help='the shortname for the connection to remove')
|
||||
|
||||
parser_update = subparsers.add_parser('update',
|
||||
usage='dgcm [OPTIONS]... update [OPTIONS] existing_shortname',
|
||||
help='update an existing connection')
|
||||
parser_update.add_argument('-U', '--user', help='provide the new username')
|
||||
parser_update.add_argument('-H', '--host', help='provide the new hostname')
|
||||
parser_update.add_argument('-P', '--port', help='provide the new port')
|
||||
parser_update.add_argument('-S', '--shortname', help='provide the new shortname')
|
||||
parser_update.add_argument('existing_shortname', help='the existing shortname to update')
|
||||
|
||||
group_mutually_exclusive = parser.add_mutually_exclusive_group()
|
||||
group_mutually_exclusive.add_argument('-v', '--verbose',
|
||||
action='count', default=0,
|
||||
help='increase output verbosity')
|
||||
group_mutually_exclusive.add_argument('-q', '--quiet', action='store_true', help='disable output')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
print(args)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
35
dgcm/main.py
35
dgcm/main.py
|
|
@ -1,35 +0,0 @@
|
|||
"""The Dazed Gerbil Connection Manager"""
|
||||
import argparse
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(prog='dgcm',
|
||||
# usage='dgcm [OPTIONS]...',
|
||||
description='The Dazed Gerbil Connection Manager')
|
||||
|
||||
command_group = parser.add_argument_group('Command options')
|
||||
command_group.add_argument('-a', '--add', action='store_true', help='add a new connection')
|
||||
command_group.add_argument('-l', '--list', action='store_true', help='list the existing connections')
|
||||
command_group.add_argument('-c', '--connect', action='store_true', help='connect to an existing connection')
|
||||
command_group.add_argument('-r', '--remove', action='store_true', help='remove an existing connection')
|
||||
command_group.add_argument('-u', '--update', action='store_true', help='update an existing connection')
|
||||
|
||||
connection_group = parser.add_argument_group('Connection options')
|
||||
connection_group.add_argument('-U', '--user', help='the user to connect as')
|
||||
connection_group.add_argument('-H', '--host', help='specify the host for the connection')
|
||||
connection_group.add_argument('-P', '--port', help='specify the port if non-standard')
|
||||
connection_group.add_argument('-S', '--shortname', help='provide a short name for faster access')
|
||||
|
||||
mutually_exclusive_group = parser.add_mutually_exclusive_group()
|
||||
mutually_exclusive_group.add_argument('-v', '--verbose', action='count', default=0, help='increase output verbosity')
|
||||
mutually_exclusive_group.add_argument('-q', '--quiet', action='store_true', help='disable output')
|
||||
|
||||
parser.add_argument('connection', action='store_false', help='shortname of the connection to use')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
print(args)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Loading…
Reference in New Issue