How to use the pin.command.get function in pin

To help you get started, we’ve selected a few pin examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dustinlacewell / pin / pin / delegate.py View on Github external
proj_path = registry.pathfor(cmd)
        if proj_path is not None:
            os.chdir(proj_path)
            cmd = args[0]
            args = args[1:]
        if '-' in cmd:
            cmd, newargs = cmd.split('-', 1)
            args = [newargs, ] + args
        comcls = command.get(cmd) or command.get('help')
        try:
            if comcls:
                comobj = comcls(args)
                if comobj.is_relevant():
                    comobj._execute()
                else:
                    helpcls = command.get('help')
                    helpobj = helpcls((cmd,))
                    helpobj._execute()
                    print "\n'%s %s' command not relevant here." % (cmd, ' '.join(args).strip())
            else:
                self.do_default()
        except KeyboardInterrupt:
            print "\n"
            pass
github dustinlacewell / pin / pin / util.py View on Github external
# complete help command
        if nargs == off and "help".startswith(args[-1]):
            return 'help'
        # or increase offset by 1
        elif "help" in args:
            off += 1
    # # # # # # # #
    # base-command
    if nargs == off:
        arg = '' # default to empty arg
        if len(args) == off:
            # set working arg to item at offset
            arg = args[off-1]
        choices = " ".join([c for c in command._commands 
                            if c.startswith(arg)
                            and command.get(c)([]).is_relevant()])
        # return the choices if there are any
        if choices:
            return choices
        # we want commands to complete before
        # project names, so if we don't return any
        # choices above, complete a project name now
        # if we're completing the first argument
        if nargs == 1:
            if proj_path is not None:
                return os.path.basename(proj_path)
    # # # # # # # #
    # sub-commands
    elif nargs == off + 1:
        # get our parent command
        com = args[off-1]
        # get its class
github dustinlacewell / pin / pin / plugins / core.py View on Github external
def execute(self):
        if self.options.command:
            clskey = '-'.join(self.options.command)
            comcls = command.get(clskey)
            if comcls: # if args point to pin command
                comobj = comcls([])
                parser = comobj.parser
                parser.print_help()
                if hasattr(comcls, 'get_subcommands'):
                    subcoms = comcls.get_subcommands() 
                    if subcoms:
                        submaxlength = len(max(subcoms.keys(), key=len))
                        for name, subcom in subcoms.items():
                            self.process_subcom(name, subcom, submaxlength)
            else: # ask parent command
                pcomcls = command.get(self.options.command[0])
                if pcomcls and hasattr(pcomcls, 'get_subcommands'):
                    subcommands = pcomcls.get_subcommands()
                    if subcommands:
                        for name, com in subcommands.items():
                            if name == self.options.command[1]:
                                print com.__doc__ or 'Command has no docstring.'
                else:
                    self.do_default_help()

                    
            
        else:
            self.do_default_help()
github dustinlacewell / pin / pin / plugins / core.py View on Github external
def execute(self):
        if self.options.command:
            clskey = '-'.join(self.options.command)
            comcls = command.get(clskey)
            if comcls: # if args point to pin command
                comobj = comcls([])
                parser = comobj.parser
                parser.print_help()
                if hasattr(comcls, 'get_subcommands'):
                    subcoms = comcls.get_subcommands() 
                    if subcoms:
                        submaxlength = len(max(subcoms.keys(), key=len))
                        for name, subcom in subcoms.items():
                            self.process_subcom(name, subcom, submaxlength)
            else: # ask parent command
                pcomcls = command.get(self.options.command[0])
                if pcomcls and hasattr(pcomcls, 'get_subcommands'):
                    subcommands = pcomcls.get_subcommands()
                    if subcommands:
                        for name, com in subcommands.items():
github dustinlacewell / pin / pin / plugins / core.py View on Github external
def process_containercom(self, name, collen, subcollen):
        comcls = command.get(name)
        comobj = comcls([])
        usage = comobj.parser.format_usage().replace("usage: ", "")
        print usage.strip()
        if hasattr(comcls, 'get_subcommands'):
            if comcls.__doc__:
                print "{0} {1}".format(' - ', comcls.__doc__.strip(), cl=collen)
            subcoms = comcls.get_subcommands()
            if subcoms:
                for name, subcom in subcoms.items():
                    self.process_subcom(name, subcom, subcollen)
github dustinlacewell / pin / pin / plugins / core.py View on Github external
themselves as being 'relevant'. Some processing is done to determine
        formatting widths of the output and help for delegate-commands 
        that contain subcommands are dynamically computed.
        '''
        # print generic pin help
        CommandDelegator.parser.print_help()
        comkeys = [k for k in command.all().keys() if '-' not in k]
        maxlength = len(max(comkeys, key=len))
        simplekeys = [] # commands without subcommands
        containerkeys = [] # subcommand delgates
        subcomkeys = []
        submaxlength = maxlength
        # iterate over all commands
        for k in comkeys:
            # get command class
            comcls = command.get(k)
            # get dummy instance
            comobj = comcls([])
            # check if command is relevant
            if comobj.is_relevant() or self.options.all:
                # add to specific list based on `get_subcommands' attribute
                if hasattr(comcls, 'get_subcommands'):
                    containerkeys.append(k)
                    # grab all subcommand keys
                    subcoms = comcls.get_subcommands()
                    if subcoms:
                        subcomkeys += subcoms.keys()
                else:
                    simplekeys.append(k)
        # calculate global max-length of subcommand keys
        if subcomkeys:
            submaxlength = len(max(subcomkeys, key=len))