tldr-pages / tldr-python-client

:snake: Python command-line client for tldr pages 📚
https://pypi.org/project/tldr/
MIT License
603 stars 95 forks source link

The reason of returning `list` when `tldr -l` #221

Closed uunnxx closed 10 months ago

uunnxx commented 1 year ago

Hi there!

Thanks for this app!

Let me ask why it returns list when executing tldr -l there ? https://github.com/tldr-pages/tldr-python-client/blob/15242e81e833f89a28a605cfb04ffed6a32af20c/tldr.py#L304C1-L315C20

I want to use fzf to search through all pages, not using tldr --search term i.e. tldr $(tldr -l | fzf)

By just returning string by \n we could get this effect. return '\n'.join(commands)

def get_commands(platforms: Optional[List[str]] = None) -> str:
    if platforms is None:
        platforms = get_platform_list()

    commands = []
    if os.path.exists(get_cache_dir()):
        for platform in platforms:
            path = os.path.join(get_cache_dir(), 'pages', platform)
            if not os.path.exists(path):
                continue
            commands += [file[:-3] for file in os.listdir(path) if file.endswith(".md")]
    return '\n'.join(commands)
owenvoke commented 1 year ago

It returns a list of strings because it's used for searching. If we want to change to output the list as newline-separated values, this should be changed here (not within the actual function itself).