fix: persist session state in CLI mode and handle quoted text in REPL

- Add auto-save via result_callback so --project flag triggers disk
  write after every mutating command, fixing broken consecutive
  operations in non-REPL mode.
- Switch REPL arg parsing from str.split() to shlex.split() so that
  quoted strings with spaces (e.g. --text "Summer Sale") are handled
  correctly.

Fixes #111
This commit is contained in:
sehawq
2026-03-20 13:18:20 +03:00
parent edf9755dd3
commit 08f6eb5e61

View File

@@ -18,6 +18,7 @@ Usage:
import sys
import os
import json
import shlex
import click
from typing import Optional
@@ -136,6 +137,15 @@ def cli(ctx, use_json, project_path):
ctx.invoke(repl, project_path=None)
@cli.result_callback()
def auto_save_on_cli(result, **kwargs):
"""Auto-save project after CLI commands when --project is specified."""
if not _repl_mode:
sess = get_session()
if sess.has_project() and sess._modified and sess.project_path:
proj_mod.save_project(sess.get_project(), sess.project_path)
# ── Project Commands ─────────────────────────────────────────────
@cli.group()
def project():
@@ -761,8 +771,11 @@ def repl(project_path):
skin.help(_repl_commands)
continue
# Parse and execute command
args = line.split()
# Parse and execute command (shlex handles quoted strings with spaces)
try:
args = shlex.split(line)
except ValueError:
args = line.split()
try:
cli.main(args, standalone_mode=False)
except SystemExit: