Code Monkey home page Code Monkey logo

Comments (6)

stephenfin avatar stephenfin commented on July 17, 2024 1

This issue is main does not return a click object. You need to modify it like so.

diff --git a/mycli.py b/mycli.py
index 0b87781..fb3afb4 100644
--- a/mycli.py
+++ b/mycli.py
@@ -16,9 +16,7 @@ def test_command():
     """
     click.echo("Hello world")
 
-def main():
-    mycli.add_command(test_command)
-    mycli()
+mycli.add_command(test_command)
 
 if __name__ == '__main__':
-    main()
+    mycli()
diff --git a/setup.py b/setup.py
index 2afc564..20a85e7 100644
--- a/setup.py
+++ b/setup.py
@@ -9,7 +9,7 @@ setup(
     install_requires=['click'],
     entry_points='''
         [console_scripts]
-        my=mycli:main
+        my=mycli:mycli
     ''',
     classifiers=[
         'Natural Language :: English',

This ensures that (a) the add_command function is always called and the command registered and (b) you're trying to document a click object and not a random function.

from click-man.

stephenfin avatar stephenfin commented on July 17, 2024

We saw a similar issue with https://github.com/click-contrib/sphinx-click. tl;dr: you're using the wrong configuration. See click-contrib/sphinx-click#13

from click-man.

ElieDeloumeau avatar ElieDeloumeau commented on July 17, 2024

Which configuration?

from click-man.

stephenfin avatar stephenfin commented on July 17, 2024

Which configuration?

The commands listed in your console_scripts setting in conf.py. Have you a minimal test case you can share?

from click-man.

ElieDeloumeau avatar ElieDeloumeau commented on July 17, 2024

Sure, here is the test case:

mycli.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import click

@click.group()
def mycli():
    """
    Test CLI
    """
    pass

@click.command()
def test_command():
    """
    This is a test command
    """
    click.echo("Hello world")

def main():
    mycli.add_command(test_command)
    mycli()

if __name__ == '__main__':
    main()

setup.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-
from setuptools import setup, find_packages

setup(
    name='MyCLI',
    py_modules=['mycli'],
    packages=find_packages(),
    install_requires=['click'],
    entry_points='''
        [console_scripts]
        my=mycli:main
    ''',
    classifiers=[
        'Natural Language :: English',
        'Operating System :: Microsoft :: Windows',
        'Operating System :: MacOS :: MacOS X',
        'Operating System :: POSIX :: Linux',
        'Programming Language :: Python'
    ]
)

Executed command:

$ PATH=env/bin/ click-man my 
Load entry point my
Generate man pages for my in /home/elie/Documents/git/mycli/man
Traceback (most recent call last):
  File "env/bin//click-man", line 11, in <module>
    sys.exit(cli())
  File "/home/elie/Documents/git/mycli/env/lib/python2.7/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/home/elie/Documents/git/mycli/env/lib/python2.7/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/home/elie/Documents/git/mycli/env/lib/python2.7/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/elie/Documents/git/mycli/env/lib/python2.7/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/home/elie/Documents/git/mycli/env/lib/python2.7/site-packages/click_man/__main__.py", line 49, in cli
    write_man_pages(name, cli, version=entry_point.dist.version, target_dir=target)
  File "/home/elie/Documents/git/mycli/env/lib/python2.7/site-packages/click_man/core.py", line 54, in write_man_pages
    ctx = click.Context(cli, info_name=name, parent=parent_ctx)
  File "/home/elie/Documents/git/mycli/env/lib/python2.7/site-packages/click/core.py", line 254, in __init__
    allow_extra_args = command.allow_extra_args
AttributeError: 'function' object has no attribute 'allow_extra_args'

from click-man.

ElieDeloumeau avatar ElieDeloumeau commented on July 17, 2024

It works! Many thanks 😃

from click-man.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.