[OCaml] Mobile-friendly clone of cgit.
feat Refuse to overwrite an existing file
Add --output for the destination and --force to overwrite, settling the TODO about silent clobbering.
bin/config_writer.ml
@@ -1,11 +1,29 @@
1
1
(** The [ogit-write-config] executable.
2
2
3
Removed:
Writes a configuration file containing every variable at its default value,
4
Removed:
to the same location {!Ogit.Config.load} would read from. Intended for
5
Removed:
bootstrapping a new deployment.
3
Added:
Writes a configuration file containing every variable at its default value.
4
Added:
Intended for bootstrapping a new deployment. The destination defaults to
5
Added:
the path {!Ogit.Config.load} reads from; an existing file is never
6
Added:
overwritten unless [--force] is given. *)
6
7
7
Removed:
TODO: this overwrites the target file without warning and takes no
8
Removed:
arguments. Add a destination argument and refuse to clobber an existing
9
Removed:
file. *)
8
Added:
let usage = "Usage: ogit-write-config [--output <path>] [--force]"
10
9
11
Removed:
let () = Ogit.Config.(default |> to_table |> write_file)
10
Added:
let () =
11
Added:
let output = ref None in
12
Added:
let force = ref false in
13
Added:
let speclist =
14
Added:
[
15
Added:
( "--output",
16
Added:
Arg.String (fun path -> output := Some path),
17
Added:
"<path> Destination file (defaults to the standard configuration path)"
18
Added:
);
19
Added:
("--force", Arg.Set force, " Overwrite the destination when it exists");
20
Added:
]
21
Added:
in
22
Added:
Arg.parse speclist (fun _ -> ()) usage;
23
Added:
let file =
24
Added:
Option.value !output ~default:(Ogit.Config.locate_config_file ())
25
Added:
in
26
Added:
if (not !force) && Sys.file_exists file then (
27
Added:
Printf.eprintf "refusing to overwrite %s (use --force)\n" file;
28
Added:
exit 1)
29
Added:
else Ogit.Config.(default |> to_table |> write_file ~file)