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

henry3260 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 020428773e7 Remove duplicate GroupCommandParser type from airflowctl 
CLI (#76345)
020428773e7 is described below

commit 020428773e7b6ef38ed98527ecc1669e5fa500e2
Author: Andrew Chang <[email protected]>
AuthorDate: Thu Nov 12 16:16:49 2026 +0800

    Remove duplicate GroupCommandParser type from airflowctl CLI (#76345)
    
    GroupCommandParser was a copy of GroupCommand without the
    api_operation field. The parser converted GroupCommand to it in three
    places, and argparse never saw either type. Nothing read api_operation
    either, so both are removed and the parser matches the airflow-core
    CLI parser again.
---
 airflow-ctl/src/airflowctl/ctl/cli_config.py | 25 +------------------------
 airflow-ctl/src/airflowctl/ctl/cli_parser.py | 18 +++++-------------
 2 files changed, 6 insertions(+), 37 deletions(-)

diff --git a/airflow-ctl/src/airflowctl/ctl/cli_config.py 
b/airflow-ctl/src/airflowctl/ctl/cli_config.py
index b19b5d20b5e..7b0e84f7efa 100755
--- a/airflow-ctl/src/airflowctl/ctl/cli_config.py
+++ b/airflow-ctl/src/airflowctl/ctl/cli_config.py
@@ -547,33 +547,11 @@ class GroupCommand(NamedTuple):
     name: str
     help: str
     subcommands: Iterable
-    api_operation: dict | None = None
     description: str | None = None
     epilog: str | None = None
 
 
-class GroupCommandParser(NamedTuple):
-    """ClI command with subcommands."""
-
-    name: str
-    help: str
-    subcommands: Iterable
-    description: str | None = None
-    epilog: str | None = None
-
-    @classmethod
-    def from_group_command(cls, group_command: GroupCommand) -> 
GroupCommandParser:
-        """Create GroupCommandParser from GroupCommand."""
-        return cls(
-            name=group_command.name,
-            help=group_command.help,
-            subcommands=group_command.subcommands,
-            description=group_command.description,
-            epilog=group_command.epilog,
-        )
-
-
-CLICommand = ActionCommand | GroupCommand | GroupCommandParser
+CLICommand = ActionCommand | GroupCommand
 
 
 class CommandFactory:
@@ -1229,7 +1207,6 @@ def merge_commands(
                         name=command.name,
                         help=command.help,
                         subcommands=current_subcommands,
-                        api_operation=merged_command.api_operation,
                         description=merged_command.description,
                         epilog=command.epilog,
                     )
diff --git a/airflow-ctl/src/airflowctl/ctl/cli_parser.py 
b/airflow-ctl/src/airflowctl/ctl/cli_parser.py
index 4e3c1fa3684..892fb17a8a4 100644
--- a/airflow-ctl/src/airflowctl/ctl/cli_parser.py
+++ b/airflow-ctl/src/airflowctl/ctl/cli_parser.py
@@ -38,7 +38,6 @@ from airflowctl.ctl.cli_config import (
     ActionCommand,
     DefaultHelpParser,
     GroupCommand,
-    GroupCommandParser,
     core_commands,
 )
 from airflowctl.exceptions import AirflowCtlException
@@ -55,10 +54,7 @@ airflow_commands = core_commands.copy()  # make a copy to 
prevent bad interactio
 log = logging.getLogger(__name__)
 
 
-ALL_COMMANDS_DICT: dict[str, CLICommand] = {
-    sp.name: GroupCommandParser.from_group_command(sp) if isinstance(sp, 
GroupCommand) else sp
-    for sp in airflow_commands
-}
+ALL_COMMANDS_DICT: dict[str, CLICommand] = {sp.name: sp for sp in 
airflow_commands}
 
 
 class AirflowHelpFormatter(RichHelpFormatter):
@@ -73,7 +69,7 @@ class AirflowHelpFormatter(RichHelpFormatter):
             self._indent()
             subactions = action._get_subactions()
             action_subcommands, group_subcommands = partition(
-                lambda d: isinstance(ALL_COMMANDS_DICT[d.dest], 
GroupCommandParser), subactions
+                lambda d: isinstance(ALL_COMMANDS_DICT[d.dest], GroupCommand), 
subactions
             )
             yield Action([], f"\n{' ':{self._current_indent}}Groups", nargs=0)
             self._indent()
@@ -119,9 +115,7 @@ def get_parser() -> argparse.ArgumentParser:
     subparsers.required = True
 
     for _, sub in sorted(ALL_COMMANDS_DICT.items()):
-        _add_command(
-            subparsers, GroupCommandParser.from_group_command(sub) if 
isinstance(sub, GroupCommand) else sub
-        )
+        _add_command(subparsers, sub)
 
     return parser
 
@@ -139,8 +133,6 @@ def _sort_args(args: Iterable[Arg]) -> Iterable[Arg]:
 
 
 def _add_command(subparsers: argparse._SubParsersAction, sub: CLICommand) -> 
None:
-    if isinstance(sub, GroupCommand):
-        sub = GroupCommandParser.from_group_command(sub)
     if isinstance(sub, ActionCommand) and sub.hide:
         sub_proc = subparsers.add_parser(sub.name, epilog=sub.epilog)
     else:
@@ -150,7 +142,7 @@ def _add_command(subparsers: argparse._SubParsersAction, 
sub: CLICommand) -> Non
     add_preview_action(sub_proc)
     sub_proc.formatter_class = LazyRichHelpFormatter
 
-    if isinstance(sub, GroupCommandParser):
+    if isinstance(sub, GroupCommand):
         _add_group_command(sub, sub_proc)
     elif isinstance(sub, ActionCommand):
         _add_action_command(sub, sub_proc)
@@ -164,7 +156,7 @@ def _add_action_command(sub: ActionCommand, sub_proc: 
argparse.ArgumentParser) -
     sub_proc.set_defaults(func=sub.func)
 
 
-def _add_group_command(sub: GroupCommandParser, sub_proc: 
argparse.ArgumentParser) -> None:
+def _add_group_command(sub: GroupCommand, sub_proc: argparse.ArgumentParser) 
-> None:
     subcommands = sub.subcommands
     sub_subparsers = sub_proc.add_subparsers(dest="subcommand", 
metavar="COMMAND")
     sub_subparsers.required = True

Reply via email to