Skip to content

Conversation

@ProgramingIsTheFuture
Copy link

Related to issue #6235.

Adding a new command that will allow us to get the URL and Rank of a specific repo.

Also supports all (will display the url and rank of a repo for every switch):

$ opam repo show default --all

@rjbou rjbou requested review from kit-ty-kate and rjbou and removed request for rjbou October 6, 2025 13:17
@kit-ty-kate kit-ty-kate added this to the 2.5.0~alpha1 milestone Oct 6, 2025
@rjbou rjbou changed the title Add opam repo show .. support Add opam repo show <reponame> support Oct 6, 2025
@dra27 dra27 changed the title Add opam repo show <reponame> support Add opam repo show … support Oct 6, 2025
@dra27
Copy link
Member

dra27 commented Oct 6, 2025

(sorry, I can't get past .. as meaning the parent directory!)

@ProgramingIsTheFuture ProgramingIsTheFuture changed the title Add opam repo show … support Add opam repo show <reponame> support Oct 6, 2025
@kit-ty-kate kit-ty-kate linked an issue Oct 6, 2025 that may be closed by this pull request
Copy link
Member

@kit-ty-kate kit-ty-kate left a comment

Choose a reason for hiding this comment

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

Thanks for this PR, i've pushed a commit to apply some of our more common coding style, so that the new code doesn't feel too out of place.

I've tried and it works reasonably well, however i've hit some issues:

$ opam repo show --switch=does-not-exist default
switch: does-not-exist
url: https://staging.opam.ocaml.org/
rank: 2

with does-not-exist being a non-existent switch and default being an existent repository.
I don't think this should return that kind of output (i would more expect something like an error).

I also think the new command should have a way to display the details of a repository that's not currently attached to any switches (maybe with --dont-select?)

I'm also wondering how useful would opam repo show -a be, but we could add it later if needed i suppose.

@ProgramingIsTheFuture
Copy link
Author

There are some other commands with the same behaviour (abc is not defined):

$ opam repo list --switch=abc
[NOTE] These are the repositories in use by the current switch. Use '--all'
       to see all configured repositories.

<><> Repository configuration for switch abc <><><><><><><><><><><><><><><><>
 1 default https://opam.ocaml.org

Reading more the code, I found that the actual flag to select switch is --on-switch (defined here). This will produce the expected behaviour (error in case of non-existing switch).

Because --switch=<switch> doesn't populate the `Switch <switch>:

| `Switch sw ->
if not (OpamSwitch.Set.mem sw all) &&
not (OpamSwitch.is_external sw)
then
OpamConsole.error_and_exit `Not_found
"No switch %s found"
(OpamSwitch.to_string sw)
else if OpamStd.List.mem OpamSwitch.equal sw acc then acc
else acc @ [sw]

Could you please verify?

@kit-ty-kate
Copy link
Member

Ah my bad, i thought --switch would do it without looking at the man page because of the name of the variant. --on-switch works as expected indeed.

I think we should fix --switch separately. I'll open a ticket.

Copy link
Member

@kit-ty-kate kit-ty-kate left a comment

Choose a reason for hiding this comment

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

some more design questions:

  • do we want opam repo show does-no-exist to exit 0 with no error message?
  • do we want an extra name: line, even if a bit useless at the moment, it might be useful later if opam repo show -a is added
  • do we want to have colors? This might help with readability (for example opam show <pkg> has its fields coloured blue)
  • what is the intended way to parse the output? Wait for switch, then parse each line in this context until a new line starting with switch: ?

Comment on lines 235 to 236
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;

@rjbou rjbou modified the milestones: 2.5.0~alpha1, 2.6.0~alpha1 Oct 13, 2025
@ProgramingIsTheFuture
Copy link
Author

Hey @kit-ty-kate, I made the above changes.

Wait for switch, then parse each line in this context until a new line starting with switch: ?

Yes, the output should be a name, url and rank.

It now works with -a and without repo_name (it will list all repos for the current switch) and the error message is better now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

opam repo show <repo-name>

4 participants