Skip to content

Ignore/pass over the double dash (--) marker #1340

@Higgcz

Description

@Higgcz

I'm working on a command line application which includes something like ssh wrapper. Basically what I'm doing is I'm resolving hostname myself, but then I want to pass all other parameters to the underlying ssh command. However, I've noticed that Click is consuming the first double dash (--) marker.

I was hoping Click has somewhere a variable containing all unprocessed arguments, but apparently, that's not the case, or at least I couldn't find it. So, in the end, I ended up adding one more click.Context option called ignore_end_of_the_opts_marker that tells Click to pass over the double dash, so if you combine it with ignore_unknown_options, you can pick all unprocessed arguments.

Eg.:

@click.command(context_settings=dict(
    ignore_unknown_options=True,
    ignore_end_of_the_opts_marker=True
    ))
@click.argument('args', nargs=-1, type=click.UNPROCESSED)
@click.pass_context
def cli(ctx, args):
    print('All the arguments:', args)

I've noticed some people are also writing wrapper-like tools, so maybe more people would be interested in this option.

So far, I'm not sure if it's worth a Pull Request, let me know if it is, I've tried to document everything consistently with the rest of the code, but I can imagine there could be a better name for this option. Or maybe you have a better idea of how to solve this issue.

Anyway, if someone is interested, here is my fork: https://github.com/Higgcz/click

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