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

Fix:#477 Normalize command-line arguments with various dash types #853

Closed

Conversation

avijitdas126
Copy link
Collaborator

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
  • Self-reviewed the changes for clarity and maintainability
    (variable names, code reuse, readability, etc.).

Communicate decisions, questions, and potential concerns.

  • Explains differences from previous plans (e.g., issue description).
  • Highlights technical choices and bugs encountered.
  • Calls out remaining decisions and concerns.
  • Automated tests verify logic where appropriate.

Individual commits are ready for review (see commit discipline).

  • Each commit is a coherent idea.
  • Commit message(s) explain reasoning and motivation for changes.

Completed manual review and testing of the following:

  • Visual appearance of the changes.
  • Responsiveness and internationalization.
  • Strings and tooltips.
  • End-to-end functionality of buttons, interactions and flows.
  • Corner cases, error conditions, and easily imagined bugs.

@zulipbot
Copy link
Member

zulipbot commented Feb 2, 2025

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 git commit --amend in your command line client to amend your commit message description with Fixes #477..

An example of a correctly-formatted commit:

commit fabd5e450374c8dde65ec35f02140383940fe146
Author: zulipbot
Date:   Sat Mar 18 13:42:40 2017 -0700

    pull requests: Check PR commits reference when issue is referenced.

    Fixes #51.

To learn how to write a great commit message, please refer to our guide.

@zulipbot zulipbot added size: M and removed size: S labels Feb 2, 2025
@avijitdas126 avijitdas126 force-pushed the fix/-normalize-argument-dashes-477 branch from cd669a0 to 7b6909d Compare February 2, 2025 14:36
@avijitdas126
Copy link
Collaborator Author

@alya could you please review this PR?

Comment on lines 21 to 44
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"


Copy link
Collaborator Author

@avijitdas126 avijitdas126 Feb 2, 2025

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
Copy link
Collaborator Author

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
Copy link
Collaborator Author

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()

Copy link
Collaborator Author

@avijitdas126 avijitdas126 left a 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`.
@alya
Copy link
Contributor

alya commented Feb 3, 2025

Closing this PR, as there was no underlying bug to solve. Thanks for giving it a try, @avijitdas126 !

@alya alya closed this Feb 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot use config-file as a parameter
3 participants