def main(prog='python3 -m annotator.runs'): parser = dsargparse.ArgumentParser(main=main, prog=prog) subparsers = parser.add_subparsers(help='command') subparsers.add_parser(train.train, add_arguments_auto=True) subparsers.add_parser(evaluate.evaluate, add_arguments_auto=True) subparsers.add_parser(extract.extract_all, add_arguments_auto=True) subparsers.add_parser(data.generate_tfrecords, add_arguments_auto=True) return parser.parse_and_run()
def main(): """Main function. """ logging.basicConfig(level=logging.INFO, stream=sys.stderr) parser = dsargparse.ArgumentParser(main=main) # Dataset parser.add_argument( "dataset", choices=sorted(helper.DATASETS.keys()), help=( "choose one dataset to be analyzed.\n" "If choose `file`, give a file path via dataset-param with file key\n" "i.e. --dataset-param file=<path>.")) parser.add_argument( "--dataset-param", action="append", default=[], dest="dataset_param", help=( "key and value pair which are connected with '='.\n" "This option can be set multiply.")) # Algorithm parser.add_argument( "method", choices=sorted(helper.ALGORITHMS.keys()), help="choose one method.") parser.add_argument( "--method_param", action="append", default=[], help=( "key and value pair which are connected with '='.\n" "This option can be set multiply.")) parser.add_argument( "--loop", type=int, default=20, help="At most the given number of iteration will be run (default: 20).") parser.add_argument( "--threshold", type=float, default=10^-5, help=( "Loop ends the update will be smaller than the given number " "(default: 10^-5).")) # Output configuration parser.add_argument( "--output", default=sys.stdout, type=dsargparse.FileType("w"), # pylint: disable=no-member help="file path to store results (Default: stdout).") # Run try: return run(**vars(parser.parse_args())) except KeyboardInterrupt: return "Canceled" except Exception as e: # pylint: disable=broad-except logging.exception("Untracked exception occurred.") return e.message finally: logging.shutdown()
def main(): """ The main function. """ parser = dsargparse.ArgumentParser(main=main) subparsers = parser.add_subparsers() greeting_cmd = subparsers.add_parser(greeting) greeting_cmd.add_argument("title") greeting_cmd.add_argument("name") goodbye_cmd = subparsers.add_parser(goodbye) goodbye_cmd.add_argument("name") return parser.parse_and_run()
def main(): """The main function. """ if not ALGORITHMS: logging.error("No algorithms are installed.") sys.exit(1) parser = dsargparse.ArgumentParser(main=main) parser.add_argument("method", choices=sorted(ALGORITHMS.keys())) parser.add_argument( "--output", default=sys.stdout, type=dsargparse.FileType("w"), # pylint: disable=no-member help="file path to store results (Default: stdout).") parser.add_argument("--loop", type=int, default=20) parser.add_argument("--threshold", type=float, default=10 ^ -3) parser.add_argument( "--param", action="append", default=[], help=("key and value pair which are connected with '='.\n" "This option can be set multiply.")) run(**vars(parser.parse_args()))
def main(): colorama.init(autoreset=True) # create the top-level alfeios parser parser = dsargparse.ArgumentParser( description='Enrich your command-line shell with Herculean cleaning ' 'capabilities', usage='alfeios [-h] <command> [<args>]', epilog="See 'alfeios <command> -h' for help on a specific command", formatter_class=dsargparse.RawTextHelpFormatter) parser.add_argument('-V', '--version', action='version', version=__version__) subparsers_factory = parser.add_subparsers( title='Alfeios commands', prog='alfeios', # mandatory for subcommand help # as usage has been overwritten in alfeios parser metavar=' ' * 21 # hack to display help on one-liners ) # create the parser for the index command parser_i = subparsers_factory.add_parser( func=alfeios.api.index, aliases=['idx', 'i'], help='Index content of a root directory', epilog='''example: alfeios index alfeios idx D:/Pictures alfeios i ''', formatter_class=dsargparse.RawTextHelpFormatter) parser_i.add_argument('path', nargs='?', default='.', help='path to the root directory' ' - default is current working directory') # create the parser for the duplicate command parser_d = subparsers_factory.add_parser( func=alfeios.api.duplicate, aliases=['dup', 'd'], help='Find duplicate content in a root directory', epilog='''example: alfeios duplicate alfeios dup -s D:/Pictures alfeios d D:/Pictures/.alfeios/2020_01_29_10_29_39_listing.json ''', formatter_class=dsargparse.RawTextHelpFormatter) parser_d.add_argument( 'path', nargs='?', default='.', help='path to the root directory (or listing.json) - ' 'default is current working directory') parser_d.add_argument( '-s', '--save-index', action='store_true', help='save the listing.json, tree.json and forbidden.json files in the' ' root directory') # create the parser for the missing command parser_m = subparsers_factory.add_parser( func=alfeios.api.missing, aliases=['mis', 'm'], help='Find missing content in a new root directory from an old root' ' directory', epilog='''examples: alfeios missing D:/Pictures E:/AllPictures alfeios mis -s D:/Pictures E:/AllPictures alfeios m D:/Pictures/.alfeios/2020_01_29_10_29_39_listing.json E:/AllPics ''', formatter_class=dsargparse.RawTextHelpFormatter) parser_m.add_argument( 'old_path', help='path to the old root directory (or old listing.json)') parser_m.add_argument( 'new_path', help='path to the new root directory (or new listing.json)') parser_m.add_argument( '-s', '--save-index', action='store_true', help='save the listing.json, tree.json and forbidden.json files in the' ' 2 root directories') # parse command line and call appropriate function if len(sys.argv) == 1 or sys.argv[1] in ['help', 'h']: parser.print_help(sys.stderr) sys.exit(1) try: return parser.parse_and_run() except KeyboardInterrupt: print(''' Process interrupted''', file=sys.stderr) sys.exit(1)
def main(): parser = dsargparse.ArgumentParser(main=main) subparser = parser.add_subparsers() subparser.add_parser(extract, add_arguments_auto=True) return parser.parse_and_run()
def main(): """The main function. """ logging.basicConfig(level=logging.INFO, stream=sys.stderr) parser = dsargparse.ArgumentParser(main=main) parser.add_argument("--output", default=sys.stdout, type=dsargparse.FileType("w"), help="Output file (default: stdout).") parser.add_argument( "dataset", choices=helper.DATASETS.keys(), help= ("choose one dataset to be analyzed.\n" "If choose `file`, give a file path via dataset-param with file key\n" "i.e. --dataset-param file=<path>.")) parser.add_argument( "--dataset-param", action="append", default=[], dest="dataset_param", help=("key and value pair which are connected with '='.\n" "This option can be set multiply.")) parser.add_argument("--additional-dataset", action="append", default=[], dest="additional", help=("add an additional dataset file to be loaded.\n" "This option can be set multiply.")) subparsers = parser.add_subparsers() # Reviewer reviewer_cmd = subparsers.add_parser( name="reviewer", help="analyze reviewer information").add_subparsers() retrieve_reviewers_cmd = reviewer_cmd.add_parser(retrieve_reviewers, name="retrieve") retrieve_reviewers_cmd.add_argument( "target", type=dsargparse.FileType("r"), help="a file containing target product IDs.") active_reviewer_cmd = reviewer_cmd.add_parser(active_reviewers, name="active") active_reviewer_cmd.add_argument("--threshold", type=int, default=2) size_cmd = reviewer_cmd.add_parser(reviewer_size) size_cmd.add_argument("target", type=dsargparse.FileType("r")) size_cmd.add_argument("--csv", action="store_true", dest="csv_format", help="Outputs will be formatted in CSV format.") filter_reviewer_cmd = reviewer_cmd.add_parser(filter_reviewers, name="filter") filter_reviewer_cmd.add_argument( "target", type=dsargparse.FileType("r"), help="a file containing target reviewer IDs.") filter_reviewer_cmd.add_argument( "--csv", action="store_true", dest="csv_format", help="Outputs will be formatted in CSV format.") # Product product_cmd = subparsers.add_parser( name="product", help="analyze product information").add_subparsers() rating_average_cmd = product_cmd.add_parser(rating_average, name="average") rating_average_cmd.add_argument( "--csv", action="store_true", dest="csv_format", help="Outputs will be formatted in CSV format.") product_cmd.add_parser(distinct_product, name="distinct") popular_products_cmd = product_cmd.add_parser(popular_products, name="popular") popular_products_cmd.add_argument("--threshold", type=int, default=2) filter_product_cmd = product_cmd.add_parser(filter_product, name="filter") filter_product_cmd.add_argument( "target", type=dsargparse.FileType("r"), help="a file containing target product IDs.") filter_product_cmd.add_argument( "--csv", action="store_true", dest="csv_format", help="Outputs will be formatted in CSV format.") review_variance_cmd = product_cmd.add_parser(review_variance, name="variance") review_variance_cmd.add_argument( "--target", type=dsargparse.FileType("r"), help="a file consisting of a list of product ids.") review_variance_cmd.add_argument( "--csv", action="store_true", dest="csv_format", help="Outputs will be formatted in CSV format.") try: _dispatch(**vars(parser.parse_args())) except KeyboardInterrupt: return "Canceled" except Exception as e: # pylint: disable=broad-except logging.exception("Untracked exception occurred.") return e.message finally: logging.shutdown()