#!/usr/bin/env python
#
# License: BSD
#   https://raw.githubusercontent.com/stonier/py_trees_ros/devel/LICENSE
#
##############################################################################
# Documentation
##############################################################################
"""
Generic launcher for one of the tutorial entry points. Saves us having to
write and install multiple no-brainer scripts.
"""
##############################################################################
# Imports
##############################################################################

import argparse
import importlib
import py_trees.console as console
import rospy
import sys

##############################################################################
# Main
##############################################################################

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Start one of the tutorials')
    parser.add_argument('name', action='store', nargs='?',
                        default='one',
                        choices=['one', 'two', 'five', 'six', 'seven', 'eight'],
                        help='name of the tutorial to start')
    command_line_args = rospy.myargv(argv=sys.argv)[1:]
    args = parser.parse_args(command_line_args)

    module_name = "py_trees_ros.tutorials." + args.name

    try:
        module_itself = importlib.import_module(module_name)
    except ImportError:
        console.logerror("Could not import module [{0}]".format(args.name))
        sys.exit(1)
    main_itself = getattr(module_itself, "main")
    main_itself()
