This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 3a147ee1e6 Add verification if short options in breeze are repeated 
(#34269)
3a147ee1e6 is described below

commit 3a147ee1e64cd6363ae8f033a9c5215414551ce7
Author: Amogh Desai <[email protected]>
AuthorDate: Wed Sep 13 03:52:35 2023 +0530

    Add verification if short options in breeze are repeated (#34269)
---
 .../src/airflow_breeze/commands/setup_commands.py  | 37 ++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/dev/breeze/src/airflow_breeze/commands/setup_commands.py 
b/dev/breeze/src/airflow_breeze/commands/setup_commands.py
index a5f1d38699..4ee18045d2 100644
--- a/dev/breeze/src/airflow_breeze/commands/setup_commands.py
+++ b/dev/breeze/src/airflow_breeze/commands/setup_commands.py
@@ -269,6 +269,32 @@ def dict_hash(dictionary: dict[str, Any]) -> str:
     return dhash.hexdigest()
 
 
+def is_short_flag(opt):
+    return len(opt) == 2 and (not opt.startswith("--"))
+
+
+def validate_params_for_command(command_params, command):
+    options_command_map = {}
+    is_duplicate_found = False
+    if "params" in command_params:
+        for param in command_params["params"]:
+            name = param["name"]
+            for opt in param["opts"]:
+                if is_short_flag(opt):
+                    if opt not in options_command_map:
+                        options_command_map[opt] = [[command, name]]
+                    else:
+                        # same flag used in same command
+                        get_console().print(
+                            f"[error] {opt} short flag has duplicate short 
hand commands under command(s): "
+                            f"{'breeze ' + command} for parameters "
+                            f"{options_command_map[opt][0][1]} and {name}\n"
+                        )
+                        options_command_map[opt][0][1] = name
+                        is_duplicate_found = True
+    return is_duplicate_found
+
+
 def get_command_hash_export() -> str:
     import rich_click
 
@@ -281,6 +307,9 @@ def get_command_hash_export() -> str:
         commands_dict = the_context_dict["command"]["commands"]
         options = rich_click.rich_click.OPTION_GROUPS
         for command in sorted(commands_dict.keys()):
+            duplicate_found = 
validate_params_for_command(commands_dict[command], command)
+            if duplicate_found:
+                sys.exit(1)
             current_command_dict = commands_dict[command]
             current_command_hash_dict = {
                 "command": current_command_dict,
@@ -288,7 +317,13 @@ def get_command_hash_export() -> str:
             }
             if "commands" in current_command_dict:
                 subcommands = current_command_dict["commands"]
+                duplicate_found_subcommand = False
                 for subcommand in sorted(subcommands.keys()):
+                    duplicate_found = validate_params_for_command(
+                        commands_dict[command]["commands"][subcommand], 
command + " " + subcommand
+                    )
+                    if duplicate_found:
+                        duplicate_found_subcommand = True
                     subcommand_click_dict = subcommands[subcommand]
                     try:
                         subcommand_rich_click_dict = options[f"breeze 
{command} {subcommand}"]
@@ -307,6 +342,8 @@ def get_command_hash_export() -> str:
                         "rich_click_options": subcommand_rich_click_dict,
                     }
                     
hashes.append(f"{command}:{subcommand}:{dict_hash(final_dict)}")
+                if duplicate_found_subcommand:
+                    sys.exit(1)
                 
hashes.append(f"{command}:{dict_hash(current_command_hash_dict)}")
             else:
                 
hashes.append(f"{command}:{dict_hash(current_command_hash_dict)}")

Reply via email to