From 71ad6d1df4a397dcd54f4f1926496ba02c529fdf Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Fri, 6 Oct 2023 23:51:21 +0000 Subject: Deployed 4b174b5 to dev with MkDocs 1.5.3 and mike 1.1.2 --- dev/CLI/index.html | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) (limited to 'dev/CLI') diff --git a/dev/CLI/index.html b/dev/CLI/index.html index 64b287f6..616d8110 100644 --- a/dev/CLI/index.html +++ b/dev/CLI/index.html @@ -1 +1,62 @@ - CLI Reference - HydroRollCore 核心文档 (草案)
跳转至

CLI Reference⚓︎


最后更新: 2023-10-07
创建日期: 2023-10-07
\ No newline at end of file + CLI Reference - HydroRollCore 核心文档 (草案)
跳转至

CLI Reference⚓︎

```python exec="1" idprefix="" import argparse import re from HydroRollCore import Cli

parser = Cli().parser

MONOSPACED = ("pyproject.toml", "pdm.lock", ".pdm-python", ":pre", ":post", ":all")

def clean_help(help: str) -> str: # Make dunders monospaced avoiding italic markdown rendering help = re.sub(r"([\w\d_]+)", r"__\1__", help) # Make env vars monospaced help = re.sub(r"env var: ([A-Z_]+)", r"env var: \1", help) for monospaced in MONOSPACED: help = re.sub(rf"\s(['\"]?{monospaced}['\"]?)", f"{monospaced}", help) return help

def render_parser( parser: argparse.ArgumentParser, title: str, heading_level: int = 2 ) -> str: """Render the parser help documents as a string.""" result = [f"{'#' * heading_level} {title}\n"] if parser.description and title != "HydroRollCore": result.append("> " + parser.description + "\n")

 1
+ 2
+ 3
+ 4
+ 5
+ 6
+ 7
+ 8
+ 9
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+20
+21
+22
+23
+24
+25
+26
+27
+28
+29
+30
+31
for group in sorted(
+    parser._action_groups, key=lambda g: g.title.lower(), reverse=True
+):
+    if not any(
+        bool(action.option_strings or action.dest)
+        or isinstance(action, argparse._SubParsersAction)
+        for action in group._group_actions
+    ):
+        continue
+
+    result.append(f"{group.title.title()}:\n")
+    for action in group._group_actions:
+        if isinstance(action, argparse._SubParsersAction):
+            for name, subparser in action._name_parser_map.items():
+                result.append(render_parser(subparser, name, heading_level + 1))
+            continue
+
+        opts = [f"`{opt}`" for opt in action.option_strings]
+        if not opts:
+            line = f"- `{action.dest}`"
+        else:
+            line = f"- {', '.join(opts)}"
+        if action.metavar:
+            line += f" `{action.metavar}`"
+        line += f": {clean_help(action.help)}"
+        if action.default and action.default != argparse.SUPPRESS:
+            line += f" (default: `{action.default}`)"
+        result.append(line)
+    result.append("")
+
+return "\n".join(result)
+

print(render_parser(parser, "HydroRollCore")) ```


最后更新: 2023-10-07
创建日期: 2023-10-07
\ No newline at end of file -- cgit v1.2.3-70-g09d2