Repository navigation
Open
Labels
Description
Description
What
We need to make adjustments in this file.
airflow/airflow-ctl/src/airflowctl/ctl/cli_config.py
Lines 499 to 584 in a4f3417
| def _create_arg( | |
| arg_flags: tuple, | |
| arg_type: type | Callable, | |
| arg_help: str, | |
| arg_action: argparse.BooleanOptionalAction | None, | |
| arg_dest: str | None = None, | |
| arg_default: Any | None = None, | |
| ) -> Arg: | |
| return Arg( | |
| flags=arg_flags, | |
| type=arg_type, | |
| dest=arg_dest, | |
| help=arg_help, | |
| default=arg_default, | |
| action=arg_action, | |
| ) | |
| def _create_arg_for_non_primitive_type( | |
| self, | |
| parameter_type: str, | |
| parameter_key: str, | |
| ) -> list[Arg]: | |
| """Create Arg for non-primitive type Pydantic.""" | |
| parameter_type_map = getattr(generated_datamodels, parameter_type) | |
| commands = [] | |
| if parameter_type_map not in self.datamodels_extended_map.keys(): | |
| self.datamodels_extended_map[parameter_type] = [] | |
| for field, field_type in parameter_type_map.model_fields.items(): | |
| if field in self.excluded_parameters: | |
| continue | |
| self.datamodels_extended_map[parameter_type].append(field) | |
| if type(field_type.annotation) is type: | |
| commands.append( | |
| self._create_arg( | |
| arg_flags=("--" + self._sanitize_arg_parameter_key(field),), | |
| arg_type=self._python_type_from_string(field_type.annotation), | |
| arg_action=argparse.BooleanOptionalAction if field_type.annotation is bool else None, # type: ignore | |
| arg_help=f"{field} for {parameter_key} operation", | |
| arg_default=False if field_type.annotation is bool else None, | |
| ) | |
| ) | |
| else: | |
| try: | |
| annotation = field_type.annotation.__args__[0] | |
| except AttributeError: | |
| annotation = field_type.annotation | |
| commands.append( | |
| self._create_arg( | |
| arg_flags=("--" + self._sanitize_arg_parameter_key(field),), | |
| arg_type=self._python_type_from_string(annotation), | |
| arg_action=argparse.BooleanOptionalAction if annotation is bool else None, # type: ignore | |
| arg_help=f"{field} for {parameter_key} operation", | |
| arg_default=False if annotation is bool else None, | |
| ) | |
| ) | |
| return commands | |
| def _create_args_map_from_operation(self): | |
| """Create Arg from Operation Method checking for parameters and return types.""" | |
| for operation in self.operations: | |
| args = [] | |
| for parameter in operation.get("parameters"): | |
| for parameter_key, parameter_type in parameter.items(): | |
| if self._is_primitive_type(type_name=parameter_type): | |
| is_bool = parameter_type == "bool" | |
| args.append( | |
| self._create_arg( | |
| arg_flags=("--" + self._sanitize_arg_parameter_key(parameter_key),), | |
| arg_type=self._python_type_from_string(parameter_type), | |
| arg_action=argparse.BooleanOptionalAction if is_bool else None, | |
| arg_help=f"{parameter_key} for {operation.get('name')} operation in {operation.get('parent').name}", | |
| arg_default=False if is_bool else None, | |
| ) | |
| ) | |
| else: | |
| args.extend( | |
| self._create_arg_for_non_primitive_type( | |
| parameter_type=parameter_type, parameter_key=parameter_key | |
| ) | |
| ) | |
| if any(operation.get("name").startswith(cmd) for cmd in self.output_command_list): | |
| args.extend([ARG_OUTPUT, ARG_AUTH_ENVIRONMENT]) | |
| self.args_map[(operation.get("name"), operation.get("parent").name)] = args |
airflowctl will understand whether the parameter is nullable. If it is not nullable, we should add as a destination parameter, and if it is nullable, it will be positional.
Example:
from
airflow connections create --connection-id="test" --conn-type="test" ...
to
airflow connections create test test ...
Are you willing to submit a PR?
- Yes I am willing to submit a PR!
Code of Conduct
- I agree to follow this project's Code of Conduct
Reacted by Pratiksha Badheka
Activity
[-]Make positional parameters as a destionation paramater[/-][+]Make positional parameters as a destionation paramater for auto-generated commands[/+]douglasmnegri commentedon Jan 5, 2026
Hi! I’d be happy to work on this issue. Could you assign it to me?
jroachgolf84 commentedon Jan 5, 2026
@douglasmnegri, please feel free to open a PR for this issue!
abhijeets25012-tech commentedon Jan 5, 2026
I would also like to contribute
jroachgolf84 commentedon Jan 6, 2026
@abhijeets25012-tech, please feel free to check out "Issues" to find another issue that you'd like to contribute to. @douglasmnegri is going to take a spin at this one :)
Fury0508 commentedon Jan 6, 2026
Hi @douglasmnegri and @jroachgolf64,
I apologise, I started working on this issue before realising @douglasmnegri was assigned yesterday. This is my first open source contribution and I didn't check assignments first.
I've completed an implementation and am submitting a PR to share the work, but I want to be clear: if @douglasmnegri is already working on this, I will immediately close my PR. I'm not trying to compete or step on anyone's work.
I've learned to check for assignments before starting work going forward. Thanks for your patience with a first-time contributor!
PR submitted: #60193
douglasmnegri commentedon Jan 6, 2026
No problem at all @Fury0508 ! I was still setting up my environment to run tests and start developing the code, so nothing concrete yet.
This is my first issue as well, so feel free to keep going with it. I'll tackle the next one!
Thanks for the heads-up and good luck with the PR!
Fury0508 commentedon Jan 6, 2026
Thank you so much @douglasmnegri! I really appreciate your understanding. This is my first contribution too, so I was nervous about the situation.
Best of luck with your next issue! If you ever want to collaborate or have questions, feel free to reach out. 🙂
@jroachgolf64 @bugraoz93 - PR #60193 is now ready for review!
Implement positional parameters for required CLI args in airflowctl
potiuk commentedon Mar 2, 2026
@douglasmnegri We are unassigning you from this issue as part of our updated assignment policy.
This is not meant to discourage your contribution — quite the opposite! You are still very welcome to work on this issue and submit a PR for it. Simply comment that you are working on it and open a PR when ready.
We found that formal assignments were not working well, as they often prevented others from contributing when the assignee was not actively working on the issue.
shivaam commentedon Apr 6, 2026
I'm working on this issue. Will submit a PR shortly.
shivaam commentedon Apr 6, 2026
Quick clarifying question on scope — should all required non-boolean params become positional, even for commands with many required args?
For example,
xcom addhas 5 required params (dag_id,dag_run_id,task_id,key,value). Making all of them positional means:vs keeping some as flags for clarity:
Similarly,
dagrun listhasstateandlimitas required primitives — should those be positional too?Happy to go either way, just want to confirm the intent before submitting the PR.
shivaam commentedon Apr 6, 2026
Opened a PR: #64812
bugraoz93 commentedon Apr 7, 2026
We should be able to use arguments in both styles, as optional flags
--param-name <value>and as positional arguments . Mandatory fields can be either positional arguments or optional flags with required=True. Any CLI can have both positional and optional argument types for Pydantic required fields. For not required Pydantic fields, we should leave them optional as--param-name <value>shivaam commentedon Apr 8, 2026
Thanks for the feedback @bugraoz93!
I looked into supporting both positional and
--flagstyles for required params. Unfortunately argparse doesn't natively support this — a parameter is either positional (dag_id) or a flag (--dag-id), never both.Why it's not straightforward:
The closest workaround is registering all params as
--flags, adding anargs='*'catch-all for bare values, and usingparse_intermixed_argsto map positionals into unfilled flag slots after parsing. More about this at the bottom of this comment. But this means we lose argparse's built-in validation, type checking, help formatting, andrequired=Truefor those params — we'd essentially reimplement positional argument handling ourselves on top of argparse.Options:
Keep it positional for required params (current PR) — the simplest, most conventional choice. Required params are positional, optional params are flags. All argparse features work, clean help output.
Two-pass parsing — maintain two parsers per command: one with required params as positional, one with them as
--flags required=True. Try positional first, fall back to flags. Users can use either style, just not mixed in the same invocation:No argparse hacks needed (both parsers are standard), but doubles the parser setup and mixed usage isn't supported.
Cap positional count — first 1-2 required params (like
dag_id) are positional, rest stay as--flag required=True. Common CLI pattern (likegit checkout <branch> --force). No hacks, all argparse features work.I'd recommend Option 1 for simplicity. Happy to go with whichever you prefer!
Details on the
parse_intermixed_argsworkaround (and why I didn't recommend it)The idea is to register all required params as
--flagsonly (no argparse positionals), add a singlenargs='*'argument to collect any bare values, then map those bare values into whichever flag slots the user didn't fill:parse_intermixed_args(Python 3.7+) allows flags and bare values to be freely interspersed, so all of these would work:The problem is what we lose:
required=Trueon flags (argparse would reject positional-only usage), so we validate manually after gap-fillingtype=int,choices=[...]etc. don't apply to thenargs='*'catch-all, so we type-check manually[positionals ...]instead of named params likeDAG_ID TASK_ID, and no indication which flags are required vs optionalargparse.REMAINDERand mutually exclusive groups with positionals — unsupported withparse_intermixed_argsThis effectively means using argparse for flag parsing only and reimplementing positional handling on top of it.
Implement positional parameters for required CLI args in airflowctl