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
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions zulip_bots/zulip_bots/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

import sys
from typing import Optional

Expand All @@ -17,7 +18,32 @@
current_dir = os.path.dirname(os.path.abspath(__file__))


def normalize_args() -> None:
"""Replaces various dash variations in arguments with standard options in command lines interfaces."""
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"


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

usage = """
zulip-run-bot <bot_name> --config-file ~/zuliprc
zulip-run-bot --help
Expand Down