예제 #1
0
 def run(self, key=None, outfile=None, **options):
     if outfile is None:
         outfile = sys.stdout
     writer = self._writer(outfile)
     name = from_cli(key)
     if key is None:
         self.api.parser.print_help(outfile)
         return
     if name == "topics":
         self.print_topics(outfile)
         return
     if name in self._topics:
         self.print_commands(name, outfile)
     elif name in self.Command:
         cmd = self.Command[name]
         if cmd.NO_CLI:
             raise HelpError(topic=name)
         self.Backend.cli.build_parser(cmd).print_help(outfile)
     elif any(name in t[2] for t in self._topics.values()
              if type(t[2]) is dict):
         self.print_commands(name, outfile)
     elif name == "commands":
         mcl = 0
         for cmd_plugin in self.Command:
             if cmd_plugin is not self.Command.get_plugin(cmd_plugin.name):
                 continue
             if cmd_plugin.NO_CLI:
                 continue
             mcl = max(mcl, len(cmd_plugin.name))
             writer(
                 '%s  %s' %
                 (to_cli(cmd_plugin.name).ljust(mcl), cmd_plugin.summary))
     else:
         raise HelpError(topic=name)
예제 #2
0
 def run(self, key, outfile=None, **options):
     if outfile is None:
         outfile = sys.stdout
     writer = self._writer(outfile)
     name = from_cli(key)
     mod_name = '%s.%s' % (self._PLUGIN_BASE_MODULE, name)
     if key is None:
         self.api.parser.print_help(outfile)
         return
     if name == "topics":
         self.print_topics(outfile)
         return
     if name in self._topics:
         self.print_commands(name, outfile)
     elif name in self.Command:
         cmd = self.Command[name]
         if cmd.NO_CLI:
             raise HelpError(topic=name)
         self.Backend.cli.build_parser(cmd).print_help(outfile)
     elif mod_name in sys.modules:
         self.print_commands(name, outfile)
     elif name == "commands":
         mcl = max(len(s) for s in (self.Command))
         for cname in self.Command:
             cmd = self.Command[cname]
             if cmd.NO_CLI:
                 continue
             writer('%s  %s' % (to_cli(cmd.name).ljust(mcl), cmd.summary))
     else:
         raise HelpError(topic=name)
예제 #3
0
파일: cli.py 프로젝트: vikas-lamba/freeipa
    def print_commands(self, topic, outfile):
        writer = self.Writer(outfile)

        if topic in self._topics and type(self._topics[topic][2]) is dict:
            # we want to display topic which has subtopics
            for subtopic in self._topics[topic][2]:
                doc = self._topics[topic][2][subtopic][0]
                mcl = self._topics[topic][1]
                writer.append('  {0}  {1}'.format(
                    to_cli(subtopic).ljust(mcl), doc))
        else:
            # we want to display subtopic or a topic which has no subtopics
            if topic in self._topics:
                mcl = self._topics[topic][1]
                commands = self._topics[topic][2]
            else:
                commands = []
                for t in self._topics:
                    if type(self._topics[t][2]) is not dict:
                        continue
                    if topic not in self._topics[t][2]:
                        continue
                    mcl = self._topics[t][2][topic][1]
                    commands = self._topics[t][2][topic][2]
                    break

            doc, _topic = self._get_topic(topic)

            if topic not in self.Command and len(commands) == 0:
                raise HelpError(topic=topic)

            writer.append(doc)
            if commands:
                writer.append()
                writer.append(_('Topic commands:'))
                for c in commands:
                    writer.append(
                        '  {0}  {1}'.format(
                            to_cli(c.name).ljust(mcl), c.summary))
                writer.append()
                writer.append(_('To get command help, use:'))
                writer.append(_('  ipa <command> --help'))
            writer.append()
        writer.write()
예제 #4
0
    def print_commands(self, topic, outfile):
        writer = self._writer(outfile)
        if topic in self._topics and type(self._topics[topic][2]) is dict:
            # we want to display topic which has subtopics
            for subtopic in self._topics[topic][2]:
                doc = self._topics[topic][2][subtopic][0]
                mcl = self._topics[topic][1]
                writer('  %s  %s' % (to_cli(subtopic).ljust(mcl), doc))
        else:
            # we want to display subtopic or a topic which has no subtopics
            if topic in self._topics:
                mcl = self._topics[topic][1]
                commands = self._topics[topic][2]
            else:
                commands = []
                for t in self._topics:
                    if type(self._topics[t][2]) is not dict:
                        continue
                    if topic not in self._topics[t][2]:
                        continue
                    mcl = self._topics[t][2][topic][1]
                    commands = self._topics[t][2][topic][2]
                    break

            m = '%s.%s' % (self._PLUGIN_BASE_MODULE, topic)
            doc = (unicode(_(sys.modules[m].__doc__)) or '').strip()

            if topic not in self.Command and len(commands) == 0:
                raise HelpError(topic=topic)

            writer(doc)
            if commands:
                writer()
                writer(_('Topic commands:'))
                for c in commands:
                    writer('  %s  %s' % (to_cli(c.name).ljust(mcl), c.summary))
                writer()
                writer(_('To get command help, use:'))
                writer(_('  ipa <command> --help'))
            writer()