Skip to content

Commit 68d28e3

Browse files
authored
[frontend] Add --help=page option for paginated help output (#20961)
Signed-off-by: reidliu41 <reid201711@gmail.com>
1 parent 37a7d5d commit 68d28e3

File tree

2 files changed

+39
-8
lines changed

2 files changed

+39
-8
lines changed

docs/cli/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ Start the vLLM OpenAI Compatible API server.
3737

3838
# To search by keyword
3939
vllm serve --help=max
40+
41+
# To view full help with pager (less/more)
42+
vllm serve --help=page
4043
```
4144

4245
## chat

vllm/entrypoints/utils.py

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import asyncio
66
import functools
77
import os
8+
import subprocess
89
import sys
910
from typing import Any, Optional, Union
1011

@@ -25,7 +26,8 @@
2526
" - To view a argument group: --help=ModelConfig\n"
2627
" - To view a single argument: --help=max-num-seqs\n"
2728
" - To search by keyword: --help=max\n"
28-
" - To list all groups: --help=listgroup")
29+
" - To list all groups: --help=listgroup\n"
30+
" - To view help with pager: --help=page")
2931

3032

3133
async def listen_for_disconnect(request: Request) -> None:
@@ -190,6 +192,24 @@ def _validate_truncation_size(
190192
return truncate_prompt_tokens
191193

192194

195+
def _output_with_pager(text: str):
196+
"""Output text using scrolling view if available and appropriate."""
197+
198+
pagers = ['less -R', 'more']
199+
for pager_cmd in pagers:
200+
try:
201+
proc = subprocess.Popen(pager_cmd.split(),
202+
stdin=subprocess.PIPE,
203+
text=True)
204+
proc.communicate(input=text)
205+
return
206+
except (subprocess.SubprocessError, OSError, FileNotFoundError):
207+
continue
208+
209+
# No pager worked, fall back to normal print
210+
print(text)
211+
212+
193213
def show_filtered_argument_or_group_from_help(parser: argparse.ArgumentParser,
194214
subcommand_name: list[str]):
195215

@@ -208,16 +228,24 @@ def show_filtered_argument_or_group_from_help(parser: argparse.ArgumentParser,
208228
if arg.startswith('--help='):
209229
search_keyword = arg.split('=', 1)[1]
210230

231+
# Enable paged view for full help
232+
if search_keyword == 'page':
233+
help_text = parser.format_help()
234+
_output_with_pager(help_text)
235+
sys.exit(0)
236+
211237
# List available groups
212238
if search_keyword == 'listgroup':
213-
print("\nAvailable argument groups:")
239+
output_lines = ["\nAvailable argument groups:"]
214240
for group in parser._action_groups:
215241
if group.title and not group.title.startswith(
216242
"positional arguments"):
217-
print(f" - {group.title}")
243+
output_lines.append(f" - {group.title}")
218244
if group.description:
219-
print(" " + group.description.strip())
220-
print()
245+
output_lines.append(" " +
246+
group.description.strip())
247+
output_lines.append("")
248+
_output_with_pager("\n".join(output_lines))
221249
sys.exit(0)
222250

223251
# For group search
@@ -229,7 +257,7 @@ def show_filtered_argument_or_group_from_help(parser: argparse.ArgumentParser,
229257
formatter.add_text(group.description)
230258
formatter.add_arguments(group._group_actions)
231259
formatter.end_section()
232-
print(formatter.format_help())
260+
_output_with_pager(formatter.format_help())
233261
sys.exit(0)
234262

235263
# For single arg
@@ -243,10 +271,10 @@ def show_filtered_argument_or_group_from_help(parser: argparse.ArgumentParser,
243271
matched_actions.append(action)
244272

245273
if matched_actions:
246-
print(f"\nParameters matching '{search_keyword}':\n")
274+
header = f"\nParameters matching '{search_keyword}':\n"
247275
formatter = parser._get_formatter()
248276
formatter.add_arguments(matched_actions)
249-
print(formatter.format_help())
277+
_output_with_pager(header + formatter.format_help())
250278
sys.exit(0)
251279

252280
print(f"\nNo group or parameter matching '{search_keyword}'")

0 commit comments

Comments
 (0)