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

feat: added arguments for more flexibility #228

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

iMilnb
Copy link

@iMilnb iMilnb commented Oct 31, 2024

Use argparse to be able to pass server address and port, along with other hardcoded parameters.

@fewmysteriessolved
Copy link

fewmysteriessolved commented Dec 27, 2024

Regarding your commit 8f33849 it may be a small improvement to use:

action="store_true"instead of type=bool, default=False

Which means....

parser.add_argument("--debug", action="store_true", help="Enable debug mode")
parser.add_argument("--share", action="store_true", dest="share", help="Enable sharing")
parser.add_argument("--show-error", action="store_true", dest="show_error", help="Enable error display")

...instead of

parser.add_argument("--share", type=bool, default=False)

--
Therefore to enable all flags the simplified command would look like this:

python app.py --debug --share --show-error

or keeping everything disabled

python app.py

Why?

action="store_true"

explicitly states the desired behavior: if the flag (e.g. --share) is present on the command line, the corresponding argument (e.g. args.share) will be set to True. If the flag is not present, it defaults to False.

Advantage:
Using type=bool can lead to unexpected behavior when giving an explicit argument.
For instance the user provides an explicit value for the argument (e.g., --share True), it might not be interpreted correctly. action="store_true" avoids these potential pitfalls.

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.

2 participants