diff --git a/src/cmdforge/ui_urwid/__init__.py b/src/cmdforge/ui_urwid/__init__.py index eb16609..9e7d782 100644 --- a/src/cmdforge/ui_urwid/__init__.py +++ b/src/cmdforge/ui_urwid/__init__.py @@ -402,21 +402,48 @@ class CmdForgeUI: on_version ) + def _prompt_for_token(self, tool, version): + """Prompt user to enter their registry token.""" + from ..config import set_registry_token + + def on_info_ok(): + def on_token(token): + if token and token.strip(): + token = token.strip() + try: + set_registry_token(token) + self.message_box( + "Token Saved", + "Token configured successfully!", + callback=lambda: self._do_publish(tool, version) + ) + except Exception as e: + self.message_box("Error", f"Failed to save token: {e}") + + self.input_dialog( + "Enter Token", + "Paste your API token:", + "", + on_token + ) + + self.message_box( + "Authentication Required", + "To publish tools, you need an API token.\n\n" + "1. Go to cmdforge.brrd.tech/register\n" + "2. Log in and go to Dashboard > Tokens\n" + "3. Create a token and copy it\n" + "4. Paste it in the next dialog", + callback=on_info_ok + ) + def _do_publish(self, tool, version): """Perform the actual publish.""" from ..config import load_config, set_registry_token config = load_config() if not config.registry.token: - self.message_box( - "Authentication Required", - "No registry token configured.\n\n" - "To publish tools:\n" - "1. Register at cmdforge.brrd.tech/register\n" - "2. Log in and go to Dashboard > Tokens\n" - "3. Generate a token\n" - "4. Run: cmdforge config set-token " - ) + self._prompt_for_token(tool, version) return def do_publish():