Skip to content

Make positional parameters as a destionation paramater for auto-generated commands #60142

Open

Description

@bugraoz93

Description

What
We need to make adjustments in this file.

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

Activity

  1. changed the title [-]Make positional parameters as a destionation paramater[/-] [+]Make positional parameters as a destionation paramater for auto-generated commands[/+] on Jan 5, 2026
  2. douglasmnegri commented on Jan 5, 2026

    @douglasmnegri

    Hi! I’d be happy to work on this issue. Could you assign it to me?

  3. jroachgolf84 commented on Jan 5, 2026

    @jroachgolf84
    Collaborator

    @douglasmnegri, please feel free to open a PR for this issue!

  4. abhijeets25012-tech commented on Jan 5, 2026

    @abhijeets25012-tech
    Contributor

    I would also like to contribute

  5. jroachgolf84 commented on Jan 6, 2026

    @jroachgolf84
    Collaborator

    @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 :)

  6. Fury0508 commented on Jan 6, 2026

    @Fury0508
    Contributor

    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

  7. douglasmnegri commented on Jan 6, 2026

    @douglasmnegri

    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!

  8. Fury0508 commented on Jan 6, 2026

    @Fury0508
    Contributor

    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!

  9. potiuk commented on Mar 2, 2026

    @potiuk
    Member

    @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.

  10. shivaam commented on Apr 6, 2026

    @shivaam
    Contributor

    I'm working on this issue. Will submit a PR shortly.

  11. shivaam commented on Apr 6, 2026

    @shivaam
    Contributor

    Quick clarifying question on scope — should all required non-boolean params become positional, even for commands with many required args?

    For example, xcom add has 5 required params (dag_id, dag_run_id, task_id, key, value). Making all of them positional means:

    airflowctl xcom add example_dag "manual__2025-01-01" runme_0 my_key '{"value": 1}'

    vs keeping some as flags for clarity:

    airflowctl xcom add example_dag "manual__2025-01-01" --task-id=runme_0 --key=my_key --value='{"value": 1}'

    Similarly, dagrun list has state and limit as required primitives — should those be positional too?

    Happy to go either way, just want to confirm the intent before submitting the PR.

  12. shivaam commented on Apr 6, 2026

    @shivaam
    Contributor

    Opened a PR: #64812

  13. bugraoz93 commented on Apr 7, 2026

    @bugraoz93
    ContributorAuthor

    Quick clarifying question on scope — should all required non-boolean params become positional, even for commands with many required args?

    For example, xcom add has 5 required params (dag_id, dag_run_id, task_id, key, value). Making all of them positional means:

    airflowctl xcom add example_dag "manual__2025-01-01" runme_0 my_key '{"value": 1}'
    vs keeping some as flags for clarity:

    airflowctl xcom add example_dag "manual__2025-01-01" --task-id=runme_0 --key=my_key --value='{"value": 1}'
    Similarly, dagrun list has state and limit as required primitives — should those be positional too?

    Happy to go either way, just want to confirm the intent before submitting the PR.

    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>

  14. shivaam commented on Apr 8, 2026

    @shivaam
    Contributor

    Thanks for the feedback @bugraoz93!

    I looked into supporting both positional and --flag styles 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 a nargs='*' catch-all for bare values, and using parse_intermixed_args to 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, and required=True for those params — we'd essentially reimplement positional argument handling ourselves on top of argparse.

    Options:

    1. 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.

    2. 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:

      # both work:
      airflowctl xcom add my_dag my_task my_key
      airflowctl xcom add --dag-id=my_dag --task-id=my_task --key=my_key
      
      # but not mixed:
      airflowctl xcom add my_dag --task-id=my_task my_key  # would fail

      No argparse hacks needed (both parsers are standard), but doubles the parser setup and mixed usage isn't supported.

    3. Cap positional count — first 1-2 required params (like dag_id) are positional, rest stay as --flag required=True. Common CLI pattern (like git 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_args workaround (and why I didn't recommend it)

    The idea is to register all required params as --flags only (no argparse positionals), add a single nargs='*' argument to collect any bare values, then map those bare values into whichever flag slots the user didn't fill:

    PARAM_ORDER = ['dag_id', 'task_id', 'key']
    
    parser.add_argument('--dag-id', dest='dag_id', default=None)
    parser.add_argument('--task-id', dest='task_id', default=None)
    parser.add_argument('--key', default=None)
    parser.add_argument('positionals', nargs='*')
    
    args = parser.parse_intermixed_args(argv)
    
    # map bare values into unfilled flag slots, left to right
    unfilled = [d for d in PARAM_ORDER if getattr(args, d) is None]
    for i, val in enumerate(args.positionals):
        setattr(args, unfilled[i], val)

    parse_intermixed_args (Python 3.7+) allows flags and bare values to be freely interspersed, so all of these would work:

    airflowctl xcom add d t k                          # all positional
    airflowctl xcom add --dag-id=d --task-id=t --key=k # all flags
    airflowctl xcom add d --task-id=t k                 # mixed
    airflowctl xcom add --task-id=t my_dag my_key       # gap-filling

    The problem is what we lose:

    • Validation — can't use required=True on flags (argparse would reject positional-only usage), so we validate manually after gap-filling
    • Type checking — type=int, choices=[...] etc. don't apply to the nargs='*' catch-all, so we type-check manually
    • Help output — shows [positionals ...] instead of named params like DAG_ID TASK_ID, and no indication which flags are required vs optional
    • argparse.REMAINDER and mutually exclusive groups with positionals — unsupported with parse_intermixed_args

    This effectively means using argparse for flag parsing only and reimplementing positional handling on top of it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions