How to use the stig.completion.candidates function in stig

To help you get started, we’ve selected a few stig 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 rndusr / stig / stig / commands / tui / torrent.py View on Github external
def completion_candidates_posargs(cls, args):
        """Complete positional arguments"""
        return candidates.fs_path(args.curarg.before_cursor,
                                  base=os.environ.get('HOME', '.'),
                                  glob=r'*.torrent')
github rndusr / stig / stig / commands / base / torrent.py View on Github external
def completion_candidates_params(cls, option, args):
        """Complete parameters (e.g. --option parameter1,parameter2)"""
        if option == '--path':
            return candidates.fs_path(args.curarg.before_cursor,
                                      base=objects.remotecfg['path.complete'],
                                      directories_only=True)
github rndusr / stig / stig / commands / base / config.py View on Github external
def completion_candidates_posargs(cls, args):
        """Complete positional arguments"""
        # If --columns or --sort is anywhere, we only display options
        for arg in args:
            if cls.short_options.get(arg, arg) in ('--columns', '--sort'):
                return

        settings = candidates.setting_names()
        if args.curarg_index == 1:
            log.debug('Returning setting names: %r', settings)
            return settings
        elif args.curarg_index >= 2:
            log.debug('Completing values for %r', args[1])
            # Remove command name from command line
            return candidates.setting_values(args[1:])
github rndusr / stig / stig / commands / cli / torrent.py View on Github external
async def completion_candidates_posargs(cls, args):
        """Complete positional arguments"""
        if args.curarg_index == 1:
            log.debug('Getting torrent filter candidates from %r', candidates.torrent_filter)
            return await candidates.torrent_filter(args.curarg)
        elif args.curarg_index == 2:
            return candidates.fs_path(args.curarg.before_cursor,
                                      base=objects.remotecfg['path.complete'],
                                      directories_only=True)
github rndusr / stig / stig / commands / tui / torrent.py View on Github external
async def completion_candidates_posargs(cls, args):
        """Complete positional arguments"""
        def dest_path_candidates(curarg):
            return candidates.fs_path(curarg.before_cursor,
                                      base=objects.remotecfg['path.complete'],
                                      directories_only=True)

        curarg = args.curarg
        if len(args) >= 3:
            if args.curarg_index == 1:
                return await candidates.torrent_filter(curarg)
            elif args.curarg_index == 2:
                return dest_path_candidates(curarg)
        elif len(args) == 2:
            # Single argument may be a path or a filter
            filter_cands = await candidates.torrent_filter(curarg)
            path_cands = dest_path_candidates(curarg)
            return (path_cands,) + filter_cands
github rndusr / stig / stig / commands / base / config.py View on Github external
def completion_candidates_posargs(cls, args):
        """Complete positional arguments"""
        # Command only takes one argument
        if args.curarg_index == 1:
            return candidates.fs_path(args.curarg,
                                      base=os.path.dirname(defaults.DEFAULT_RCFILE))
github rndusr / stig / stig / commands / base / torrent.py View on Github external
async def completion_candidates_posargs(cls, args):
        """Complete positional arguments"""
        # We don't care about options
        args = args.without_options()
        log.debug(args)
        if args.curarg_index == 1:
            # Complete file and directory names from torrent(s)
            log.debug('torrent_path(%r)', args.curarg)
            return await candidates.torrent_path(args.curarg, only='any')
        elif args.curarg_index == 2:
            first_arg_stripped = args[1].strip('/')
            if '/' in first_arg_stripped:
                # First argument contains a path separator, so destination is
                # the new file name.  The second argument can't contain a path
                # separator if it's a file or directory.
                if '/' not in args.curarg:
                    # To make it more convenient to adjust file/directory names,
                    # destination candidates are existing files or directories
                    # from the path specified in the first argument.  Files if
                    # the first argument points to a file, directories if the
                    # first argument points to a directory.
                    source = Arg(first_arg_stripped, curpos=len(first_arg_stripped))
                    log.debug('Using destination candidates from: %r', source)
                    return await candidates.torrent_path(source, only='auto')
            else:
github rndusr / stig / stig / commands / base / torrent.py View on Github external
def completion_candidates_posargs(cls, args):
        """Complete positional arguments"""
        if args.curarg_index == 1:
            return candidates.torrent_filter(args.curarg)
github rndusr / stig / stig / commands / base / config.py View on Github external
def completion_candidates_posargs(cls, args):
        """Complete positional arguments"""
        return candidates.setting_names()
github rndusr / stig / stig / commands / cli / torrent.py View on Github external
async def completion_candidates_posargs(cls, args):
        """Complete positional arguments"""
        if args.curarg_index == 1:
            log.debug('Getting torrent filter candidates from %r', candidates.torrent_filter)
            return await candidates.torrent_filter(args.curarg)
        elif args.curarg_index == 2:
            return candidates.fs_path(args.curarg.before_cursor,
                                      base=objects.remotecfg['path.complete'],
                                      directories_only=True)