1515from .tbrn import TBRN , TBRNType
1616from .utility import edit_input , error , get_dataset_client , get_gas
1717
18- _DRAFT_HINT = """
18+ _DRAFT_HINT = """{}
19+ {}
1920# Please enter the title for your draft.
2021# Lines starting with '#' will be ignored.
2122# And an empty draft title aborts the creation.
2223"""
2324
2425
2526def _implement_draft (
26- obj : Dict [str , str ], tbrn : str , is_list : bool , message : Tuple [str , ...]
27+ obj : Dict [str , str ], tbrn : str , is_list : bool , edit : bool , message : Tuple [str , ...]
2728) -> None :
2829 gas = get_gas (** obj )
2930 info = TBRN (tbrn = tbrn )
@@ -34,6 +35,8 @@ def _implement_draft(
3435
3536 if is_list :
3637 _list_drafts (dataset_client , info )
38+ elif edit :
39+ _edit_draft (dataset_client , info , message )
3740 else :
3841 _create_draft (dataset_client , info , message )
3942
@@ -83,7 +86,7 @@ def _echo_draft(
8386 try :
8487 branch = dataset_client .get_branch (branch_name )
8588 except ResourceNotExistError :
86- error ('The branch "{branch_name}" does not exist' )
89+ error (f 'The branch "{ branch_name } " does not exist' )
8790
8891 if branch .commit_id != ROOT_COMMIT_ID :
8992 click .echo (f"Branch: { branch_name } ({ branch .commit_id } )" )
@@ -95,3 +98,27 @@ def _echo_draft(
9598 click .echo (f"\n { title } \n " )
9699 if description :
97100 click .echo (f" { description } \n " )
101+
102+
103+ def _edit_draft (dataset_client : DatasetClientType , info : TBRN , message : Tuple [str , ...]) -> None :
104+ if not info .is_draft :
105+ error ("Draft number is needed when editing draft" )
106+
107+ if message :
108+ title , description = message [0 ], "\n " .join (message [1 :])
109+ else :
110+ draft = dataset_client .get_draft (draft_number = info .draft_number )
111+ title , description = edit_input (
112+ _DRAFT_HINT .format (
113+ draft .title , "\n " + draft .description + "\n " if draft .description else ""
114+ )
115+ )
116+
117+ if not title :
118+ error ("Aborting creating draft due to empty draft title" )
119+
120+ dataset_client .update_draft (
121+ draft_number = info .draft_number , title = title , description = description
122+ )
123+ click .echo (f"{ info .get_tbrn ()} update successful!" )
124+ _echo_draft (dataset_client , title , description , dataset_client .status .branch_name )
0 commit comments