django-click
django-click copied to clipboard
Can't pass "help" parameter to click argument
The following script works with the base click
library but raises an exception with the django-click
library.
import djclick as click
@click.command()
@click.argument("name", help="Some name")
def command(name):
click.echo(f"Hi {name}!")
Exception:
Traceback (most recent call last):
File "/app/./manage.py", line 22, in <module>
main()
File "/app/./manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 244, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 37, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/usr/local/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 790, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "/app/core/management/commands/click1.py", line 6, in <module>
def command(name):
File "/usr/local/lib/python3.9/site-packages/click/decorators.py", line 168, in decorator
_param_memo(f, ArgumentClass(param_decls, **attrs))
File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1984, in __init__
Parameter.__init__(self, param_decls, required=required, **attrs)
TypeError: __init__() got an unexpected keyword argument 'help'
I think you and I have both made this mistake @johnnymetz . Arguments don't have help text.
Someone else had the exact same problem here... https://github.com/pallets/click/issues/466 ... so were also not the only two people 😄
Documenting Arguments
click.argument() does not take a help parameter. This is to follow the general convention of Unix tools of using arguments for only the most necessary things, and to document them in the command help text by referring to them by name.
Not sure if you want to close this as "user error" or wait for a reply, but id say its probably safe to say this isn't a bug in your library @GaretJax