jflow_cli.py 1.91 KB
Newer Older
Jerome Mariette's avatar
Jerome Mariette committed
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
52
53
54
#
# Copyright (C) 2012 INRA
# 
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

import sys
import argparse

try:
    import _preamble
except ImportError:
    sys.exc_clear()

from jflow.workflows_manager import WorkflowsManager
from jflow.workflow import Workflow


if __name__ == '__main__':

    # Create the top-level parser
    parser = argparse.ArgumentParser(prog='jflow')
    subparsers = parser.add_subparsers(title='Available sub commands')
    
    # Add available pipelines
    wf_instances = WorkflowsManager.get_workflows()
    for instance in wf_instances:
        # create the subparser for each applications
        sub_parser = subparsers.add_parser(instance.name, help=instance.description)
        for param in instance.parameters:
            sub_parser.add_argument(param.flag, type=param.type, help=param.help,
                                    required=param.required, dest=param.name,
                                    metavar=param.metavar, default=param.default,
                                    action=param.action, choices=param.choices)
        sub_parser.set_defaults(cmd_object=instance)
    args = vars(parser.parse_args())
    
    if isinstance(args["cmd_object"], Workflow):
        try:
            args["cmd_object"].execute(args)
        except (IOError, NameError), e: 
            sys.exit("Error: " + str(e))