forked from extern/httpie-cli
ff6f1887b0
* Refactor tests to use a text-based standard output. (#1318) * Implement new style `--help` (#1316) * Implement man page generation (#1317) * Implement rich progress bars. (#1324) * Man page deployment & isolation. (#1325) * Remove all unsorted usages in the CLI docs * Implement isolated mode for man page generation * Add a CI job for autogenerated files * Distribute man pages through PyPI * Pin the date for man pages. (#1326) * Hide suppressed arguments from --help/man pages (#1329) * Change download spinner to line (#1328) * Regenerate autogenerated files when pushed against to master. (#1339) * Highlight options (#1340) * Additional man page enhancements (#1341) * Group options by the parent category & highlight -o/--o * Display (and underline) the METAVAR on man pages. * Make help message processing more robust (#1342) * Inherit `help` from `short_help` * Don't mirror short_help directly. * Fixup the serialization * Use `pager` and `man` on `--manual` when applicable (#1343) * Run `man $program` on --manual * Page the output of `--manual` for systems that lack man pages * Improvements over progress bars (separate bar, status line, etc.) (#1346) * Redesign the --help layout. * Make our usage of rich compatible with 9.10.0 * Add `HTTPIE_NO_MAN_PAGES` * Make tests also patch os.get_terminal_size * Generate CLI spec from HTTPie & Man Page Hook (#1354) * Generate CLI spec from HTTPie & add man page hook * Use the full command space for the option headers
34 lines
806 B
Python
34 lines
806 B
Python
"""Logic for checking and displaying man pages."""
|
|
|
|
import subprocess
|
|
import os
|
|
from httpie.context import Environment
|
|
|
|
MAN_COMMAND = 'man'
|
|
NO_MAN_PAGES = os.getenv('HTTPIE_NO_MAN_PAGES', False)
|
|
|
|
|
|
def is_available(program: str) -> bool:
|
|
"""Check whether HTTPie's man pages are available in this system."""
|
|
|
|
if NO_MAN_PAGES or os.system == 'nt':
|
|
return False
|
|
|
|
process = subprocess.run(
|
|
[MAN_COMMAND, program],
|
|
shell=False,
|
|
stdout=subprocess.DEVNULL,
|
|
stderr=subprocess.DEVNULL
|
|
)
|
|
return process.returncode == 0
|
|
|
|
|
|
def display_for(env: Environment, program: str) -> None:
|
|
"""Display the man page for the given command (http/https)."""
|
|
|
|
subprocess.run(
|
|
[MAN_COMMAND, program],
|
|
stdout=env.stdout,
|
|
stderr=env.stderr
|
|
)
|