loam/cli.py
def _zsh_comp_command(self, zcf, cmd, grouping, add_help=True):
        """Write zsh _arguments compdef for a given command.

        Args:
            zcf (file): zsh compdef file.
            cmd (str): command name, set to None or '' for bare command.
            grouping (bool): group options (zsh>=5.4).
            add_help (bool): add an help option.
        """
        if add_help:
            if grouping:
                print("+ '(help)'", end=BLK, file=zcf)
            print("'--help[show help message]'", end=BLK, file=zcf)
            print("'-h[show help message]'", end=BLK, file=zcf)
        # could deal with duplicate by iterating in reverse and keep set of
        # already defined opts.
        no_comp = ('store_true', 'store_false')
        cmd_dict = self._opt_cmds[cmd] if cmd else self._opt_bare
        for opt, sct in cmd_dict.items():
            meta = self._conf[sct].def_[opt]
            if meta.cmd_kwargs.get('action') == 'append':
                grpfmt, optfmt = "+ '{}'", "'*{}[{}]{}'"
                if meta.comprule is None:
                    meta.comprule = ''
            else:
                grpfmt, optfmt = "+ '({})'", "'{}[{}]{}'"
            if meta.cmd_kwargs.get('action') in no_comp \
               or meta.cmd_kwargs.get('nargs') == 0:
                meta.comprule = None
            if meta.comprule is None:
                compstr = ''
            elif meta.comprule == '':
                optfmt = optfmt.split('[')
                optfmt = optfmt[0] + '=[' + optfmt[1]
                compstr = ': :( )'
            else:
                optfmt = optfmt.split('[')
                optfmt = optfmt[0] + '=[' + optfmt[1]
                compstr = ': :{}'.format(meta.comprule)
            if grouping:
                print(grpfmt.format(opt), end=BLK, file=zcf)
            for name in _names(self._conf[sct], opt):
                print(optfmt.format(name, meta.help.replace("'", "'\"'\"'"),
                                    compstr), end=BLK, file=zcf)
def _zsh_comp_command(self, zcf, cmd, grouping, add_help=True):
        if add_help:
            if grouping:
                print("+ '(help)'", end=BLK, file=zcf)
            print("'--help[show help message]'", end=BLK, file=zcf)
            print("'-h[show help message]'", end=BLK, file=zcf)
        # could deal with duplicate by iterating in reverse and keep set of
        # already defined opts.
        no_comp = ('store_true', 'store_false')
        cmd_dict = self._opt_cmds[cmd] if cmd else self._opt_bare
        for opt, sct in cmd_dict.items():
            meta = self._conf[sct].def_[opt]
            if meta.cmd_kwargs.get('action') == 'append':
                grpfmt, optfmt = "+ '{}'", "'*{}[{}]{}'"
                if meta.comprule is None:
                    meta.comprule = ''
            else:
                grpfmt, optfmt = "+ '({})'", "'{}[{}]{}'"
            if meta.cmd_kwargs.get('action') in no_comp \
               or meta.cmd_kwargs.get('nargs') == 0:
                meta.comprule = None
            if meta.comprule is None:
                compstr = ''
            elif meta.comprule == '':
                optfmt = optfmt.split('[')
                optfmt = optfmt[0] + '=[' + optfmt[1]
                compstr = ': :( )'
            else:
                optfmt = optfmt.split('[')
                optfmt = optfmt[0] + '=[' + optfmt[1]
                compstr = ': :{}'.format(meta.comprule)
            if grouping:
                print(grpfmt.format(opt), end=BLK, file=zcf)
            for name in _names(self._conf[sct], opt):
                print(optfmt.format(name, meta.help.replace("'", "'\"'\"'"),
                                    compstr), end=BLK, file=zcf)
def _zsh_comp_command ( self , zcf , cmd , grouping , add_help = True ) : if add_help : if grouping : print ( "+ '(help)'" , end = BLK , file = zcf ) print ( "'--help[show help message]'" , end = BLK , file = zcf ) print ( "'-h[show help message]'" , end = BLK , file = zcf ) # could deal with duplicate by iterating in reverse and keep set of # already defined opts. no_comp = ( 'store_true' , 'store_false' ) cmd_dict = self . _opt_cmds [ cmd ] if cmd else self . _opt_bare for opt , sct in cmd_dict . items ( ) : meta = self . _conf [ sct ] . def_ [ opt ] if meta . cmd_kwargs . get ( 'action' ) == 'append' : grpfmt , optfmt = "+ '{}'" , "'*{}[{}]{}'" if meta . comprule is None : meta . comprule = '' else : grpfmt , optfmt = "+ '({})'" , "'{}[{}]{}'" if meta . cmd_kwargs . get ( 'action' ) in no_comp or meta . cmd_kwargs . get ( 'nargs' ) == 0 : meta . comprule = None if meta . comprule is None : compstr = '' elif meta . comprule == '' : optfmt = optfmt . split ( '[' ) optfmt = optfmt [ 0 ] + '=[' + optfmt [ 1 ] compstr = ': :( )' else : optfmt = optfmt . split ( '[' ) optfmt = optfmt [ 0 ] + '=[' + optfmt [ 1 ] compstr = ': :{}' . format ( meta . comprule ) if grouping : print ( grpfmt . format ( opt ) , end = BLK , file = zcf ) for name in _names ( self . _conf [ sct ] , opt ) : print ( optfmt . format ( name , meta . help . replace ( "'" , "'\"'\"'" ) , compstr ) , end = BLK , file = zcf )
Write zsh _arguments compdef for a given command.

        Args:
            zcf (file): zsh compdef file.
            cmd (str): command name, set to None or '' for bare command.
            grouping (bool): group options (zsh>=5.4).
            add_help (bool): add an help option.
Write zsh _arguments compdef for a given command .