package opam-lib

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

Basic functions

Abstract types

module type SET = sig ... end

Collection of abstract values

module type MAP = sig ... end

Dictionaries of abstract values

module type ABSTRACT = sig ... end

All abstract types should implement this signature

module type OrderedType = sig ... end

Extended sets and maps

module Set : sig ... end

Set constructor

module Map : sig ... end

Map constructor

module Base : sig ... end

Base module, useful to abstract strings

Integer manipulation

module IntMap : MAP with type key = int

Map of ints

module IntSet : SET with type elt = int

Set of ints

val sconcat_map : ?left:string -> ?right:string -> ?nil:string -> string -> ('a -> string) -> 'a list -> string

Convert list items to string and concat. sconcat_map sep f x is equivalent to String.concat sep (List.map f x) but tail-rec.

val string_of_list : ('a -> string) -> 'a list -> string

Display a list of strings

val itemize : ?bullet:string -> ('a -> string) -> 'a list -> string

Convert a list of items to string as a dashed list

val string_map : (char -> char) -> string -> string
val pretty_list : ?last:string -> string list -> string

Display a pretty list: "x";"y";"z" -> "x, y and z". "and" can be changed by specifying last

val remove_duplicates : 'a list -> 'a list

Removes consecutive duplicates in a list

String manipulation

module StringMap : MAP with type key = string

Map of strings

module StringSet : SET with type elt = string

Set of strings

module StringSetSet : SET with type elt = StringSet.t

Set of string sets

module StringSetMap : MAP with type key = StringSet.t

Map of string sets

val strip : string -> string

Strip a string

val starts_with : prefix:string -> string -> bool

Does a string starts with the given prefix ?

val ends_with : suffix:string -> string -> bool

Does a string ends with the given suffix ?

val remove_prefix : prefix:string -> string -> string

Remove a prefix

val remove_suffix : suffix:string -> string -> string

Remove a suffix

val cut_at : string -> char -> (string * string) option

Cut a string at the first occurence of the given char

val rcut_at : string -> char -> (string * string) option

Same as cut_at, but starts from the right

val contains : string -> char -> bool

Does a string contains the given chars ?

val split : string -> char -> string list

Split a string

val visual_length : string -> int

Returns the length of the string in terminal chars, ignoring ANSI color sequences from OpamGlobals.colorise

val indent_left : string -> ?visual:string -> int -> string

left indenting. ~visual can be used to indent eg. ANSI colored strings and should correspond to the visible characters of s

val indent_right : string -> ?visual:string -> int -> string

right indenting

val align_table : string list list -> string list list

Pads fields in a table with spaces for alignment.

val print_table : Pervasives.out_channel -> sep:string -> string list list -> unit

Prints a table

val sub_at : int -> string -> string

Cut a string

val reformat : ?start_column:int -> ?indent:int -> string -> string

Cut long lines in string according to the terminal width

Option

module Option : sig ... end

Misc

val reset_env_value : prefix:string -> char -> string -> string list

Remove from a c-separated list of string the one with the given prefix

val cut_env_value : prefix:string -> char -> string -> string list * string list

split a c-separated list of string in two according to the first occurrences of the string with the given prefix. The list of elements occurring before is returned in reverse order. If there are other elements with the same prefix they are kept in the second list.

val rsync_trim : string list -> string list

if rsync -arv return 4 lines, this means that no files have changed

val exact_match : Re.re -> string -> bool

Exact regexp matching

val filter_map : ('a -> 'b option) -> 'a list -> 'b list

Filter and map

val insert : ('a -> 'a -> int) -> 'a -> 'a list -> 'a list

Insert a value in an ordered list

val getenv : string -> string

Lazy environment variable

val env : unit -> (string * string) list

Lazy environment

val fatal : exn -> unit

To use when catching default exceptions: ensures we don't catch fatal errors like C-c. try-with should _always_ (by decreasing order of preference):

  • either catch specific exceptions
  • or re-raise the same exception
  • or call this function on the caught exception
val register_backtrace : exn -> unit

Register a backtrace for when you need to process a finalizer (that internally uses exceptions) and then re-raise the same exception. To be printed by pretty_backtrace.

val pretty_backtrace : exn -> string

Return a pretty-printed backtrace

val prettify_path : string -> string

Prettify a local path (eg. replace /home/me/ by '~')

module OP : sig ... end
val tty_out : bool

true if stdout is bound to a terminal

val terminal_columns : unit -> int

When stdout refers to a terminal, query the number of columns. Otherwise return max_int.

val uname_s : unit -> string option

Get the output of uname -s

val uname_m : unit -> string option

Get the output of uname -m

val guess_shell_compat : unit -> [ `csh | `zsh | `sh | `bash | `fish ]

Guess the shell compat-mode

val guess_dot_profile : [ `csh | `zsh | `sh | `bash | `fish ] -> string

Guess the location of .profile

val at_exit : (unit -> unit) -> unit

Like Pervasives.at_exit but with the possibility to call manually (eg. before exec())

val exec_at_exit : unit -> unit

Calls the functions registered in at_exit

/

val debug : bool Pervasives.ref
OCaml

Innovation. Community. Security.