@@ -309,6 +309,53 @@ def _drafts_create(api, args):
309309 print (f"Created draft { draft .get ('id' )} : { title } " )
310310
311311
312+ def _drafts_update (api , args ):
313+ if not args .yes and (args .json_output or not sys .stdin .isatty ()):
314+ raise CLIUsageError ("--yes is required in non-interactive or JSON mode" )
315+
316+ markdown_file = Path (args .markdown_file )
317+ if not markdown_file .exists ():
318+ raise CLIUsageError (f"File not found: { markdown_file } " )
319+
320+ if not args .yes :
321+ action = "update" if not args .dry_run else "dry-run update"
322+ print (f"Ready to { action } draft { args .draft_id } from { markdown_file } " )
323+ print ("Substack nodes that are not supported by Markdown export/import" )
324+ print ("will cause the update to be refused to prevent data loss." )
325+ print ()
326+ try :
327+ response = input (f"Confirm { action } ? [y/N]: " )
328+ if response .lower () not in ["y" , "yes" ]:
329+ print ("Aborted." )
330+ return
331+ except EOFError as exc :
332+ raise CLIUsageError (
333+ f"Confirm { action } requires confirmation or --yes"
334+ ) from exc
335+
336+ markdown = markdown_file .read_text (encoding = "utf-8" )
337+
338+ result = api .update_draft_from_markdown (
339+ args .draft_id ,
340+ markdown ,
341+ subtitle = args .subtitle ,
342+ audience = args .audience ,
343+ write_comment_permissions = args .write_comment_permissions ,
344+ search_engine_title = args .search_engine_title ,
345+ search_engine_description = args .search_engine_description ,
346+ slug = args .slug ,
347+ draft_section_id = args .draft_section_id ,
348+ tags = args .tags ,
349+ dry_run = args .dry_run ,
350+ )
351+
352+ if args .json_output :
353+ _print_json (result )
354+ else :
355+ status = "Dry-run updated" if args .dry_run else "Updated"
356+ print (f"{ status } draft { args .draft_id } " )
357+
358+
312359def _drafts_export (api , args ):
313360 output_path = Path (args .output ) if args .output else None
314361 if output_path is not None and output_path .exists () and not args .force :
@@ -447,6 +494,23 @@ def _build_parser():
447494 drafts_create .add_argument ("--tag" , action = "append" , dest = "tags" , metavar = "TAG" )
448495 drafts_create .set_defaults (handler = _drafts_create )
449496
497+ drafts_update = draft_commands .add_parser (
498+ "update" , help = "Update a draft from a Markdown file."
499+ )
500+ drafts_update .add_argument ("draft_id" , type = int )
501+ drafts_update .add_argument ("markdown_file" , metavar = "MARKDOWN_FILE" )
502+ drafts_update .add_argument ("--subtitle" )
503+ drafts_update .add_argument ("--audience" )
504+ drafts_update .add_argument ("--write-comment-permissions" )
505+ drafts_update .add_argument ("--search-engine-title" )
506+ drafts_update .add_argument ("--search-engine-description" )
507+ drafts_update .add_argument ("--slug" )
508+ drafts_update .add_argument ("--draft-section-id" , type = int )
509+ drafts_update .add_argument ("--tag" , action = "append" , dest = "tags" , metavar = "TAG" )
510+ drafts_update .add_argument ("--dry-run" , action = "store_true" )
511+ drafts_update .add_argument ("--yes" , action = "store_true" )
512+ drafts_update .set_defaults (handler = _drafts_update )
513+
450514 drafts_export = draft_commands .add_parser (
451515 "export" , help = "Export a draft to Markdown without modifying it."
452516 )
0 commit comments