-
-
Notifications
You must be signed in to change notification settings - Fork 388
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
Fix:#477 Normalize command-line arguments with various dash types #853
Fix:#477 Normalize command-line arguments with various dash types #853
Conversation
Hello @avijitdas126, it seems like you have referenced #477 in your pull request description, but you have not referenced them in your commit message description(s). Referencing an issue in a commit message automatically closes the corresponding issue when the commit is merged, which makes the issue tracker easier to manage. Please run An example of a correctly-formatted commit:
To learn how to write a great commit message, please refer to our guide. |
cd669a0
to
7b6909d
Compare
@alya could you please review this PR? |
zulip_bots/zulip_bots/run.py
Outdated
def normalize_args() -> None: | ||
"""Replaces various dash variations in arguments with standard options.""" | ||
dash_variations = r"[\u002D\u2010\u2011\u2012\u2013\u2014\u2015]" | ||
for i, arg in enumerate(sys.argv): | ||
if re.match(rf"^{dash_variations}{{2}}config{dash_variations}file$", arg): | ||
sys.argv[i] = "--config-file" | ||
elif re.match(rf"^{dash_variations}c$", arg): | ||
sys.argv[i] = "-c" | ||
elif re.match( | ||
rf"^{dash_variations}{{2}}bot{dash_variations}config{dash_variations}file$", arg | ||
): | ||
sys.argv[i] = "--bot-config-file" | ||
elif re.match(rf"^{dash_variations}c$", arg): | ||
sys.argv[i] = "-b" | ||
elif re.match(rf"^{dash_variations}{{2}}force$", arg): | ||
sys.argv[i] = "--force" | ||
elif re.match(rf"^{dash_variations}{{2}}registry$", arg): | ||
sys.argv[i] = "--registry" | ||
elif re.match(rf"^{dash_variations}r$", arg): | ||
sys.argv[i] = "-r" | ||
elif re.match(rf"^{dash_variations}{{2}}provision$", arg): | ||
sys.argv[i] = "--provision" | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix: Normalize various dash variations in CLI arguments
This update ensures that different dash variations (e.g., en dash, em dash)
in command-line arguments are replaced with standard options.
It improves argument consistency and prevents unexpected behavior
when parsing user inputs.
Affected arguments include:
--config-file
,-c
,--bot-config-file
,-b
,--force
,
--registry
,-r
, and--provision
.
@@ -3,6 +3,7 @@ | |||
import argparse | |||
import logging | |||
import os | |||
import re |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Import re module for fix:#477
def parse_args() -> argparse.Namespace: | ||
normalize_args() # Fix arguments before parsing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use normalize_args()
function in parse_args()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please take a look at my PR #853?
I would appreciate your review and feedback. Once you're happy with the changes, kindly merge it.
Thanks in advance! 🙏✨
This update ensures that different dash variations (e.g., en dash, em dash) in command-line arguments are replaced with standard options. It improves argument consistency and prevents unexpected behavior when parsing user inputs. Affected arguments include: - `--config-file`, `-c`, `--bot-config-file`, `-b`, `--force`, `--registry`, `-r`, and `--provision`.
Closing this PR, as there was no underlying bug to solve. Thanks for giving it a try, @avijitdas126 ! |
This pull request enhances the command-line argument parser by adding normalization for various dash types. The changes ensure that arguments like --config-file, –config-file (en-dash), and —config-file (em-dash) are treated uniformly.
Included comprehensive unit tests to validate normalization for all known dash types.
Fixes: #477
Key Changes:
Implemented normalize_args() to replace non-standard dashes with standard hyphens.
Added support for:
--config-file
and its variations.-c
and its variations.--bot-config-file
and its variations.-b
and its variations.--force
and its variations.--registry
and its variations.-r
and its variations.--provision
and its variations.Impact: Improves user experience by preventing errors caused by invisible or non-standard dash characters in command-line arguments.
How did you test this PR?
Self-review checklist
(variable names, code reuse, readability, etc.).
Communicate decisions, questions, and potential concerns.
Individual commits are ready for review (see commit discipline).
Completed manual review and testing of the following: