add cli docs generator
This commit is contained in:
@@ -81,7 +81,6 @@ def create_parser(prog: str | None = None) -> argparse.ArgumentParser:
|
|||||||
default=get_clan_flake_toplevel_or_env(),
|
default=get_clan_flake_toplevel_or_env(),
|
||||||
metavar="PATH",
|
metavar="PATH",
|
||||||
type=flake_path,
|
type=flake_path,
|
||||||
epilog="Default is dynamically determined based on the current directory.",
|
|
||||||
)
|
)
|
||||||
|
|
||||||
subparsers = parser.add_subparsers()
|
subparsers = parser.add_subparsers()
|
||||||
|
|||||||
@@ -1,11 +1,7 @@
|
|||||||
import argparse
|
import argparse
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import Tuple
|
|
||||||
from clan_cli import create_parser
|
from clan_cli import create_parser
|
||||||
import argparse
|
|
||||||
import os
|
|
||||||
from dataclasses import dataclass
|
|
||||||
from typing import Tuple
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@@ -69,7 +65,7 @@ def get_subcommands(
|
|||||||
to: list[Category],
|
to: list[Category],
|
||||||
level: int = 0,
|
level: int = 0,
|
||||||
prefix: list[str] = [],
|
prefix: list[str] = [],
|
||||||
) -> Tuple[list[Option], list[Option], list[Subcommand]]:
|
) -> tuple[list[Option], list[Option], list[Subcommand]]:
|
||||||
"""
|
"""
|
||||||
Generate Markdown documentation for an argparse.ArgumentParser instance including its subcommands.
|
Generate Markdown documentation for an argparse.ArgumentParser instance including its subcommands.
|
||||||
|
|
||||||
@@ -85,7 +81,6 @@ def get_subcommands(
|
|||||||
subcommands: list[Subcommand] = []
|
subcommands: list[Subcommand] = []
|
||||||
|
|
||||||
for action in parser._actions:
|
for action in parser._actions:
|
||||||
|
|
||||||
if isinstance(action, argparse._HelpAction):
|
if isinstance(action, argparse._HelpAction):
|
||||||
# Pseudoaction that holds the help message
|
# Pseudoaction that holds the help message
|
||||||
continue
|
continue
|
||||||
@@ -117,7 +112,6 @@ def get_subcommands(
|
|||||||
|
|
||||||
for action in parser._actions:
|
for action in parser._actions:
|
||||||
if isinstance(action, argparse._SubParsersAction):
|
if isinstance(action, argparse._SubParsersAction):
|
||||||
|
|
||||||
subparsers: dict[str, argparse.ArgumentParser] = action.choices
|
subparsers: dict[str, argparse.ArgumentParser] = action.choices
|
||||||
|
|
||||||
for name, subparser in subparsers.items():
|
for name, subparser in subparsers.items():
|
||||||
@@ -168,7 +162,6 @@ def collect_commands() -> list[Category]:
|
|||||||
if isinstance(action, argparse._SubParsersAction):
|
if isinstance(action, argparse._SubParsersAction):
|
||||||
subparsers: dict[str, argparse.ArgumentParser] = action.choices
|
subparsers: dict[str, argparse.ArgumentParser] = action.choices
|
||||||
for name, subparser in subparsers.items():
|
for name, subparser in subparsers.items():
|
||||||
|
|
||||||
(_options, _positionals, _subcommands) = get_subcommands(
|
(_options, _positionals, _subcommands) = get_subcommands(
|
||||||
subparser, to=result, level=2, prefix=[name]
|
subparser, to=result, level=2, prefix=[name]
|
||||||
)
|
)
|
||||||
@@ -183,7 +176,7 @@ def collect_commands() -> list[Category]:
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
def weight_cmd_groups(c: Category):
|
def weight_cmd_groups(c: Category) -> tuple[str, int, str]:
|
||||||
sub = [o for o in result if o.title.startswith(c.title) and o.title != c.title]
|
sub = [o for o in result if o.title.startswith(c.title) and o.title != c.title]
|
||||||
weight = len(c.title.split(" "))
|
weight = len(c.title.split(" "))
|
||||||
if sub:
|
if sub:
|
||||||
|
|||||||
Reference in New Issue
Block a user