Homebrew bottle builder and tap manager for OCaml monorepos
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

bottler: add update command, extract tap_name

bottler update: runs brew upgrade for all bottled binaries.
Supports filtering by name: bottler update monopam merlint

+64 -26
+36
bin/cmd_update.ml
··· 1 + open Cmdliner 2 + 3 + let run config_file names = 4 + let config = Common.load_config config_file in 5 + let binaries = 6 + match names with 7 + | [] -> config.Homebrew.binaries 8 + | names -> 9 + List.filter 10 + (fun (b : Homebrew.binary) -> List.mem b.name names) 11 + config.binaries 12 + in 13 + if binaries = [] then ( 14 + Fmt.epr "No matching binaries found.@."; 15 + exit 1); 16 + (* Update the tap first *) 17 + let tap_name = Homebrew.tap_name config in 18 + let status = Sys.command (Fmt.str "brew update") in 19 + if status <> 0 then Fmt.epr "Warning: brew update failed (exit %d)@." status; 20 + (* Upgrade each binary *) 21 + List.iter 22 + (fun (b : Homebrew.binary) -> 23 + let formula = Fmt.str "%s/%s" tap_name b.name in 24 + Fmt.pr "Upgrading %s...@." b.name; 25 + let status = Sys.command (Fmt.str "brew upgrade %s 2>&1" formula) in 26 + if status <> 0 then 27 + (* Try install if not installed yet *) 28 + let status = Sys.command (Fmt.str "brew install %s 2>&1" formula) in 29 + if status <> 0 then Fmt.epr " Failed to upgrade/install %s@." b.name) 30 + binaries; 31 + Fmt.pr "Done.@." 32 + 33 + let cmd = 34 + let doc = "Upgrade all bottled binaries via brew." in 35 + let info = Cmd.info "update" ~doc in 36 + Cmd.v info Term.(const run $ Common.config_file $ Common.binary_names)
+1
bin/main.ml
··· 33 33 Cmd_config.cmd; 34 34 Cmd_login.cmd; 35 35 Cmd_doctor.cmd; 36 + Cmd_update.cmd; 36 37 ] 37 38 38 39 let () = exit (Cmd.eval cmd)
+23 -26
lib/homebrew.ml
··· 512 512 pr "end\n"; 513 513 Buffer.contents buf 514 514 515 + let tap_name config = 516 + let url = config.tap.clone_url in 517 + match Astring.String.cut ~rev:true ~sep:"/" url with 518 + | Some (base, repo) -> 519 + let repo = 520 + match Astring.String.cut ~sep:".git" repo with 521 + | Some (r, _) -> r 522 + | None -> repo 523 + in 524 + let repo = 525 + match Astring.String.cut ~sep:"homebrew-" repo with 526 + | Some (_, r) -> r 527 + | None -> repo 528 + in 529 + let user = 530 + match Astring.String.cut ~rev:true ~sep:"/" base with 531 + | Some (_, u) -> u 532 + | None -> base 533 + in 534 + Fmt.str "%s/%s" user repo 535 + | None -> url 536 + 515 537 let generate_readme config = 516 538 let buf = Buffer.create 512 in 517 539 let pr fmt = Fmt.kstr (fun s -> Buffer.add_string buf s) fmt in 518 - (* Derive tap name from clone_url: https://github.com/samoht/homebrew-monopam.git -> samoht/monopam *) 519 - let tap_name = 520 - let url = config.tap.clone_url in 521 - let url = 522 - match Astring.String.cut ~rev:true ~sep:"/" url with 523 - | Some (base, repo) -> 524 - let repo = 525 - match Astring.String.cut ~sep:".git" repo with 526 - | Some (r, _) -> r 527 - | None -> repo 528 - in 529 - let repo = 530 - match Astring.String.cut ~sep:"homebrew-" repo with 531 - | Some (_, r) -> r 532 - | None -> repo 533 - in 534 - let user = 535 - match Astring.String.cut ~rev:true ~sep:"/" base with 536 - | Some (_, u) -> u 537 - | None -> base 538 - in 539 - Fmt.str "%s/%s" user repo 540 - | None -> url 541 - in 542 - url 543 - in 540 + let tap_name = tap_name config in 544 541 pr "# homebrew-monopam\n\n"; 545 542 pr "Homebrew tap for OCaml tools.\n\n"; 546 543 pr "## Installation\n\n";
+4
lib/homebrew.mli
··· 51 51 val load_config : string -> (config, string) result 52 52 (** [load_config path] loads a YAML configuration file. *) 53 53 54 + val tap_name : config -> string 55 + (** [tap_name config] derives the Homebrew tap name (e.g. ["samoht/monopam"]). 56 + *) 57 + 54 58 (** {1 Platform Detection} *) 55 59 56 60 (** Build platform identifier. *)