Skip to content

Improved Arg Parsing #114

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

Open
AliSot2000 opened this issue Dec 20, 2024 · 1 comment
Open

Improved Arg Parsing #114

AliSot2000 opened this issue Dec 20, 2024 · 1 comment
Labels
comment/feedback A comment or feedback about difPy.

Comments

@AliSot2000
Copy link

Hi again

FYI, you can improve the argparsing you're doing by using the action parameter of add_argument.

Example:

parser.add_argument('-la', '--lazy', type=lambda x: bool(_help._strtobool(x)), help='Compares image dimensions before comparison process.', required=False, choices=[True, False], default=True)    

If you provide -la or --lazy you must provide a True or False otherwise the parser will complain that there's no argument for the flag.

dif.py: error: argument -la/--lazy: expected one argument 

Try this instead:

parser.add_argument('-la', '--lazy', help='Compares image dimensions before comparison process.', action='store_true')

The action store_true will store True in the namespace when the flag is provided, it sets required to False, sets the type to bool and sets the default to False

If you want a flag which disables something like rotate you can use the inverse store_false which just inverts the default and const so:

parser.add_argument('-ro', '--rotate', action="store_False")
@elisemercury
Copy link
Owner

Hi @AliSot2000,

Thanks a lot for the suggestion! We will potentially consider your suggestion this as part of future upgrades.

Best,
Elise

@elisemercury elisemercury added the comment/feedback A comment or feedback about difPy. label Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comment/feedback A comment or feedback about difPy.
Projects
None yet
Development

No branches or pull requests

2 participants