{"record":{"id":"dde11054da4b9308","repo":"google/python-fire","slug":"the-argument-argument-is-ambiguous-as-it-could","errorCode":null,"errorMessage":"The argument '{argument}' is ambiguous as it could refer to any of the following arguments: {matching_fn_args}","messagePattern":"The argument '(.+?)' is ambiguous as it could refer to any of the following arguments: (.+?)","errorType":"exception","errorClass":"FireError","httpStatus":null,"severity":"error","filePath":"fire/core.py","lineNumber":897,"sourceCode":"        value = None  # value will be set later on.\n\n      key = key.replace('-', '_')\n      is_bool_syntax = (not contains_equals and\n                        (index + 1 == len(args) or _IsFlag(args[index + 1])))\n\n      # Determine the keyword.\n      keyword = ''  # Indicates no valid keyword has been found yet.\n      if (key in fn_args\n          or (is_bool_syntax and key.startswith('no') and key[2:] in fn_args)\n          or fn_keywords):\n        keyword = key\n      elif len(key) == 1:\n        # This may be a shortcut flag.\n        matching_fn_args = [arg for arg in fn_args if arg[0] == key]\n        if len(matching_fn_args) == 1:\n          keyword = matching_fn_args[0]\n        elif len(matching_fn_args) > 1:\n          raise FireError(\n              f\"The argument '{argument}' is ambiguous as it could \"\n              f\"refer to any of the following arguments: {matching_fn_args}\"\n          )\n\n      # Determine the value.\n      if not keyword:\n        got_argument = False\n      elif contains_equals:\n        # Already got the value above.\n        got_argument = True\n      elif is_bool_syntax:\n        # There's no next arg or the next arg is a Flag, so we consider this\n        # flag to be a boolean.\n        got_argument = True\n        if keyword in fn_args:\n          value = 'True'\n        elif keyword.startswith('no'):\n          keyword = keyword[2:]","sourceCodeStart":879,"sourceCodeEnd":915,"githubUrl":"https://github.com/google/python-fire/blob/716bbc23d7eca949fdb682172283c8d18f742cb6/fire/core.py#L879-L915","documentation":"Fire supports single-letter shortcut flags when exactly one function argument starts with that letter. If multiple arguments share the same first letter, the shortcut is ambiguous and FireError listing all matching_fn_args is raised instead of guessing.","triggerScenarios":"Calling fn(host, hint) with -h=... (both start with 'h'); fn(port, path, protocol) with -p; using abbreviation flags on functions whose parameter names collide on the first character.","commonSituations":"Convenience one-letter flags colliding after adding new parameters; users assuming abbreviation works like argparse's prefix matching (it only matches first character and must be unique).","solutions":["Use the full flag name (--host=...) instead of the shortcut","Rename one of the colliding parameters","Add **kwargs or restructure args to avoid the first-letter collision"],"exampleFix":"// before\n$ mytool connect -h=example.com  # host, header both match 'h'\n// after\n$ mytool connect --host=example.com","handlingStrategy":"fallback","validationCode":"first_letters = [n[0] for n in inspect.signature(fn).parameters]\nif len(first_letters) != len(set(first_letters)):\n    print('warning: single-letter shortcut flags are ambiguous for this function')","typeGuard":null,"tryCatchPattern":"try:\n    fire.Fire(component)\nexcept fire.core.FireError as e:\n    if 'ambiguous' in str(e):\n        print('use full flag names instead of shortcuts', file=sys.stderr)\n        sys.exit(2)\n    raise","preventionTips":["Prefer full flag names in scripts over single-letter shortcuts","Keep parameter first letters unique within a callable","Do not rely on abbreviation behavior; it is not argparse-style prefix matching"],"tags":["python","cli","ambiguous-flag","shortcut"],"backgroundTag":"ambiguous-argument","analyzedSha":"716bbc23d7eca949fdb682172283c8d18f742cb6","analyzedAt":"2026-08-28T21:57:47.200Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}