def print_usage(self, cmd_name=None):
        '''Print the usage(s) of all commands or a command.'''

        def append_usage(cmd_name, without_name=False):
            # nonlocal usages
            cmd_func = self.command_funcs[cmd_name]
            usages.append(Command(cmd_func, cmd_name).build_usage(without_name))

        usages = []

        if cmd_name is None:
            # prepare all usages
            if self.default is not None:
                append_usage(self.default, True)
            for name in sorted(self.command_funcs.keys()):
                append_usage(name)
        else:
            # prepare the usage of a command
            if self.default == cmd_name:
                append_usage(cmd_name, without_name=True)
            append_usage(cmd_name)

        # print the usages
        iusages = iter(usages)
        try:
            print('usage:', next(iusages))
        except __HOLE__:   # Empty usages; print nothing.
            pass
        else:
            for usage in iusages:
                print('   or:', usage)

        # find the doc

        # find the module-level doc
        if cmd_name is None:
            if self.doc:
                doc = self.doc
            elif inspect.ismodule(self.obj):
                doc = inspect.getdoc(self.obj)
            else:
                doc = None

            # fallback to default command if still not found
            if not doc:
                cmd_name = self.default

        if cmd_name:
            doc = inspect.getdoc(self.command_funcs[cmd_name])

        # print the doc
        if doc:
            print()
            print(doc)
            print()
dataset/ETHPy150Open moskytw/clime/clime/core.py/Program.print_usage