{"record":{"id":"66f833b2e5316a0d","repo":"kovidgoyal/kitty","slug":"must-specify-exactly-command-args-args-count-arg","errorCode":null,"errorMessage":"Must specify exactly {command.args.args_count} argument(s) for {command.name}","messagePattern":"Must specify exactly (.+?) argument\\(s\\) for (.+?)","errorType":"console","errorClass":"SystemExit","httpStatus":null,"severity":"error","filePath":"kitty/rc/base.py","lineNumber":453,"sourceCode":"        pass\n\n    def handle_streamed_data(self, data: bytes, payload_get: PayloadGetType) -> BytesIO | AsyncResponse:\n        stream_id = payload_get('stream_id')\n        if not stream_id or not isinstance(stream_id, str):\n            raise StreamError('No stream_id in rc payload')\n        return self.stream_in_flight.handle_data(stream_id, data)\n\n\ndef cli_params_for(command: RemoteCommand) -> tuple[Callable[[], str], str, str, str]:\n    return (command.options_spec or '\\n').format, command.args.spec, command.desc, f'kitten @ {command.name}'\n\n\ndef parse_subcommand_cli(command: RemoteCommand, args: ArgsType) -> tuple[Any, ArgsType]:\n    opts, items = parse_args(args[1:], *cli_params_for(command), result_class=command.options_class)\n    if command.args.args_count is not None and command.args.args_count != len(items):\n        if command.args.args_count == 0:\n            raise SystemExit(f'Unknown extra argument(s) supplied to {command.name}')\n        raise SystemExit(f'Must specify exactly {command.args.args_count} argument(s) for {command.name}')\n    return opts, items\n\n\ndef display_subcommand_help(func: RemoteCommand) -> None:\n    with suppress(SystemExit):\n        parse_args(['--help'], (func.options_spec or '\\n').format, func.args.spec, func.desc, func.name)\n\n\ndef command_for_name(cmd_name: str) -> RemoteCommand:\n    from importlib import import_module\n\n    cmd_name = cmd_name.replace('-', '_')\n    try:\n        m = import_module(f'kitty.rc.{cmd_name}')\n    except ImportError:\n        raise KeyError(f'Unknown kitty remote control command: {cmd_name}')\n    return cast(RemoteCommand, getattr(m, cmd_name))\n","sourceCodeStart":435,"sourceCodeEnd":471,"githubUrl":"https://github.com/kovidgoyal/kitty/blob/6d5d0c440603ad9bdf6dcd599f73f6dde21acb44/kitty/rc/base.py#L435-L471","documentation":"SystemExit raised by kitty's remote-control subcommand CLI parser when a command that requires a fixed number of positional arguments receives a different count. args_count declares the exact arity (e.g. 1 for @ send-text's text, 2 for title+value commands); a mismatch aborts before execution.","triggerScenarios":"Running e.g. 'kitten @ set-window-title' with no title (needs 1), 'kitten @ send-text' with no text, or any rc subcommand with fewer/more positional args than declared in its args.spec.","commonSituations":"Scripts where the interpolated variable is empty, forgotten arguments when converting one-liners, or shell quoting mistakes that merge/split arguments.","solutions":["Run 'kitten @ <command> --help' to see the expected positional arguments and supply exactly that many","Fix empty shell variables: use defaults or guard before invoking, e.g. [ -n \"$title\" ] && kitten @ set-window-title \"$title\"","Quote arguments so multi-word values count as one positional"],"exampleFix":"# before\nkitten @ set-window-title\n\n# after\nkitten @ set-window-title \"my title\"","handlingStrategy":"validation","validationCode":"# example for @ set-window-title which takes exactly 1 positional\ntitle = os.environ.get('TITLE', '').strip()\nif not title:\n    sys.exit('TITLE required')\nassert len([title]) == 1\nsubprocess.run(['kitten', '@', 'set-window-title', title])","typeGuard":"def has_exact_args(items: list[str], n: int) -> bool:\n    return len(items) == n","tryCatchPattern":"res = subprocess.run(argv, capture_output=True, text=True)\nif 'Must specify exactly' in res.stderr:\n    print_usage_and_expected_count(cmd); sys.exit(2)","preventionTips":["Guard against empty interpolated variables before building kitty @ commands","Read each subcommand's --help once and encode its arity in your script's command table"],"tags":["kitty","remote-control","cli","arity"],"backgroundTag":"wrong-argument-count","analyzedSha":"6d5d0c440603ad9bdf6dcd599f73f6dde21acb44","analyzedAt":"2026-08-27T14:20:20.142Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}