You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Ignore/pass over the double dash (--) marker #1340
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_contextdefcli(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.
Pretty much a duplicate of #619, see additional discussion there. Just like if you need to pass an argument that looks like an option, use -- if you need to pass a -- as an argument.
Activity
adzenith commentedon Dec 16, 2020
Thoughts on making this into a PR? I would love to see this in upstream
click.Midnighter commentedon Jun 24, 2021
sashati commentedon Sep 23, 2021
POD666 commentedon Oct 4, 2021
I end up with the following snippet:
It's limited to my use case but might be helpful.
davidism commentedon Feb 27, 2022
Pretty much a duplicate of #619, see additional discussion there. Just like if you need to pass an argument that looks like an option, use
--if you need to pass a--as an argument.