Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make use of argparse.REMAINDER #53

Open
pfuntner opened this issue Dec 11, 2019 · 1 comment
Open

Make use of argparse.REMAINDER #53

pfuntner opened this issue Dec 11, 2019 · 1 comment

Comments

@pfuntner
Copy link
Owner

pfuntner commented Dec 11, 2019

I have some tools such as sudo-ssh where an option might appear after the first positional parameter but I don't want the tool to interpret it as an option for it. For instance, without nargs=argparse.REMAINDER this command won't do what I want:

sudo-ssh foo find / -name bar

Instead, sudo-ssh complains about the -n option that it knows nothing about but the option isn't for sudo-ssh! It's for find when the tool runs the command on the remote foo machine!

WIthout nargs=argparse.REMAINDER, you need to do something like this instead to protect the faux-option:

sudo-ssh foo -- find / -name bar

But if nargs=argparse.REMAINDER is used, either use does what I want.

See:

@pfuntner
Copy link
Owner Author

While using this option could make -- unnecessary, it could also make the argparse help less accurate. Right now, I can rely on argparse automatically building the command string for online help.

It's not a major pain to use --. Sometimes I make use of it even when it's not necessary and that's not a bad practice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant