Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example from README not working #18

Open
fepegar opened this issue Nov 27, 2023 · 2 comments
Open

Example from README not working #18

fepegar opened this issue Nov 27, 2023 · 2 comments

Comments

@fepegar
Copy link

fepegar commented Nov 27, 2023

Hi, and thanks for this library!

I'm trying the example from the README, but I'm getting the following error:

mkdocs_typer._exceptions.MkDocsTyperException: 'cli' must be a 'typer.main.Typer' object, got <class 'function'>

If I use :command: my_app (instead of cli), I get no error, but I see a big my_app in the docs:

Screenshot 2023-11-27 at 01 52 12
  1. Is there a bug?
  2. Am I doing something wrong?
  3. Is it possible to hide that my_app header? I tried playing with :depth: with no luck.
@multimeric
Copy link

Indeed, this seems to be broken. My guess is that the typer API changed such that @command no longer returns a typer object and now just returns the unchanged function. This package should be able to work with the app object but as you noted, that's also broken.

I found a workaround that I'm quite happy with, though:

  1. pip install mkdocs-click
  2. Use mkdocs-click in your mkdocs.yml:
markdown_extensions:
-- mkdocs-typer
+- mkdocs-click
  1. Create a click app in your Python module:
+ from typer.main import get_command
app = Typer()
+ click_app = get_command(app)
  1. Update your markdown docs:
-::: mkdocs-typer
-    :module: my_pkg.__main__
-    :command: app
+::: mkdocs-click
+    :module: my_pkg.__main__
+    :command: click_app

@fepegar
Copy link
Author

fepegar commented Aug 21, 2024

Thanks for your reply, @multimeric!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants