#!/usr/bin/env python3
import os
import sys
import subprocess

commands = {
    "mask"    : "Converts *.PFFTS to *.FIL, *.MASK, *.MAXMIN and *.BADCHANS",
    "masknew" : "Converts all new *.PFFTS in directory" }
"""
    Modules available to user of 'pulsar-script'. This is the dictionary where
    keys are modules names and values are modules descriptions. Names are
    relative to module :mod:`mpifr.pulsarscript`. Descriptions must be as short
    and concise as  possible, up to 60 characters long (much stricter that
    Twitter, though!). """

reldir = os.path.dirname(os.path.realpath(__file__))
sys.path.append(reldir)
sys.path.append(os.path.join(reldir, "submodules/rvlm-entrypoint"))
import mpifr.pulsarscript

out = lambda s="": print(s, file=sys.stderr)

# When no parameter given, of only '--help' is provided, output short
# help and usage clauses, with list of available commands.
if len(sys.argv) == 1  or (len(sys.argv) >= 2 and sys.argv[1] == "--help"):
    out("Dispatcher script for pulsar research at Max Planck")
    out("institute for radioastronomy (MPIFR), Bonn, Germany.")
    out("Usage: $ pulsar-script --help")
    out("       $ pulsar-script COMMAND ... ")
    out()
    out("Available commands:")
    for (cmd, doc) in commands.items():
        out("  %-10s %s" % (cmd, doc))
    out()
    sys.exit(1)

cmd  = sys.argv[1]
args = sys.argv[2:]
process = mpifr.pulsarscript.runmodule("mpifr.pulsarscript.%s" % cmd, *args)
process.wait()
