From 0216d1d77aa83eb1d1be1d3064b6c8e4130a1ded Mon Sep 17 00:00:00 2001 From: rob Date: Fri, 16 Jan 2026 06:55:30 -0400 Subject: [PATCH] Add disconnect command and fix GUI connection status refresh - Add `cmdforge config disconnect` command to clear registry token - Fix GUI connection status label not updating after connect - Store status as instance variable instead of local - Add _update_connection_status() method - Call update after connect dialog completes Co-Authored-By: Claude Opus 4.5 --- src/cmdforge/cli/__init__.py | 4 ++++ src/cmdforge/cli/config_commands.py | 18 ++++++++++++++++++ src/cmdforge/gui/pages/tools_page.py | 22 ++++++++++++++-------- 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/cmdforge/cli/__init__.py b/src/cmdforge/cli/__init__.py index 4abcb1c..07ff350 100644 --- a/src/cmdforge/cli/__init__.py +++ b/src/cmdforge/cli/__init__.py @@ -255,6 +255,10 @@ def main(): p_cfg_connect.add_argument("username", help="Your CmdForge username") p_cfg_connect.set_defaults(func=cmd_config) + # config disconnect + p_cfg_disconnect = config_sub.add_parser("disconnect", help="Disconnect from registry (clear token)") + p_cfg_disconnect.set_defaults(func=cmd_config) + # Default for config with no subcommand p_config.set_defaults(func=lambda args: cmd_config(args) if args.config_cmd else (setattr(args, 'config_cmd', 'show') or cmd_config(args))) diff --git a/src/cmdforge/cli/config_commands.py b/src/cmdforge/cli/config_commands.py index ec0300e..7f502e4 100644 --- a/src/cmdforge/cli/config_commands.py +++ b/src/cmdforge/cli/config_commands.py @@ -17,10 +17,13 @@ def cmd_config(args): return _cmd_config_set(args) elif args.config_cmd == "connect": return _cmd_config_connect(args) + elif args.config_cmd == "disconnect": + return _cmd_config_disconnect(args) else: print("Config commands:") print(" show Show current configuration") print(" connect Connect this app to your CmdForge account") + print(" disconnect Disconnect from registry (clear token)") print(" set-token Set registry authentication token") print(" set Set a configuration value") return 0 @@ -165,3 +168,18 @@ def _cmd_config_connect(args): except KeyboardInterrupt: print("\n\nConnection cancelled.") return 1 + + +def _cmd_config_disconnect(args): + """Disconnect from registry by clearing the token.""" + config = load_config() + + if not config.registry.token: + print("Not connected to registry (no token set).") + return 0 + + # Clear the token + set_registry_token(None) + print("Disconnected from registry.") + print("Token has been cleared from local configuration.") + return 0 diff --git a/src/cmdforge/gui/pages/tools_page.py b/src/cmdforge/gui/pages/tools_page.py index 3736c9c..e3b1ffd 100644 --- a/src/cmdforge/gui/pages/tools_page.py +++ b/src/cmdforge/gui/pages/tools_page.py @@ -83,14 +83,9 @@ class ToolsPage(QWidget): header_layout.addStretch() # Connection status - config = load_config() - if config.registry.token: - status = QLabel("Connected to Registry") - status.setStyleSheet("color: #38a169; font-weight: 500;") - else: - status = QLabel("Not connected") - status.setStyleSheet("color: #718096;") - header_layout.addWidget(status) + self.connection_status = QLabel() + self._update_connection_status() + header_layout.addWidget(self.connection_status) layout.addWidget(header) @@ -174,6 +169,16 @@ class ToolsPage(QWidget): layout.addWidget(buttons) + def _update_connection_status(self): + """Update the connection status label.""" + config = load_config() + if config.registry.token: + self.connection_status.setText("Connected to Registry") + self.connection_status.setStyleSheet("color: #38a169; font-weight: 500;") + else: + self.connection_status.setText("Not connected") + self.connection_status.setStyleSheet("color: #718096;") + def refresh(self): """Refresh the tool list.""" self.tool_tree.clear() @@ -392,6 +397,7 @@ class ToolsPage(QWidget): dialog = ConnectDialog(self) if dialog.exec(): self.refresh() + self._update_connection_status() self.main_window.show_status("Connected to registry") # Recreate publish button self.btn_publish.setText("Publish")