click-contrib / click-man

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

Sub-commands manual not generated #14

Open ivansenic opened 6 years ago

ivansenic commented 6 years ago

Hi,

We use such setup:

from setuptools import setup, find_packages

setup(
    name='ap',
    version='1.0',
    packages=find_packages(),
    include_package_data=True,
    install_requires=[
        'Click'
    ],
    entry_points='''
        [console_scripts]
        ap=main:cli
    '''
)

with the dynamic sub-commands located in the [root]/scripts/commands and dynamic loading in the main.py:

COMMANDS_FOLDER = os.path.join(os.path.dirname(__file__), 'scripts', 'commands')

class ApCli(click.MultiCommand):

    def list_commands(self, ctx):
        """Provides names of all commands by searching the commands folder"""
        rv = []
        for filename in os.listdir(COMMANDS_FOLDER):
            # find py files, ignore the ones that start with __ (f.e. __init__.py)
            if filename.endswith('.py') and not filename.startswith('__'):
                rv.append(filename[:-3])
        rv.sort()
        return rv

    def get_command(self, ctx, name):
        """Returns compiled command for given name, expects that command has a function same as its name"""
        ns = {}
        fn = os.path.join(COMMANDS_FOLDER, name + '.py')
        if os.path.isfile(fn):
            with open(fn) as f:
                code = compile(f.read(), fn, 'exec')
                eval(code, ns, ns)
        else:
            return

        if ns.get(name) is not None:
            return ns[name]

@click.command(cls=ApCli)
@click.option('-v', '--verbose', is_flag=True, default=False, help='Enables verbose mode.')
@click.version_option()
@ap.pass_context
def cli(context, verbose):
    """Main entry point for the CLI"""
    context.logger.isVerbose = verbose

However manual get generated only for our main entry point and for nothing else.. Any idea how can we fix this?

jhermann commented 4 years ago

Support for command groups seems to be missing generally, as I got this on my first test…

AttributeError: 'Group' object has no attribute 'get_short_help_str'
smarlowucf commented 4 years ago

The AttributeError I think is an issue with Click < 7.0. https://github.com/click-contrib/click-man/pull/33 should fix this.