Exemple #1
0
 def register_command(self,
                      name,
                      func,
                      *,
                      desc='',
                      shortdesc='',
                      completion=None,
                      usage=''):
     """
     Add a command
     """
     if name in self.commands:
         return
     if not desc and shortdesc:
         desc = shortdesc
     self.commands[name] = core.Command(func, desc, completion, shortdesc,
                                        usage)
Exemple #2
0
    def add_command(self,
                    module_name,
                    name,
                    handler,
                    help,
                    completion=None,
                    short='',
                    usage=''):
        """
        Add a global command.
        """
        if name in self.core.commands:
            raise Exception(_("Command '%s' already exists") % (name, ))

        commands = self.commands[module_name]
        commands[name] = core.Command(handler, help, completion, short, usage)
        self.core.commands[name] = commands[name]
Exemple #3
0
 def add_tab_command(self,
                     module_name,
                     tab_type,
                     name,
                     handler,
                     help,
                     completion=None,
                     short='',
                     usage=''):
     """
     Add a command only for a type of Tab.
     """
     commands = self.tab_commands[module_name]
     t = tab_type.__name__
     if name in tab_type.plugin_commands:
         return
     if not t in commands:
         commands[t] = []
     commands[t].append((name, handler, help, completion))
     tab_type.plugin_commands[name] = core.Command(handler, help,
                                                   completion, short, usage)
     for tab in self.core.tabs:
         if isinstance(tab, tab_type):
             tab.update_commands()
Exemple #4
0
# Top-level api invocation

def osh(*ops):
    """Invoke osh interpreter. Each argument is a function invocation identifying a command.
    The command sequence corresponds to the sequence of arguments.
    """
    # Construct the pipeline
    pipeline = None
    try:
        pipeline = apiparser._sequence_op(ops)
    except Exception, e:
        print >>sys.stderr, e
        sys.exit(1)
    # Run
    command = core.Command(pipeline)
    command.execute()
    last_op = ops[-1]
    if type(last_op) is _ReturnList:
        return last_op.list
    else:
        return None

class _ReturnList(core.Op):

    _unwrap_singleton = None
    _list = None

    def __init__(self, unwrap_singleton):
        core.Op.__init__(self, '', (0, 0))
        self._unwrap_singleton = unwrap_singleton