from nilmdb.utils.printf import *

import argparse
import sys

def setup(self, sub):
    cmd = sub.add_parser("help", help="Show detailed help for a command",
                         description="""
                         Show help for a command. 'help command' is
                         the same as 'command --help'.
                         """)
    cmd.set_defaults(handler = cmd_help)
    cmd.set_defaults(no_test_connect = True)
    cmd.add_argument("command", nargs="?",
                     help="Command to get help about")
    cmd.add_argument("rest", nargs=argparse.REMAINDER,
                     help=argparse.SUPPRESS)
    return cmd

def cmd_help(self):
    if self.args.command in self.subcmd:
        self.subcmd[self.args.command].print_help()
    else:
        self.parser.print_help()

    return
