| 1 | """ |
| 2 | Simple Example Template for creating a CLI tool |
| 3 | """ |
| 4 | |
| 5 | import logging |
| 6 | import os |
| 7 | import sys |
| 8 | |
| 9 | from pbcommand.validators import validate_file |
| 10 | from pbcommand.utils import setup_log |
| 11 | from pbcommand.cli import get_default_argparser_with_base_opts, pacbio_args_runner |
| 12 | |
| 13 | log = logging.getLogger(__name__) |
| 14 | |
| 15 | __version__ = "0.1.0" |
| 16 | |
| 17 | |
| 18 | def get_parser(): |
| 19 | """Define Parser. Use the helper methods in validators to validate input""" |
| 20 | p = get_default_argparser_with_base_opts(__version__, __doc__) |
| 21 | p.add_argument('path_to_file', type=validate_file, help="Path to File") |
| 22 | return p |
| 23 | |
| 24 | |
| 25 | def run_main(path, value=8): |
| 26 | """ |
| 27 | Main function that should be called. Typically this is imported from your |
| 28 | library code. |
| 29 | |
| 30 | This should NOT reference args.* |
| 31 | """ |
| 32 | log.info("Running path {p} with value {v}".format(p=path, v=value)) |
| 33 | log.info("Found path? {t} {p}".format(p=path, t=os.path.exists(path))) |
| 34 | return 0 |
| 35 | |
| 36 | |
| 37 | def args_runner(args): |
| 38 | log.info("Raw args {a}".format(a=args)) |
| 39 | return run_main(args.path_to_file, value=100) |
| 40 | |
| 41 | |
| 42 | def main(argv): |
| 43 | return pacbio_args_runner(argv[1:], |
| 44 | get_parser(), |
| 45 | args_runner, |
| 46 | log, |
| 47 | setup_log_func=setup_log) |
| 48 | |
| 49 | |
| 50 | if __name__ == '__main__': |
| 51 | sys.exit(main(sys.argv)) |