Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
man_pages.py49 linesDownload Raw Back to ui
1"""Logic for checking and displaying man pages."""2 3import subprocess4import os5from httpie.context import Environment6 7 8MAN_COMMAND = 'man'9NO_MAN_PAGES = os.getenv('HTTPIE_NO_MAN_PAGES', False)10 11# On some systems, HTTP(n) might exist, but we are only interested in HTTP(1).12# For more information on man page sections: <https://unix.stackexchange.com/a/138643>13MAN_PAGE_SECTION = '1'14 15 16def is_available(program: str) -> bool:17    """18    Check whether `program`'s man pages are available on this system.19 20    """21    if NO_MAN_PAGES or os.system == 'nt':22        return False23    try:24        process = subprocess.run(25            [MAN_COMMAND, MAN_PAGE_SECTION, program],26            shell=False,27            stdout=subprocess.DEVNULL,28            stderr=subprocess.DEVNULL29        )30    except Exception:31        # There might be some errors outside the process, e.g32        # a permission error to execute something that is not an33        # executable.34        return False35    else:36        return process.returncode == 037 38 39def display_for(env: Environment, program: str) -> None:40    """41    Open the system man page for the given command (http/https/httpie).42 43    """44    subprocess.run(45        [MAN_COMMAND, MAN_PAGE_SECTION, program],46        stdout=env.stdout,47        stderr=env.stderr48    )49 
codekingpro/portable-devtools · Team Ai