logic for checking and displaying man pages import subprocess import os from httpie context import environment mancommand man nomanpages os getenv httpienomanpages false on some systems httpn might exist but we are only interested in http1 for more information on man page sections https unix stackexchange coma138643 manpagesection 1 def isavailableprogram str bool if nomanpages or os system nt return false try process subprocess run mancommand manpagesection program shellfalse stdoutsubprocess devnull stderrsubprocess devnull except exception there might be some errors outside the process e g a permission error to execute something that is not an executable return false else return process returncode 0 def displayforenv environment program str none subprocess run mancommand manpagesection program stdoutenv stdout stderrenv stderr on some systems http n might exist but we are only interested in http 1 for more information on man page sections https unix stackexchange com a 138643 check whether program s man pages are available on this system there might be some errors outside the process e g a permission error to execute something that is not an executable open the system man page for the given command http https httpie
import subprocess
import os
from httpie.context import Environment


MAN_COMMAND = 'man'
NO_MAN_PAGES = os.getenv('HTTPIE_NO_MAN_PAGES', False)



MAN_PAGE_SECTION = '1'


def is_available(program: str) -> bool:
    
    if NO_MAN_PAGES or os.system == 'nt':
        return False
    try:
        process = subprocess.run(
            [MAN_COMMAND, MAN_PAGE_SECTION, program],
            shell=False,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL
        )
    except Exception:
        
        
        
        return False
    else:
        return process.returncode == 0


def display_for(env: Environment, program: str) -> None:
    
    subprocess.run(
        [MAN_COMMAND, MAN_PAGE_SECTION, program],
        stdout=env.stdout,
        stderr=env.stderr
    )