Skip to content

Commit

Permalink
add cli command
Browse files Browse the repository at this point in the history
  • Loading branch information
iyume committed Feb 1, 2023
1 parent c3b5f45 commit aeb3952
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
34 changes: 31 additions & 3 deletions nb_autodoc/__main__.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,50 @@
from typing import Tuple
from typing_extensions import Literal

import click

from nb_autodoc.builders.markdown import MarkdownBuilder
from nb_autodoc.config import Config
from nb_autodoc.log import logger
from nb_autodoc.manager import ModuleManager

logger.setLevel("INFO")


@click.command()
@click.argument("modules", nargs=-1, required=True)
@click.argument("module", required=True)
@click.option(
"-o",
"--output-dir",
default="build",
type=click.Path(exists=False, file_okay=False, writable=True, executable=True),
show_default=True,
)
def main(modules: Tuple[str, ...], output_dir: str) -> None:
print(modules)
@click.option("-s", "--skip", multiple=True, help="skip import modules")
@click.option("-u", "--undoc", multiple=True, help="undocument modules")
@click.option(
"--markdown-linkmode",
default="heading_id",
type=click.Choice(["heading_id", "vuepress"]),
show_default=True,
)
def main(
module: str,
output_dir: str,
skip: Tuple[str, ...],
undoc: Tuple[str, ...],
markdown_linkmode: Literal["heading_id", "vuepress"],
) -> None:
manager = ModuleManager(
module,
config=Config(
output_dir=output_dir,
skip_import_modules=set(skip),
exclude_documentation_modules=set(undoc),
),
)
builder = MarkdownBuilder(manager, link_mode=markdown_linkmode)
builder.write()


if __name__ == "__main__":
Expand Down
16 changes: 14 additions & 2 deletions nb_autodoc/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ class Config(TypedDict, total=False):
Carefully add this option on a dependent module because we want to
analyze python object relationship.
Support `fnmatch` pattern, such as '*', '?', etc.
Default: `frozenset()`
CLI Flags: `-s`, `--skip`
"""

### Builder Config ###
Expand All @@ -46,10 +49,19 @@ class Config(TypedDict, total=False):
"""Exclude documentation modules.
Support `fnmatch` pattern, such as '*', '?', etc.
Default: `frozenset()`
CLI Flags: `-u`, `--undoc`
"""

output_dir: str
"""Documentation output directory. Default to 'build'."""
"""Documentation output directory.
Default: `'build'`.
CLI Flags: `-o`, `--output-dir`
"""

write_encoding: str
"""File encoding to write. Default to 'utf-8'."""
Expand Down

0 comments on commit aeb3952

Please sign in to comment.