Skip to content

Commit 178459f

Browse files
committed
argpase: colorize the --help output with rich-argparse
1 parent 6c86caa commit 178459f

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

cwltool/argparser.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
from collections.abc import MutableMapping, MutableSequence, Sequence
77
from typing import Any, Callable, Optional, Union, cast
88

9+
import rich.markup
10+
from rich_argparse import RichHelpFormatter
11+
912
from .loghandler import _logger
1013
from .process import Process, shortname
1114
from .resolver import ga4gh_tool_registries
@@ -15,8 +18,9 @@
1518

1619
def arg_parser() -> argparse.ArgumentParser:
1720
parser = argparse.ArgumentParser(
21+
formatter_class=RichHelpFormatter,
1822
description="Reference executor for Common Workflow Language standards. "
19-
"Not for production use."
23+
"Not for production use.",
2024
)
2125
parser.add_argument("--basedir", type=str)
2226
parser.add_argument(
@@ -855,6 +859,7 @@ def add_argument(
855859
urljoin: Callable[[str, str], str] = urllib.parse.urljoin,
856860
base_uri: str = "",
857861
) -> None:
862+
description = rich.markup.escape(description)
858863
if len(name) == 1:
859864
flag = "-"
860865
else:

cwltool/main.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import coloredlogs
2323
import requests
2424
import ruamel.yaml
25+
from rich_argparse import RichHelpFormatter
2526
from ruamel.yaml.comments import CommentedMap, CommentedSeq
2627
from ruamel.yaml.main import YAML
2728
from schema_salad.exceptions import ValidationException
@@ -413,7 +414,10 @@ def init_job_order(
413414
namemap: dict[str, str] = {}
414415
records: list[str] = []
415416
toolparser = generate_parser(
416-
argparse.ArgumentParser(prog=args.workflow),
417+
argparse.ArgumentParser(
418+
prog=args.workflow,
419+
formatter_class=RichHelpFormatter,
420+
),
417421
process,
418422
namemap,
419423
records,

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@
135135
"pyparsing != 3.0.2", # breaks --print-dot (pydot) https://github.com/pyparsing/pyparsing/issues/319
136136
"cwl-utils >= 0.32",
137137
"spython >= 0.3.0",
138+
"rich-argparse",
138139
],
139140
extras_require={
140141
"deps": [

0 commit comments

Comments
 (0)