Installs pre-commit hooks for OCaml projects that run dune fmt automatically
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

precommit: add -C option to change directory before running

Add -C DIR option to all commands (init, status, check, fix) to change
to a directory before running, similar to git's -C option.

+34 -12
+34 -12
bin/main.ml
··· 19 19 20 20 (* {1 Common arguments} *) 21 21 22 + let chdir = 23 + let doc = "Change to $(docv) before running. Equivalent to cd $(docv)." in 24 + Arg.(value & opt (some dir) None & info [ "C" ] ~docv:"DIR" ~doc) 25 + 22 26 let dirs = 23 27 let doc = 24 28 "Root directories to scan for git projects. Defaults to the current \ ··· 97 101 Log.info (fun m -> 98 102 m "Processed %d director%s" !count (if !count = 1 then "y" else "ies")) 99 103 100 - let init dry_run force hooks dirs = 104 + let init chdir dry_run force hooks dirs = 101 105 Eio_main.run @@ fun env -> 102 - let fs = Eio.Stdenv.cwd env in 106 + let fs = 107 + match chdir with 108 + | None -> Eio.Stdenv.cwd env 109 + | Some d -> Eio.Path.(Eio.Stdenv.fs env / d) 110 + in 103 111 init_impl ~fs dry_run force hooks dirs 104 112 105 113 let init_cmd = ··· 125 133 ] 126 134 in 127 135 let info = Cmd.info "init" ~doc ~man in 128 - Cmd.v info Term.(const init $ dry_run $ force $ hooks $ dirs) 136 + Cmd.v info Term.(const init $ chdir $ dry_run $ force $ hooks $ dirs) 129 137 130 138 (* {1 Status command} *) 131 139 ··· 181 189 else if !ok > 0 then 182 190 success "%d project%s properly configured" !ok (if !ok = 1 then "" else "s") 183 191 184 - let status dirs = 192 + let status chdir dirs = 185 193 Eio_main.run @@ fun env -> 186 - let fs = Eio.Stdenv.cwd env in 194 + let fs = 195 + match chdir with 196 + | None -> Eio.Stdenv.cwd env 197 + | Some d -> Eio.Path.(Eio.Stdenv.fs env / d) 198 + in 187 199 status_impl ~fs dirs 188 200 189 201 let status_cmd = ··· 202 214 ] 203 215 in 204 216 let info = Cmd.info "status" ~doc ~man in 205 - Cmd.v info Term.(const status $ dirs) 217 + Cmd.v info Term.(const status $ chdir $ dirs) 206 218 207 219 (* {1 Check command} *) 208 220 ··· 285 297 end 286 298 else success "No AI attribution found in commit history" 287 299 288 - let check dirs = 300 + let check chdir dirs = 289 301 Eio_main.run @@ fun env -> 290 - let fs = Eio.Stdenv.cwd env in 302 + let fs = 303 + match chdir with 304 + | None -> Eio.Stdenv.cwd env 305 + | Some d -> Eio.Path.(Eio.Stdenv.fs env / d) 306 + in 291 307 check_impl ~fs dirs 292 308 293 309 let check_cmd = ··· 301 317 `S Manpage.s_examples; 302 318 `P "Check all projects under src/:"; 303 319 `Pre " precommit check src/"; 320 + `P "Check a specific directory:"; 321 + `Pre " precommit check -C ../src/ocaml-requests"; 304 322 ] 305 323 in 306 324 let info = Cmd.info "check" ~doc ~man in 307 - Cmd.v info Term.(const check $ dirs) 325 + Cmd.v info Term.(const check $ chdir $ dirs) 308 326 309 327 (* {1 Fix command} *) 310 328 ··· 387 405 let doc = "Skip interactive confirmation prompt." in 388 406 Arg.(value & flag & info [ "y"; "yes" ] ~doc) 389 407 390 - let fix dry_run yes dirs = 408 + let fix chdir dry_run yes dirs = 391 409 Eio_main.run @@ fun env -> 392 - let fs = Eio.Stdenv.cwd env in 410 + let fs = 411 + match chdir with 412 + | None -> Eio.Stdenv.cwd env 413 + | Some d -> Eio.Path.(Eio.Stdenv.fs env / d) 414 + in 393 415 fix_impl ~fs dry_run yes dirs 394 416 395 417 let fix_cmd = ··· 415 437 ] 416 438 in 417 439 let info = Cmd.info "fix" ~doc ~man in 418 - Cmd.v info Term.(const fix $ dry_run $ yes $ dirs) 440 + Cmd.v info Term.(const fix $ chdir $ dry_run $ yes $ dirs) 419 441 420 442 (* {1 Main} *) 421 443