molvs/cli.py
def main():
    """Main function for molvs command line interface."""

    # Root options
    parser = MolvsParser(epilog='use "molvs <command> -h" to show help for a specific command')
    subparsers = parser.add_subparsers(title='Available commands')

    # Options common to all commands

    common_parser = MolvsParser(add_help=False)
    common_parser.add_argument('infile', nargs='?', help='input filename', type=argparse.FileType('r'), default=sys.stdin)
    common_parser.add_argument('-i', '--intype', help='input filetype', choices=FILETYPES)
    common_parser.add_argument('-:', '--smiles', help='input SMILES instead of file', metavar='<smiles>')
    common_parser.add_argument('-O', '--outfile', help='output filename', type=argparse.FileType('w'), default=sys.stdout, metavar='<outfile>')

    # Standardize options
    standardize_parser = subparsers.add_parser('standardize', help='standardize a molecule', parents=[common_parser])
    standardize_parser.add_argument('-o', '--outtype', help='output filetype', choices=FILETYPES)
    standardize_parser.set_defaults(func=standardize_main)

    # Validate options
    validate_parser = subparsers.add_parser('validate', help='validate a molecule', parents=[common_parser])
    validate_parser.set_defaults(func=validate_main)

    args = parser.parse_args()
    try:
        args.func(args)
    except Exception as e:
        sys.stderr.write('Error: %s\n\n'.encode() % e.message)
        parser.print_help()
        sys.exit(2)
def main():
    # Root options
    parser = MolvsParser(epilog='use "molvs <command> -h" to show help for a specific command')
    subparsers = parser.add_subparsers(title='Available commands')

    # Options common to all commands

    common_parser = MolvsParser(add_help=False)
    common_parser.add_argument('infile', nargs='?', help='input filename', type=argparse.FileType('r'), default=sys.stdin)
    common_parser.add_argument('-i', '--intype', help='input filetype', choices=FILETYPES)
    common_parser.add_argument('-:', '--smiles', help='input SMILES instead of file', metavar='<smiles>')
    common_parser.add_argument('-O', '--outfile', help='output filename', type=argparse.FileType('w'), default=sys.stdout, metavar='<outfile>')

    # Standardize options
    standardize_parser = subparsers.add_parser('standardize', help='standardize a molecule', parents=[common_parser])
    standardize_parser.add_argument('-o', '--outtype', help='output filetype', choices=FILETYPES)
    standardize_parser.set_defaults(func=standardize_main)

    # Validate options
    validate_parser = subparsers.add_parser('validate', help='validate a molecule', parents=[common_parser])
    validate_parser.set_defaults(func=validate_main)

    args = parser.parse_args()
    try:
        args.func(args)
    except Exception as e:
        sys.stderr.write('Error: %s\n\n'.encode() % e.message)
        parser.print_help()
        sys.exit(2)
def main ( ) : # Root options parser = MolvsParser ( epilog = 'use "molvs <command> -h" to show help for a specific command' ) subparsers = parser . add_subparsers ( title = 'Available commands' ) # Options common to all commands common_parser = MolvsParser ( add_help = False ) common_parser . add_argument ( 'infile' , nargs = '?' , help = 'input filename' , type = argparse . FileType ( 'r' ) , default = sys . stdin ) common_parser . add_argument ( '-i' , '--intype' , help = 'input filetype' , choices = FILETYPES ) common_parser . add_argument ( '-:' , '--smiles' , help = 'input SMILES instead of file' , metavar = '<smiles>' ) common_parser . add_argument ( '-O' , '--outfile' , help = 'output filename' , type = argparse . FileType ( 'w' ) , default = sys . stdout , metavar = '<outfile>' ) # Standardize options standardize_parser = subparsers . add_parser ( 'standardize' , help = 'standardize a molecule' , parents = [ common_parser ] ) standardize_parser . add_argument ( '-o' , '--outtype' , help = 'output filetype' , choices = FILETYPES ) standardize_parser . set_defaults ( func = standardize_main ) # Validate options validate_parser = subparsers . add_parser ( 'validate' , help = 'validate a molecule' , parents = [ common_parser ] ) validate_parser . set_defaults ( func = validate_main ) args = parser . parse_args ( ) try : args . func ( args ) except Exception as e : sys . stderr . write ( 'Error: %s\n\n' . encode ( ) % e . message ) parser . print_help ( ) sys . exit ( 2 )
Main function for molvs command line interface.
Main function for molvs command line interface .