click-contrib / click-man

Automate generation of man pages for python click applications :star:
MIT License
163 stars 35 forks source link

Add support for typer applications #51

Open sbordeynemics opened 2 years ago

sbordeynemics commented 2 years ago

Typer is a CLI python package built on click, so it stands to reason that this project should work just fine with CLIs built with typer.

Here's the output of the command to generate man pages :

poetry run click-man --target ./man my-cli
Load entry point my-cli
Error: Could not find click.Command object for "my-cli".

The entry point points to a typer.Typer instance. The click object can be fetched using typer.main.get_command(app: typer.Typer), which should make it trivial to make the app work.

I've tried to make it work myself :

I may try to import click-man in my poetry scripts and run it using poetry run gen-man or something, in order to make it work, but having typer support out of the box would be great.

sbordeynemics commented 2 years ago
import typer
from click_man.core import write_man_pages

from cli import app, __version__

def make_man():
    '''Generates man pages for the CLI'''
    cli = typer.main.get_command(app)
    name = 'cli'
    version = __version__
    target_dir = './man'
    write_man_pages(name, cli, version=version, target_dir=target_dir)
    return

That code snippet seems to work just fine to generate man pages for my typer CLI