Skip to content

Any way to ignore unknown commands? #1509

@kylepollina

Description

@kylepollina

Click v7.0

I'm trying to write a wrapper for git for my own purposes. I'm new to using click, so correct me if I'm doing this the wrong way.

My goal is to have special sub commands do specific functionalities, and if the argument is not a special sub command, default to running git with the given arguments.

I have something like this

import click

@click.group(
    invoke_without_command=True,
    context_settings = {'ignore_unknown_options': True, 'allow_extra_args': True}
)
@click.pass_context
def cli(ctx):
    if not ctx.invoked_subcommand:
        # run git with given arguments instead
        ...

@cli.command()
def special_command():
    # do some special functionality

What I want is when I run the cli with arguments/commands that isn't the special command, to run git with those arguments. But the cli gives me a Error: No such command ... if I give it any command other than the special command. Is this possible? Or am I doing this the wrong way?

I also want to add that I'm running this through setuptools and the entry point is cli

Example: My git wrapper is called cli

cli special_command will run the special command

cli status will run git status

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