Exemplo n.º 1
0
    def usage(self):

        nmtalk.message("")
        nmtalk.message("Usage: nm " + self.name() + " <options> " + \
                       self.arguments())
        nmtalk.message("")

        description = self.description_long() or self.description_short()
        if description:
            description = "'" + self.name() + "': " + description
            for l in nmformat.linebreak(description, 72):
                nmtalk.message(l)
            nmtalk.message("")

        opts = self.local_opt_table()
        if opts:
            nmtalk.message("'" + self.name() + "' Options:")
            nmformat.opt_table(opts)
            nmtalk.message("")
        
        opts = self.default_opt_table()
        if opts:
            nmtalk.message("General Options:")
            nmformat.opt_table(opts)
            nmtalk.message("")

        exit(1)
Exemplo n.º 2
0
def print_command_list(commands, with_categories=0):

    max_len = 0
    cmd_list = []
    
    for c in commands:
        name, aliases, description, category = c

        if aliases:
            name = name + " (" + string.join(aliases, ", ") + ")"

        cmd_list.append([name, description, category])
        max_len = max(max_len, len(name))

    desc_len = max_len + 4

    cmd_list.sort(command_sort)

    previous_category = "we will banish all dwarves from the love kingdom"

    for c in cmd_list:

        name, description, category = c

        if with_categories and category != previous_category:
            if category_data.has_key(category):
                category_name = category_data[category][0]
            else:
                category_name = string.upper(category[0]) + category[1:]
                
            nmtalk.message("\n" + category_name + " commands:")
            previous_category = category

        # If, for some reason, the command list is *really* wide (which it never should
        # be), don't do something stupid.
        if 79 - desc_len > 10:
            desc = nmformat.linebreak(description, 79-desc_len)
        else:
            desc = [description]
                
        desc_first = desc.pop(0)
        nmtalk.message("  " + string.ljust(name, max_len) + "  " + desc_first)
        for d in desc:
            nmtalk.message(" " * desc_len + d)