Skip to content

Commit a8e1e29

Browse files
Copilotkovidgoyal
andauthored
fix: save_as_session --save-only flag now works when path comes before the flag
The CLI parser (parse_cli_from_spec) stops at the first non-option argument (POSIX-style), so when users wrote `save_as_session /path --save-only`, the --save-only flag was placed in the leftover args and never parsed. Fix parse_save_as_options_spec_args to reorder args before parsing, ensuring all option flags appear before positional arguments. Also properly handles value-taking options (--match, --base-dir) that may appear after the path. Agent-Logs-Url: https://github.com/kovidgoyal/kitty/sessions/046a1de7-ad0d-46a5-8383-c06025d1d4eb Co-authored-by: kovidgoyal <1308621+kovidgoyal@users.noreply.github.com>
1 parent e7aa197 commit a8e1e29

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

kitty/session.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,29 @@ def save_as_session_part2(boss: BossType, opts: SaveAsSessionOptions, path: str)
709709
def parse_save_as_options_spec_args(args: list[str]) -> tuple[SaveAsSessionOptions, list[str]]:
710710
from kitty.cli import cached_parse_cmdline
711711
ans = SaveAsSessionOptions()
712-
leftover_args = cached_parse_cmdline(save_as_session_options(), args, ans)
712+
# The CLI parser stops at the first non-option argument (POSIX style). Reorder
713+
# args to put all option flags before positional args so that flags like
714+
# --save-only work correctly regardless of whether they appear before or after
715+
# the session file path (e.g. save_as_session /path --save-only).
716+
options: list[str] = []
717+
positional: list[str] = []
718+
# Options that take a value argument (not bool-set)
719+
value_options = frozenset(('--match', '--base-dir'))
720+
i = 0
721+
while i < len(args):
722+
a = args[i]
723+
if a == '--':
724+
positional.extend(args[i:])
725+
break
726+
if a.startswith('-'):
727+
options.append(a)
728+
if '=' not in a and a in value_options and i + 1 < len(args):
729+
i += 1
730+
options.append(args[i])
731+
else:
732+
positional.append(a)
733+
i += 1
734+
leftover_args = cached_parse_cmdline(save_as_session_options(), options + positional, ans)
713735
return ans, leftover_args
714736

715737

0 commit comments

Comments
 (0)