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

Add note to always use positional args first #15761

Closed

Conversation

AbrilRBS
Copy link
Member

@AbrilRBS AbrilRBS commented Feb 27, 2024

This adds a note to let the user know they should set positional args first in commands

conan/cli/command.py Outdated Show resolved Hide resolved
Copy link
Member

@memsharded memsharded left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😱 😱

@AbrilRBS AbrilRBS marked this pull request as ready for review March 4, 2024 21:26
@AbrilRBS AbrilRBS changed the title Make argparse output positionals before optionals Add note to always use positional args first Mar 4, 2024
Comment on lines +125 to +127
formatted_help += ("\nNOTE: Use always positional parameters first\n"
" conan <command> <positional args> [optional args]\n")
return formatted_help
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
formatted_help += ("\nNOTE: Use always positional parameters first\n"
" conan <command> <positional args> [optional args]\n")
return formatted_help
lines = formatted_help.splitlines()
note = ("\nNOTE: Use always positional parameters first\n"
" conan <command> <positional args> [optional args]\n")
lines.insert(lines.index(""), note)
return "\n".join(lines)

I tried it, but I was not convinced, as it shows at the very end, not very visible when there are arguments.
Then I tried this, it seems it would be a bit better IMHO.

Still, it is also missing in the short usage error when some arg is missing or incorrect. This can be solved by adding the format_usage() method too.

All in all, seems a bit too dirty/too much for a known Python bug: python/cpython#53584

Not sure what would be the best approach to be honest.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's just make sure we mention it somewhere in the docs then!

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

Successfully merging this pull request may close these issues.

None yet

2 participants