Skip to content

[Feature] Pass version_option() to Command(params=) #2324

@sla-1

Description

@sla-1

Hello,

We're using the click.MultiCommand in a custom class and I was trying to use the built-in click.version_option() in click, but I would get this error anytime I tried to pass the function option to the MultiCommand class:

ERROR:'function' object has no attribute 'opts'

My init block looks like this, and if I change click.version_option to just click.options(...) it works just fine.

class CustomCli(click.MultiCommand):
    """Custom click.MultiCommand"""

    def __init__(self, commands_dir, description=None):
        env_option = click.version_option(version=0.1)
        params = [env_option]
        click.MultiCommand.__init__(self, help=description, params=params)
        self.__commands_dir = commands_dir
    
    def list_commands(self, ctx):
       ...
       return x
    
    def get_command(self, ctx, name):
       ...
       return x

The reusable version_options should be passable to multiclick. If there was a different way use click.version_option()with MultiCommand please let me know. I couldn't find any documentation on it.

Environment:

  • Python version: 3.8
  • Click version: 8.1.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions