···11+open Cmdliner
22+33+let run config_file names =
44+ let config = Common.load_config config_file in
55+ let binaries =
66+ match names with
77+ | [] -> config.Homebrew.binaries
88+ | names ->
99+ List.filter
1010+ (fun (b : Homebrew.binary) -> List.mem b.name names)
1111+ config.binaries
1212+ in
1313+ if binaries = [] then (
1414+ Fmt.epr "No matching binaries found.@.";
1515+ exit 1);
1616+ (* Update the tap first *)
1717+ let tap_name = Homebrew.tap_name config in
1818+ let status = Sys.command (Fmt.str "brew update") in
1919+ if status <> 0 then Fmt.epr "Warning: brew update failed (exit %d)@." status;
2020+ (* Upgrade each binary *)
2121+ List.iter
2222+ (fun (b : Homebrew.binary) ->
2323+ let formula = Fmt.str "%s/%s" tap_name b.name in
2424+ Fmt.pr "Upgrading %s...@." b.name;
2525+ let status = Sys.command (Fmt.str "brew upgrade %s 2>&1" formula) in
2626+ if status <> 0 then
2727+ (* Try install if not installed yet *)
2828+ let status = Sys.command (Fmt.str "brew install %s 2>&1" formula) in
2929+ if status <> 0 then Fmt.epr " Failed to upgrade/install %s@." b.name)
3030+ binaries;
3131+ Fmt.pr "Done.@."
3232+3333+let cmd =
3434+ let doc = "Upgrade all bottled binaries via brew." in
3535+ let info = Cmd.info "update" ~doc in
3636+ Cmd.v info Term.(const run $ Common.config_file $ Common.binary_names)
···512512 pr "end\n";
513513 Buffer.contents buf
514514515515+let tap_name config =
516516+ let url = config.tap.clone_url in
517517+ match Astring.String.cut ~rev:true ~sep:"/" url with
518518+ | Some (base, repo) ->
519519+ let repo =
520520+ match Astring.String.cut ~sep:".git" repo with
521521+ | Some (r, _) -> r
522522+ | None -> repo
523523+ in
524524+ let repo =
525525+ match Astring.String.cut ~sep:"homebrew-" repo with
526526+ | Some (_, r) -> r
527527+ | None -> repo
528528+ in
529529+ let user =
530530+ match Astring.String.cut ~rev:true ~sep:"/" base with
531531+ | Some (_, u) -> u
532532+ | None -> base
533533+ in
534534+ Fmt.str "%s/%s" user repo
535535+ | None -> url
536536+515537let generate_readme config =
516538 let buf = Buffer.create 512 in
517539 let pr fmt = Fmt.kstr (fun s -> Buffer.add_string buf s) fmt in
518518- (* Derive tap name from clone_url: https://github.com/samoht/homebrew-monopam.git -> samoht/monopam *)
519519- let tap_name =
520520- let url = config.tap.clone_url in
521521- let url =
522522- match Astring.String.cut ~rev:true ~sep:"/" url with
523523- | Some (base, repo) ->
524524- let repo =
525525- match Astring.String.cut ~sep:".git" repo with
526526- | Some (r, _) -> r
527527- | None -> repo
528528- in
529529- let repo =
530530- match Astring.String.cut ~sep:"homebrew-" repo with
531531- | Some (_, r) -> r
532532- | None -> repo
533533- in
534534- let user =
535535- match Astring.String.cut ~rev:true ~sep:"/" base with
536536- | Some (_, u) -> u
537537- | None -> base
538538- in
539539- Fmt.str "%s/%s" user repo
540540- | None -> url
541541- in
542542- url
543543- in
540540+ let tap_name = tap_name config in
544541 pr "# homebrew-monopam\n\n";
545542 pr "Homebrew tap for OCaml tools.\n\n";
546543 pr "## Installation\n\n";
+4
lib/homebrew.mli
···5151val load_config : string -> (config, string) result
5252(** [load_config path] loads a YAML configuration file. *)
53535454+val tap_name : config -> string
5555+(** [tap_name config] derives the Homebrew tap name (e.g. ["samoht/monopam"]).
5656+*)
5757+5458(** {1 Platform Detection} *)
55595660(** Build platform identifier. *)