(self, args: str, context: CommandContext)
| 159 | """ |
| 160 | |
| 161 | async def run(self, args: str, context: CommandContext) -> InteractiveOutcome: |
| 162 | parsed = parse_export_args(args) |
| 163 | if parsed.error: |
| 164 | return InteractiveOutcome(message=parsed.error, display="system") |
| 165 | |
| 166 | # Resolve the conversation with the existing no-conversation idiom |
| 167 | # (builtins.py:381). Covers a None conversation too — hasattr(None, …) |
| 168 | # is False — so SDK/listing callers degrade gracefully instead of |
| 169 | # raising. |
| 170 | conversation = context.conversation |
| 171 | if not hasattr(conversation, "messages"): |
| 172 | return InteractiveOutcome( |
| 173 | message="No conversation to export.", display="system" |
| 174 | ) |
| 175 | messages = conversation.messages |
| 176 | |
| 177 | # Format: --format flag > filename extension > text default |
| 178 | # (export.tsx:60-63). |
| 179 | fmt: Optional[ExportFormat] = parsed.format |
| 180 | if fmt is None and parsed.filename: |
| 181 | fmt = infer_export_format_from_filename(parsed.filename) |
| 182 | if fmt is None: |
| 183 | fmt = "text" |
| 184 | |
| 185 | cwd = str(context.cwd or context.workspace_root) |
| 186 | |
| 187 | # --- Args path: headless render + write, never touches ctx.ui. --- |
| 188 | if parsed.filename: |
| 189 | # TS preserves a ``.markdown`` extension only when the user did not |
| 190 | # pass an explicit --format flag (export.tsx:69-71). |
| 191 | return self._write_export( |
| 192 | messages, |
| 193 | fmt, |
| 194 | parsed.filename, |
| 195 | cwd, |
| 196 | preserve_markdown_extension=parsed.format is None, |
| 197 | ) |
| 198 | |
| 199 | # --- Wizard path: select format, then prompt for filename. --- |
| 200 | picked = await context.ui.select( |
| 201 | "Select export format:", _FORMAT_OPTIONS, current=fmt |
| 202 | ) |
| 203 | if picked is None: |
| 204 | return InteractiveOutcome.skip() # Esc -> cancel the whole export. |
| 205 | chosen: ExportFormat = picked # type: ignore[assignment] |
| 206 | |
| 207 | # Default filename carries the chosen format's extension (ExportDialog |
| 208 | # recomputes it when the format changes, ExportDialog.tsx:37-66). |
| 209 | default_name = ensure_export_filename_extension( |
| 210 | _default_filename(messages), chosen, preserve_markdown_extension=True |
| 211 | ) |
| 212 | name = await context.ui.prompt_text("Enter filename:", default=default_name) |
| 213 | if name is None: |
| 214 | return InteractiveOutcome.skip() |
| 215 | |
| 216 | # The wizard submit always preserves a ``.markdown`` extension |
| 217 | # (ExportDialog.tsx:99-101). |
| 218 | return self._write_export( |
nothing calls this directly
no test coverage detected