@@ -771,7 +771,7 @@ module FormatCodeblocks = struct
771771            |  _  -> Ast_mapper. default_mapper.attribute mapper attr);
772772      }
773773    in 
774-     let  formatted_content, source  = 
774+     let  content  = 
775775      if  Filename. check_suffix path " .md" then 
776776        let  content = 
777777          let  ic =  open_in path in 
@@ -787,8 +787,8 @@ module FormatCodeblocks = struct
787787            ~markdown BlockStartLine:1  content
788788        in 
789789        if  hadCodeBlocks &&  formattedContents <>  content then 
790-           (formattedContents, content)
791-         else  (content, content)
790+           Ok   (formattedContents, content)
791+         else  Ok   (content, content)
792792      else  if  Filename. check_suffix path " .res" then 
793793        let  parser = 
794794          Res_driver. parsing_engine.parse_implementation ~for_printer: true 
@@ -799,10 +799,11 @@ module FormatCodeblocks = struct
799799        let  filename =  Filename. basename filename in 
800800        let  mapper =  makeMapper ~display Filename:filename in 
801801        let  astMapped =  mapper.structure mapper structure in 
802-         ( Res_printer. print_implementation
803-             ~width: Res_multi_printer. default_print_width astMapped ~comments ,
804-           source )
805-       else 
802+         Ok 
803+           ( Res_printer. print_implementation
804+               ~width: Res_multi_printer. default_print_width astMapped ~comments ,
805+             source )
806+       else  if  Filename. check_suffix path " .resi" then 
806807        let  parser = 
807808          Res_driver. parsing_engine.parse_interface ~for_printer: true 
808809        in 
@@ -811,23 +812,32 @@ module FormatCodeblocks = struct
811812        in 
812813        let  mapper =  makeMapper ~display Filename:filename in 
813814        let  astMapped =  mapper.signature mapper signature in 
814-         ( Res_printer. print_interface
815-             ~width: Res_multi_printer. default_print_width astMapped ~comments ,
816-           source )
815+         Ok 
816+           ( Res_printer. print_interface
817+               ~width: Res_multi_printer. default_print_width astMapped ~comments ,
818+             source )
819+       else 
820+         Error 
821+           (Printf. sprintf
822+              " File extension not supported. This command accepts .res, .resi, \
823+               and .md files"  )
817824    in 
818-     let  errors =  ! errors in 
819-     if  List. length errors >  0  then  (
820-       errors |>  List. rev |>  String. concat " \n " |>  print_endline;
821-       Error 
822-         (Printf. sprintf " %s: Error formatting docstrings." 
823-            (Filename. basename path)))
824-     else  if  formatted_content <>  source then  (
825-       match  outputMode with 
826-       |  `Stdout  -> Ok  formatted_content
827-       |  `File  ->
828-         let  oc =  open_out path in 
829-         Printf. fprintf oc " %s" 
830-         close_out oc;
831-         Ok  (Filename. basename path ^  " : formatted successfully" 
832-     else  Ok  (Filename. basename path ^  " : needed no formatting" 
825+     match  content with 
826+     |  Error  e  -> Error  e
827+     |  Ok  (formatted_content , source ) ->
828+       let  errors =  ! errors in 
829+       if  List. length errors >  0  then  (
830+         errors |>  List. rev |>  String. concat " \n " |>  print_endline;
831+         Error 
832+           (Printf. sprintf " %s: Error formatting docstrings." 
833+              (Filename. basename path)))
834+       else  if  formatted_content <>  source then  (
835+         match  outputMode with 
836+         |  `Stdout  -> Ok  formatted_content
837+         |  `File  ->
838+           let  oc =  open_out path in 
839+           Printf. fprintf oc " %s" 
840+           close_out oc;
841+           Ok  (Filename. basename path ^  " : formatted successfully" 
842+       else  Ok  (Filename. basename path ^  " : needed no formatting" 
833843end 
0 commit comments