#!/usr/bin/env python
# coding: utf-8

"""
The main command line program to interact with the tasks.
"""

from siskin.utils import get_task_import_cache
import importlib
import luigi
import os
import sys

if __name__ == '__main__':
    if len(sys.argv) < 2:
        raise RuntimeError('specify a task to run')
    taskname = sys.argv[1]

    task_import_cache, path = get_task_import_cache()
    if taskname in task_import_cache:
        importlib.import_module(task_import_cache[taskname])
    else:
        try:
            os.remove(path)
        except OSError:
            pass

        from siskin.sources import *
        from siskin.workflows import *

    luigi.run()
