k
This commit is contained in:
@@ -181,7 +181,12 @@ def _strip_value_quotes(value: str) -> str:
|
||||
|
||||
|
||||
def _run(piped_result: Any, args: List[str], config: Dict[str, Any]) -> int:
|
||||
current_config = load_config()
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
# Load from workspace root, not SYS directory
|
||||
workspace_root = Path(__file__).resolve().parent.parent
|
||||
current_config = load_config(config_dir=workspace_root)
|
||||
|
||||
selection_key = _get_selected_config_key()
|
||||
value_from_args = _extract_value_arg(args) if selection_key else None
|
||||
@@ -197,7 +202,7 @@ def _run(piped_result: Any, args: List[str], config: Dict[str, Any]) -> int:
|
||||
new_value = _strip_value_quotes(new_value)
|
||||
try:
|
||||
set_nested_config(current_config, selection_key, new_value)
|
||||
save_config(current_config)
|
||||
save_config(current_config, config_dir=workspace_root)
|
||||
print(f"Updated '{selection_key}' to '{new_value}'")
|
||||
return 0
|
||||
except Exception as exc:
|
||||
@@ -205,6 +210,47 @@ def _run(piped_result: Any, args: List[str], config: Dict[str, Any]) -> int:
|
||||
return 1
|
||||
|
||||
if not args:
|
||||
# Check if we're in an interactive terminal and can launch a Textual modal
|
||||
if sys.stdin.isatty() and not piped_result:
|
||||
try:
|
||||
from textual.app import App, ComposeResult
|
||||
from TUI.modalscreen.config_modal import ConfigModal
|
||||
|
||||
class ConfigApp(App):
|
||||
def on_mount(self) -> None:
|
||||
self.title = "Config Editor"
|
||||
# We push the modal screen. It will sit on top of the main (blank) screen.
|
||||
# Using a callback to exit the app when the modal is dismissed.
|
||||
self.push_screen(ConfigModal(), callback=self.exit_on_close)
|
||||
|
||||
def exit_on_close(self, result: Any = None) -> None:
|
||||
self.exit()
|
||||
|
||||
with ctx.suspend_live_progress():
|
||||
app = ConfigApp()
|
||||
app.run()
|
||||
|
||||
# After modal exits, show the new status table if possible
|
||||
try:
|
||||
from cmdlet._shared import SharedArgs
|
||||
from cmdnat.status import CMDLET as STATUS_CMDLET
|
||||
# We reload the config one more time because it might have changed on disk
|
||||
fresh_config = load_config(config_dir=workspace_root)
|
||||
|
||||
# Force refresh of shared caches (especially stores)
|
||||
SharedArgs._refresh_store_choices_cache(fresh_config)
|
||||
# Update the global SharedArgs choices so cmdlets pick up new stores
|
||||
SharedArgs.STORE.choices = SharedArgs.get_store_choices(fresh_config, force=True)
|
||||
|
||||
return STATUS_CMDLET.exec(None, [], fresh_config)
|
||||
except Exception:
|
||||
pass
|
||||
return 0
|
||||
except Exception as exc:
|
||||
# Fall back to table display if Textual modal fails
|
||||
print(f"Note: Could not launch interactive editor ({exc}). Showing configuration table:")
|
||||
return _show_config_table(current_config)
|
||||
|
||||
return _show_config_table(current_config)
|
||||
|
||||
key = args[0]
|
||||
@@ -215,7 +261,7 @@ def _run(piped_result: Any, args: List[str], config: Dict[str, Any]) -> int:
|
||||
value = _strip_value_quotes(" ".join(args[1:]))
|
||||
try:
|
||||
set_nested_config(current_config, key, value)
|
||||
save_config(current_config)
|
||||
save_config(current_config, config_dir=workspace_root)
|
||||
print(f"Updated '{key}' to '{value}'")
|
||||
return 0
|
||||
except Exception as exc:
|
||||
|
||||
Reference in New Issue
Block a user