package b0

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file b0_cmd_tool.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
(*---------------------------------------------------------------------------
   Copyright (c) 2020 The b0 programmers. All rights reserved.
   SPDX-License-Identifier: ISC
  ---------------------------------------------------------------------------*)

open B0_std
open Result.Syntax

let pp_tool ppf n = Fmt.st [`Fg `Green] ppf n
let list ~output_details c =
  let pp, sep = match output_details with
  | `Short ->
      let pp_tool ppf (n, _) = Fmt.code ppf n in
      pp_tool, Fmt.cut
  | `Normal ->
      let pp_tool ppf (n, u) =
        if n = B0_unit.name u
        then Fmt.pf ppf "@[%a %s@]" pp_tool n (B0_unit.doc u) else
        Fmt.pf ppf "@[%a (%a) %s@]" pp_tool n B0_unit.pp_name u (B0_unit.doc u)
      in
      pp_tool, Fmt.cut
  | `Long ->
      let pp_tool ppf (n, u) = B0_unit.pp ppf u in
      pp_tool, Fmt.(cut ++ cut)
  in
  Log.if_error ~use:Os.Exit.no_such_name @@
  let* us = B0_unit.get_list_or_hint ~all_if_empty:true [] in
  let keep_tool u = match B0_unit.find_meta B0_unit.tool_name u with
  | Some n when B0_unit.tool_is_user_accessible u -> Some (n, u)
  | None | Some _ -> None
  in
  let tools = List.sort compare (List.filter_map keep_tool us) in
  Log.if_error' ~use:Os.Exit.some_error @@
  let no_pager = B0_driver.Conf.no_pager c in
  let* pager = B0_pager.find ~no_pager () in
  let* () = B0_pager.page_stdout pager in
  if tools <> []
  then Log.stdout (fun m -> m "@[<v>%a@]" Fmt.(list ~sep pp) tools);
  Ok Os.Exit.ok

(* Command line interface *)

open Cmdliner
open Cmdliner.Term.Syntax

let list =
  let doc = "List buildable tools" in
  let descr = `P "$(cmd) lists given buildable tools"; in
  B0_tool_cli.cmd_with_b0_file "list" ~doc ~descr @@
  let+ output_details = B0_cli.output_details in
  list ~output_details

let cmd =
  let doc = "Operate on buildable tools" in
  let descr = `Blocks [
    `P "$(cmd) operates on buildable tools.";
    `P "These are the public tools in the build and the non-public tools \
        in the root scope."; ]
  in
  B0_tool_cli.cmd_group "tool" ~doc ~descr @@
  [list]