Skip to content

Commit ba224cc

Browse files
rjboukit-ty-kate
authored andcommitted
admincommand: factorise cwd repo root creation with a function that is called everywhere
1 parent 80e29e3 commit ba224cc

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

src/client/opamAdminCommand.ml

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@ open Cmdliner
1616

1717
type command = unit Cmdliner.Term.t * Cmdliner.Cmd.info
1818

19+
(* TODO ORR maybe better name ? *)
20+
let cwd_repo_root () = OpamRepositoryRoot.Dir.of_dir (OpamFilename.cwd ())
21+
1922
let checked_repo_root () =
20-
let repo_root = OpamRepositoryRoot.Dir.of_dir (OpamFilename.cwd ()) in
23+
let repo_root = cwd_repo_root () in
2124
if not (OpamFilename.exists_dir (OpamRepositoryPath.packages_dir repo_root))
2225
then
2326
OpamConsole.error_and_exit `Bad_arguments
@@ -776,8 +779,7 @@ let upgrade_command cli =
776779
if clear_cache then OpamAdminRepoUpgrade.clear_cache ()
777780
else match create_mirror with
778781
| None ->
779-
OpamAdminRepoUpgrade.do_upgrade
780-
(OpamRepositoryRoot.Dir.of_dir (OpamFilename.cwd ()));
782+
OpamAdminRepoUpgrade.do_upgrade (cwd_repo_root ());
781783
if OpamFilename.exists (OpamFilename.of_string "index.tar.gz") ||
782784
OpamFilename.exists (OpamFilename.of_string "urls.txt")
783785
then
@@ -786,8 +788,7 @@ let upgrade_command cli =
786788
\n\
787789
\ opam admin index"
788790
| Some m ->
789-
OpamAdminRepoUpgrade.do_upgrade_mirror
790-
(OpamRepositoryRoot.Dir.of_dir (OpamFilename.cwd ())) m
791+
OpamAdminRepoUpgrade.do_upgrade_mirror (cwd_repo_root ()) m
791792
in
792793
OpamArg.mk_command ~cli OpamArg.cli_original command ~doc ~man
793794
Term.(const cmd $ global_options cli $
@@ -832,7 +833,7 @@ let lint_command cli =
832833
in
833834
let cmd global_options short list incl excl ign warn_error () =
834835
OpamArg.apply_global_options cli global_options;
835-
let repo_root = OpamRepositoryRoot.Dir.of_dir (OpamFilename.cwd ()) in
836+
let repo_root = cwd_repo_root () in
836837
if not (OpamFilename.exists_dir
837838
OpamFilename.Op.(OpamRepositoryRoot.Dir.to_dir repo_root /
838839
"packages"))
@@ -1175,10 +1176,7 @@ let list_command cli =
11751176
List.map (fun x -> Atom x) package_selection);
11761177
]
11771178
in
1178-
let st =
1179-
get_virtual_switch_state
1180-
(OpamRepositoryRoot.Dir.of_dir (OpamFilename.cwd ())) env
1181-
in
1179+
let st = get_virtual_switch_state (cwd_repo_root ()) env in
11821180
if not format.OpamListCommand.short && filter <> OpamFormula.Empty then
11831181
OpamConsole.msg "# Packages matching: %s\n"
11841182
(OpamListCommand.string_of_formula filter);
@@ -1219,7 +1217,7 @@ let filter_command cli =
12191217
global_options package_selection disjunction state_selection env
12201218
remove dryrun packages () =
12211219
OpamArg.apply_global_options cli global_options;
1222-
let repo_root = OpamRepositoryRoot.Dir.of_dir (OpamFilename.cwd ()) in
1220+
let repo_root = cwd_repo_root () in
12231221
let pattern_selector = OpamListCommand.pattern_selector packages in
12241222
let join =
12251223
if disjunction then OpamFormula.ors else OpamFormula.ands

0 commit comments

Comments
 (0)