@@ -22,6 +22,21 @@ fn usage() -> String {
2222 text
2323}
2424
25+ ///|
26+ fn write_generated_file (path : String , content : String ) -> Unit {
27+ let write_ok = try @fs .write_string_to_file (path , content ) catch {
28+ err => {
29+ println ("Error: failed to write \{ path } : \{ err } " )
30+ false
31+ }
32+ } noraise {
33+ _ => true
34+ }
35+ if write_ok {
36+ println ("generated \{ path } " )
37+ }
38+ }
39+
2540///|
2641fn normalized_args (args : Array [String ]) -> Array [String ] {
2742 if args .length () == 0 {
@@ -100,13 +115,7 @@ fn ensure_dune_file(project_root : String) -> Unit {
100115 #| (deps
101116 #| (source_tree .)))
102117 #|
103- @fs .write_string_to_file (dune_path , dune_content ) catch {
104- err => {
105- println ("Error: failed to write \{ dune_path } : \{ err } " )
106- return
107- }
108- }
109- println ("generated \{ dune_path } " )
118+ write_generated_file (dune_path , dune_content )
110119}
111120
112121///|
@@ -116,6 +125,7 @@ fn run(args : Array[String]) -> Unit {
116125 Error (msg ) => {
117126 println ("Error: \{ msg } " )
118127 println (usage ())
128+ @sys .exit (1 )
119129 }
120130 Parsed (config ) => {
121131 ensure_dune_file (config .project_root)
@@ -126,10 +136,7 @@ fn run(args : Array[String]) -> Unit {
126136 let files = render_cram_files (result )
127137 for file in files {
128138 let path = @path .Path ::join (config .project_root, file .name).to_string ()
129- @fs .write_string_to_file (path , file .content) catch {
130- err => println ("Error: failed to write \{ path } : \{ err } " )
131- }
132- println ("generated \{ path } " )
139+ write_generated_file (path , file .content)
133140 }
134141 }
135142 }
0 commit comments