tool.py 2.21 KB
Newer Older
1
import argparse
Leo Pound Singer's avatar
Leo Pound Singer committed
2

3 4
from ligo.gracedb import rest

5 6 7 8 9 10 11
from .. import followup_advocate


def main(args=None):
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '--version', action='version', version=followup_advocate.__version__)
12 13
    parser.add_argument(
        '--service', default=rest.DEFAULT_SERVICE_URL, help='GraceDb API URL')
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
    subparsers = parser.add_subparsers(help='sub-command help')

    authors = argparse.ArgumentParser(add_help=False)
    authors.add_argument(
        'authors', metavar="'A. Einstein (IAS)'", nargs='*', help='Authors')

    def add_command(func, **kwargs):
        subparser = subparsers.add_parser(
            func.__name__, **dict(kwargs, help=func.__doc__))
        subparser.set_defaults(func=func)
        return subparser

    cmd = add_command(followup_advocate.authors, parents=[authors])

    cmd = add_command(followup_advocate.compose, parents=[authors])
    cmd.add_argument(
        '-m', '--mailto', action='store_true',
        help='Open new message in default e-mail client [default: false]')
Min-A Cho's avatar
Min-A Cho committed
32 33
    cmd.add_argument('gracedb_id', metavar='S123456',
                     help='GraceDB ID of superevent')
34

35
    cmd = add_command(followup_advocate.compose_raven, parents=[authors])
Min-A Cho's avatar
Min-A Cho committed
36 37
    cmd.add_argument('gracedb_id', metavar='S123456',
                     help='GraceDB ID of superevent')
38 39 40 41

    cmd = add_command(followup_advocate.compose_grb_medium_latency,
                      parents=[authors])
    cmd.add_argument('gracedb_id', metavar='E123456', help='GraceDB ID of GRB')
42

43 44 45 46 47
    cmd = add_command(followup_advocate.compose_update, parents=[authors])
    cmd.add_argument('gracedb_id', metavar='S123456', help='GraceDB ID')
    cmd.add_argument('update_types', metavar='[sky_localization]',
                     help='List of Update types')

48
    cmd = add_command(followup_advocate.compose_retraction, parents=[authors])
49
    cmd.add_argument('gracedb_id', metavar='S123456', help='GraceDB ID')
50

51 52
    cmd = add_command(followup_advocate.compare_skymaps)
    cmd.add_argument(
53
        'paths', nargs='+', metavar='S123456/filename.fits.gz',
54 55
        help='Specify sky maps by GraceDB ID and filename')

56 57
    opts = parser.parse_args(args).__dict__
    func = opts.pop('func')
58
    print(func(**opts))