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