Skip to content

Commit

Permalink
make opam remote works more like git remote
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Bernardoff committed Sep 12, 2012
1 parent 64cc4d0 commit 05001d9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
15 changes: 9 additions & 6 deletions src/client.ml
Expand Up @@ -2069,7 +2069,7 @@ let config request =
log "OUTPUT: %S" output;
Globals.msg "%s\n" output

let remote action =
let remote ?(verbose=false) action =
log "remote %s" (string_of_remote action);
let t = load_state () in
let repos = File.Config.repositories t.config in
Expand Down Expand Up @@ -2102,12 +2102,15 @@ let remote action =
Dirname.rmdir (Path.R.root (Path.R.create repo)) in
match action with
| List ->
let pretty_print r =
let pretty_print r =
if verbose then
Globals.msg "%-7s %10s %s\n"
(Printf.sprintf "[%s]" (Repository.kind r))
(Repository.name r)
(Dirname.to_string (Repository.address r)) in
List.iter pretty_print repos
(Dirname.to_string (Repository.address r))
else
Globals.msg "%s\n" (Repository.name r) in
List.iter pretty_print repos
| Add repo ->
let name = Repository.name repo in
if List.exists (fun r -> Repository.name r = name) repos then
Expand Down Expand Up @@ -2334,8 +2337,8 @@ let upload u r =
let remove name =
check (Write_lock (fun () -> remove name))

let remote action =
check (Write_lock (fun () -> remote action))
let remote ?(verbose=false) action =
check (Write_lock (fun () -> remote ~verbose action))

let compiler_install quiet alias ocaml_version =
check (Write_lock (fun () -> compiler_install quiet alias ocaml_version))
Expand Down
2 changes: 1 addition & 1 deletion src/client.mli
Expand Up @@ -61,7 +61,7 @@ val upload : upload -> string option -> unit
val remove : N.Set.t -> unit

(** Manage remote repositories. Take the global file lock. *)
val remote : remote -> unit
val remote : ?verbose:bool -> remote -> unit

(** Install the given compiler. Take the global file lock. *)
val compiler_install: bool -> Alias.t -> OCaml_V.t -> unit
Expand Down
15 changes: 9 additions & 6 deletions src/opam.ml
Expand Up @@ -336,6 +336,7 @@ let remove = {
(* opam remote [-list|-add <url>|-rm <url>] *)
let remote =
let kind = ref None in
let verbose = ref false in
let command : [`add|`list|`rm] option ref = ref None in
let set c () = command := Some c in
{
Expand All @@ -344,21 +345,23 @@ let remote =
synopsis = "Manage remote servers";
help = "";
specs = [
("-v" , Arg.Unit (fun () -> verbose := true), " Be verbose");
("-list" , Arg.Unit (set `list), " List the repositories");
("-add" , Arg.Unit (set `add) , " Add a new repository");
("-rm" , Arg.Unit (set `rm) , " Remove a remote repository");
("-kind" , Arg.String (fun s -> kind := Some s) , " (optional) Specify the repository kind");
];
anon;
main = parse_args (fun args ->
let verbose = !verbose in
match !command, args with
| Some `list, [] -> Client.remote List
| Some `rm, [ name ] -> Client.remote (Rm name)
| Some `add , [ name; address ] ->
| Some `list, [] -> Client.remote ~verbose List
| Some `rm, [ name ] -> Client.remote ~verbose (Rm name)
| Some `add , [ name; address ] ->
let kind = guess_repository_kind !kind address in
Client.remote (Add (Repository.create ~name ~kind ~address))
| None, _ -> bad_argument "remote" "Command missing [-list|-add|-rm]"
| _ -> bad_argument "remote" "Wrong arguments")
Client.remote ~verbose (Add (Repository.create ~name ~kind ~address))
| _ -> Client.remote ~verbose List
)
}

(* opam switch [-clone] OVERSION *)
Expand Down

0 comments on commit 05001d9

Please sign in to comment.