def parse_args():
    """
    Parse the command line arguments
    """
    parser = argparse.ArgumentParser(
        description="Import existing secrets to YubiHSM eco system",
        add_help=True, formatter_class=argparse.ArgumentDefaultsHelpFormatter,)
    parser.add_argument('-D', '--device',
                        dest='device',
                        default=default_device,
                        required=False,
                        help='YubiHSM device',
                        )
    parser.add_argument('-O', '--output-dir', '--aead-dir',
                        dest='output_dir',
                        default=default_dir,
                        required=False,
                        help='Output directory (AEAD base dir)',
                        metavar='DIR',
                        )
    parser.add_argument('-v', '--verbose',
                        dest='verbose',
                        action='store_true', default=False,
                        help='Enable verbose operation',
                        )
    parser.add_argument('--debug',
                        dest='debug',
                        action='store_true', default=False,
                        help='Enable debug operation',
                        )
    parser.add_argument('--public-id-chars',
                        dest='public_id_chars',
                        type=int, default=default_public_id_chars,
                        required=False,
                        help='Number of chars in generated public ids',
                        metavar='NUM',
                        )
    parser.add_argument(
        '--key-handles',
        dest='key_handles',
        nargs='+',
        required=True,
        help='Key handle(s) to encrypt the imported secrets with',
        metavar='HANDLE',
     )
    parser.add_argument('--internal-db',
                        dest='internal_db',
                        action='store_true', default=False,
                        help='Store key in YubiHSM internal database',
                        )
    parser.add_argument(
        '--aes-key',
        dest='aes_key',
        required=False,
        default=None,
        help='AES key to use when generating AEADs (no YubiHSM)',
        metavar='HEXSTR',
     )
    parser.add_argument('--random-nonce',
                        dest='random_nonce',
                        action='store_true', default=False,
                        help='Let the HSM generate random nonce',
                        )

    args = parser.parse_args()
    if args.internal_db:
        if len(args.key_handles) != 1:
            sys.stderr.write("--internal-db requires exactly one key handle.\n")
            sys.exit(1)
        if args.aes_key:
            sys.stderr.write("--internal-db incompatible with --aes-key.\n")
            sys.exit(1)
    return args
def parse_args ( ) : parser = argparse . ArgumentParser ( description = "Import existing secrets to YubiHSM eco system" , add_help = True , formatter_class = argparse . ArgumentDefaultsHelpFormatter , ) parser . add_argument ( '-D' , '--device' , dest = 'device' , default = default_device , required = False , help = 'YubiHSM device' , ) parser . add_argument ( '-O' , '--output-dir' , '--aead-dir' , dest = 'output_dir' , default = default_dir , required = False , help = 'Output directory (AEAD base dir)' , metavar = 'DIR' , ) parser . add_argument ( '-v' , '--verbose' , dest = 'verbose' , action = 'store_true' , default = False , help = 'Enable verbose operation' , ) parser . add_argument ( '--debug' , dest = 'debug' , action = 'store_true' , default = False , help = 'Enable debug operation' , ) parser . add_argument ( '--public-id-chars' , dest = 'public_id_chars' , type = int , default = default_public_id_chars , required = False , help = 'Number of chars in generated public ids' , metavar = 'NUM' , ) parser . add_argument ( '--key-handles' , dest = 'key_handles' , nargs = '+' , required = True , help = 'Key handle(s) to encrypt the imported secrets with' , metavar = 'HANDLE' , ) parser . add_argument ( '--internal-db' , dest = 'internal_db' , action = 'store_true' , default = False , help = 'Store key in YubiHSM internal database' , ) parser . add_argument ( '--aes-key' , dest = 'aes_key' , required = False , default = None , help = 'AES key to use when generating AEADs (no YubiHSM)' , metavar = 'HEXSTR' , ) parser . add_argument ( '--random-nonce' , dest = 'random_nonce' , action = 'store_true' , default = False , help = 'Let the HSM generate random nonce' , ) args = parser . parse_args ( ) if args . internal_db : if len ( args . key_handles ) != 1 : sys . stderr . write ( "--internal-db requires exactly one key handle.\n" ) sys . exit ( 1 ) if args . aes_key : sys . stderr . write ( "--internal-db incompatible with --aes-key.\n" ) sys . exit ( 1 ) return args
Parse the command line arguments