Replies: 4 comments 2 replies
-
This already exists. |
Beta Was this translation helpful? Give feedback.
-
@davidism Please elaborate. Is this documented anywhere? I found no references to double-dashes in the click documentation. |
Beta Was this translation helpful? Give feedback.
-
Edit: never mind, this is caused by This seems broken on 8.1.6, that or it doesn't behave how I expected:
import click
print(click.__version__)
@click.command()
@click.argument('files', nargs=-1, type=click.Path())
def touch(files):
"""Print all FILES file names."""
for filename in files:
click.echo(filename)
if __name__ == "__main__":
touch() |
Beta Was this translation helpful? Give feedback.
-
FYI, #619 is the first hit I found on google, but it's locked so it cannot be commented on, and it will also not backlink if you link to it, making this answer hard to find. args = sys.argv
# skip everything after -- if it exists
if "--" in args:
args = args[: args.index("--")]
cli(args[1:]) |
Beta Was this translation helpful? Give feedback.
-
I need to accept some arguments that should be ignored by click. I am aware that it is possible to enable extra arguments however it has some major drawbacks. Use of this feature means that misspelled arguments are ignored which can cause issues. I think it would be helpful to be able to run a click command with a mix of parsed and unparsed arguments. In practice it would work something like this:
If --parsed-arg1 was misspelled in this case it would be flagged as an error. Any arguments after the double-dash would be ignored by click.
If this proposal is rejected, maybe there is a way to hook into post parsing and add custom validation on the extra arguments for unexpected contents.
Beta Was this translation helpful? Give feedback.
All reactions