Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
11 changes: 11 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_from cli2_5, "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,15 @@ let repository cli =
'--all' to see all configured repositories.";
OpamRepositoryCommand.list rt ~global ~switches ~short;
`Ok ()
| Some `show_repo, [] ->
OpamRepositoryState.with_ `Lock_none gt @@ fun rt ->
OpamRepositoryCommand.show_repo rt ~switches None;
`Ok ()
| Some `show_repo, [ repo_name ] ->
OpamRepositoryState.with_ `Lock_none gt @@ fun rt ->
let repo_name = if scope = [ `All ] then None else Some (OpamRepositoryName.of_string repo_name) in
OpamRepositoryCommand.show_repo rt ~switches repo_name;
`Ok ()
| command, params -> bad_subcommand ~cli commands ("repository", command, params)
in
mk_command_ret ~cli cli_original "repository" ~doc ~man
Expand Down
47 changes: 47 additions & 0 deletions src/client/opamRepositoryCommand.ml
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,53 @@ let list_all rt ~short =
OpamStd.Format.align_table |>
OpamConsole.print_table stdout ~sep:" "

let show_repo rt ~switches repo_name =
let repos_to_table repos =
List.fold_left (fun acc (rank, repo) ->
let r = OpamRepositoryName.Map.find repo rt.repositories in
[ OpamConsole.colorise `blue "rank"; string_of_int rank ]
:: [ OpamConsole.colorise `blue "url"; OpamUrl.to_string r.repo_url ]
:: [ OpamConsole.colorise `blue "name"; OpamRepositoryName.to_string repo ]
:: [ "\n" ]
:: acc)
[] repos
|> List.rev
in
let repos_per_switch =
List.filter_map (fun sw ->
let repos = switch_repos rt sw |> List.mapi (fun i repo -> (i+1, repo)) in
match repos with
| [] -> None
| repos -> Some (sw, repos)
) switches
in
let repos =
match repo_name with
| None -> List.map (fun (sw, repos) -> sw, repos_to_table repos) repos_per_switch
| Some repo_name ->
List.filter_map (fun (sw, repos) ->
match List.filter (fun (_, repo) ->
OpamRepositoryName.equal repo repo_name) repos with
| [] -> None
| repos -> Some (sw, repos_to_table repos)
) repos_per_switch
in
match repos with
| [] -> begin
match repo_name with
| None ->
OpamConsole.error_and_exit `Bad_arguments "No repository found";
| Some repo_name ->
OpamConsole.error_and_exit `Bad_arguments
"No repository called %s was found" (OpamRepositoryName.to_string repo_name);
end
| repos ->
List.iter (fun (sw, tbl) ->
OpamConsole.header_msg "switch: %s" (OpamSwitch.to_string sw);
OpamStd.Format.align_table tbl |>
OpamConsole.print_table ~cut:`Truncate stdout ~sep:" ")
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 option -> 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