Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/client/opamCommands.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2276,6 +2276,8 @@ let repository cli =
where they are active.";
cli_original, "priority", `priority, ["NAME"; "RANK"],
"Synonym to $(b,add NAME --rank RANK)";
cli_original, "show", `show_repo, [],
"Show the URL and priority of a repository";
] in
let man = [
`S Manpage.s_description;
Expand Down Expand Up @@ -2580,6 +2582,20 @@ let repository cli =
'--all' to see all configured repositories.";
OpamRepositoryCommand.list rt ~global ~switches ~short;
`Ok ()
| Some `show_repo, [ repo_name ] ->
OpamRepositoryState.with_ `Lock_none gt @@ fun rt ->
let switches =
if scope = [] ||
List.exists (function
| `This_switch | `Current_switch | `Switch _ -> true
| _ -> false)
scope
then switches
else all_switches
in
OpamRepositoryCommand.show_repo rt ~switches
(OpamRepositoryName.of_string repo_name);
`Ok ()
| command, params -> bad_subcommand ~cli commands ("repository", command, params)
in
mk_command_ret ~cli cli_original "repository" ~doc ~man
Expand Down
28 changes: 28 additions & 0 deletions src/client/opamRepositoryCommand.ml
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,34 @@ let list_all rt ~short =
OpamStd.Format.align_table |>
OpamConsole.print_table stdout ~sep:" "

let show_repo rt ~switches repo_name =
let repos =
List.filter_map (fun sw ->
let repos =
switch_repos rt sw |>
List.mapi (fun i repo -> (i+1, repo)) |>
List.filter (fun (_, repo) -> OpamRepositoryName.equal repo repo_name)
in
match repos with
| [] -> None
| repos -> Some (sw, repos)
) switches
in
List.iter (fun (sw, repos) ->
List.iter (fun (rank, repo) ->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is probably a better way to do this but i think it would be nice to have the different switches visually separated. opam repo show -a default is quite hard to look at, at the moment

Suggested change
List.iter (fun (sw, repos) ->
List.iter (fun (rank, repo) ->
let did_print_atleast_once = ref false in
List.iter (fun (sw, repos) ->
List.iter (fun (rank, repo) ->
if !did_print_atleast_once then
OpamConsole.msg "\n"
else
did_print_atleast_once := true;

try
let r = OpamRepositoryName.Map.find repo rt.repositories in
let url =
OpamConsole.colorise `underline (OpamUrl.to_string r.repo_url)
in
OpamConsole.msg "switch: %s\n" (OpamSwitch.to_string sw);
OpamConsole.msg "url: %s\n" url;
OpamConsole.msg "rank: %d\n" rank;
with Not_found ->
OpamConsole.msg "%s" (OpamConsole.colorise `red "not found"))
repos)
repos

let update_with_auto_upgrade rt repo_names =
let repos = List.map (OpamRepositoryState.get_repo rt) repo_names in
let failed, rt = OpamUpdate.repositories rt repos in
Expand Down
3 changes: 3 additions & 0 deletions src/client/opamRepositoryCommand.mli
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ val list:
are selected in. *)
val list_all: 'a repos_state -> short:bool -> unit

(** Show the URL and priority (rank) of the given repository *)
val show_repo: 'a repos_state -> switches:switch list -> repository_name -> unit

(** Add a new repository to ~/.opam/repos, without updating any selections *)
val add:
rw repos_state -> repository_name -> url -> trust_anchors option ->
Expand Down