mirror of
https://github.com/arcan1s/ahriman.git
synced 2026-07-19 09:01:08 +00:00
fix: disable colors for importing parser calls
In case if parser is used to generate docs, it remains w\o colors, but help messages are still formatted with it
This commit is contained in:
+1
-1
@@ -3,7 +3,7 @@ version: 2
|
|||||||
build:
|
build:
|
||||||
os: ubuntu-lts-latest
|
os: ubuntu-lts-latest
|
||||||
tools:
|
tools:
|
||||||
python: "3.13"
|
python: "3.14"
|
||||||
apt_packages:
|
apt_packages:
|
||||||
- graphviz
|
- graphviz
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ description = "ArcH linux ReposItory MANager, core package"
|
|||||||
dynamic = [
|
dynamic = [
|
||||||
"version",
|
"version",
|
||||||
]
|
]
|
||||||
requires-python = ">=3.13"
|
requires-python = ">=3.14"
|
||||||
|
|
||||||
[project.optional-dependencies]
|
[project.optional-dependencies]
|
||||||
journald = [
|
journald = [
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
#
|
#
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
|
from functools import partial
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import ahriman.application.handlers
|
import ahriman.application.handlers
|
||||||
@@ -34,10 +35,13 @@ from ahriman.models.log_handler import LogHandler
|
|||||||
__all__: list[str] = []
|
__all__: list[str] = []
|
||||||
|
|
||||||
|
|
||||||
def _parser() -> argparse.ArgumentParser:
|
def _parser(*, color: bool = False) -> argparse.ArgumentParser:
|
||||||
"""
|
"""
|
||||||
command line parser generator
|
command line parser generator
|
||||||
|
|
||||||
|
Args:
|
||||||
|
color(bool, optional): enable colors in help messages (Default value = False)
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
argparse.ArgumentParser: command line parser for the application
|
argparse.ArgumentParser: command line parser for the application
|
||||||
"""
|
"""
|
||||||
@@ -63,7 +67,7 @@ Start web service (requires additional configuration):
|
|||||||
|
|
||||||
>>> ahriman web
|
>>> ahriman web
|
||||||
""",
|
""",
|
||||||
fromfile_prefix_chars="@", formatter_class=_HelpFormatter)
|
fromfile_prefix_chars="@", formatter_class=_HelpFormatter, color=color)
|
||||||
parser.add_argument("-a", "--architecture", help="filter by target architecture")
|
parser.add_argument("-a", "--architecture", help="filter by target architecture")
|
||||||
parser.add_argument("-c", "--configuration", help="configuration path", type=Path,
|
parser.add_argument("-c", "--configuration", help="configuration path", type=Path,
|
||||||
default=Path("/") / "etc" / "ahriman.ini")
|
default=Path("/") / "etc" / "ahriman.ini")
|
||||||
@@ -92,8 +96,9 @@ Start web service (requires additional configuration):
|
|||||||
for handler in implementations(ahriman.application.handlers, Handler):
|
for handler in implementations(ahriman.application.handlers, Handler):
|
||||||
for subparser_parser in handler.arguments:
|
for subparser_parser in handler.arguments:
|
||||||
subparser = subparser_parser(subparsers)
|
subparser = subparser_parser(subparsers)
|
||||||
|
subparser.color = color
|
||||||
subparser.formatter_class = _HelpFormatter
|
subparser.formatter_class = _HelpFormatter
|
||||||
subparser.set_defaults(handler=handler, parser=_parser)
|
subparser.set_defaults(handler=handler, parser=partial(_parser, color=color))
|
||||||
|
|
||||||
# sort actions alphabetically in both choices and help message
|
# sort actions alphabetically in both choices and help message
|
||||||
# pylint: disable=protected-access
|
# pylint: disable=protected-access
|
||||||
@@ -110,7 +115,7 @@ def run() -> int:
|
|||||||
Returns:
|
Returns:
|
||||||
int: application status code
|
int: application status code
|
||||||
"""
|
"""
|
||||||
parser = _parser()
|
parser = _parser(color=True)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
if args.command is None: # in case of empty command we would like to print help message
|
if args.command is None: # in case of empty command we would like to print help message
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ description = "ArcH linux ReposItory MANager, additional extensions"
|
|||||||
dynamic = [
|
dynamic = [
|
||||||
"version",
|
"version",
|
||||||
]
|
]
|
||||||
requires-python = ">=3.13"
|
requires-python = ">=3.14"
|
||||||
|
|
||||||
[tool.hatch.build.targets.wheel]
|
[tool.hatch.build.targets.wheel]
|
||||||
packages = [
|
packages = [
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ description = "ArcH linux ReposItory MANager, web server"
|
|||||||
dynamic = [
|
dynamic = [
|
||||||
"version",
|
"version",
|
||||||
]
|
]
|
||||||
requires-python = ">=3.13"
|
requires-python = ">=3.14"
|
||||||
|
|
||||||
[project.optional-dependencies]
|
[project.optional-dependencies]
|
||||||
auth = [
|
auth = [
|
||||||
|
|||||||
+1
-1
@@ -20,7 +20,7 @@ dynamic = [
|
|||||||
]
|
]
|
||||||
license = { file = "COPYING" }
|
license = { file = "COPYING" }
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
requires-python = ">=3.13"
|
requires-python = ">=3.14"
|
||||||
|
|
||||||
[project.urls]
|
[project.urls]
|
||||||
Changelog = "https://github.com/arcan1s/ahriman/releases"
|
Changelog = "https://github.com/arcan1s/ahriman/releases"
|
||||||
|
|||||||
Reference in New Issue
Block a user