I'm using argparse to handle command-line arguments inside an application I'm developing. As it stands, everything works as advertised. However, I'm having an issue with the individual argument's help formatting.
optional arguments:
-k API_KEY, --key API_KEY
API Key to use when querying/updating records
-e EMAIL, --email EMAIL
Email to use when querying/updating records
In the help formatting above, I'm looking at how to solve the duplicate argument variable names (i.e. -k API_KEY, --key API_KEY
). This seems redundant and leads to the help formatting being on multiple lines vs a single, continuous line. Here is the relevant code.
if __name__ == '__main__':
parser=argparse.ArgumentParser(add_help=False)
parser_required=parser.add_argument_group('Required Arguments')
parser_required.add_argument('-k', '--key', dest='api_key', type=str, required=False, help='API Key to use when querying/updating records')
parser_required.add_argument('-e', '--email', dest='email', type=str, required=False, help='Email to use when querying/updating records')
I'm not totally sure how I can achieve this, though. Here is the desired output.
optional arguments:
-k, --key API Key to use when querying/updating records
-e, --email Email to use when querying/updating records