package opam-core

  1. Overview
  2. Docs

Querying

val tty_out : bool

true if stdout is bound to a terminal

val tty_in : bool

true if stdin is bound to a terminal

val terminal_columns : unit -> int

Queried lazily, but may change on SIGWINCH

val home : unit -> string

The user's home directory. Queried lazily

val etc : unit -> string

The /etc directory

val system : unit -> string

The system directory (Windows only)

type os =
  1. | Darwin
  2. | Linux
  3. | FreeBSD
  4. | OpenBSD
  5. | NetBSD
  6. | DragonFly
  7. | Cygwin
  8. | Win32
  9. | Unix
  10. | Other of string
val os : unit -> os

Queried lazily

val uname : string -> string option

The output of the command "uname", with the given argument. Memoised.

val executable_name : string -> string

Append .exe (only if missing) to executable filenames on Windows

val chop_exe_suffix : string -> string

Remove .exe (if present) from an executable filename on Windows

type powershell_host =
  1. | Powershell_pwsh
  2. | Powershell

The different families of shells we know about

type shell =
  1. | SH_sh
  2. | SH_bash
  3. | SH_zsh
  4. | SH_csh
  5. | SH_fish
  6. | SH_pwsh of powershell_host
  7. | SH_cmd
val all_shells : shell list

List of all supported shells

val guess_shell_compat : unit -> shell

Guess the shell compat-mode

val guess_dot_profile : shell -> string option

Guess the location of .profile. Returns None if the shell doesn't support the concept of a .profile file.

val path_sep : char

The separator character used in the PATH variable (varies depending on OS)

val is_valid_basename_char : char -> bool

true if a character may be used in a filename, depending on the OS. For example, on Windows, `:` and `?` can't be in the name.

val split_path_variable : ?clean:bool -> string -> string list

Splits a PATH-like variable separated with path_sep. More involved than it seems, because there may be quoting on Windows. By default, it returns the path cleaned (remove trailing, leading, contiguous delimiters). Optional argument clean permits to keep those empty strings.

val resolve_command : ?env:string array -> ?dir:string -> string -> [ `Cmd of string | `Denied | `Not_found ]

Test whether a command exists in the environment, and returns it (resolved if found in PATH). ~env defaults to Env.raw_env.

val resolve_in_path : ?env:string array -> string -> string option

Search for an arbitrary file in PATH. Unlike resolve_command, no transformations take place on the name in Windows (i.e. .exe, etc. is never appended) and no executable check takes place. The name passed must be a basename (no directory component).

val get_windows_executable_variant : ?search_in_first:string -> string -> [ `Native | `Cygwin | `Tainted of [ `Msys2 | `Cygwin ] | `Msys2 ]

For native Windows builds, returns `Cygwin if the command is a Cygwin- compiled executable, `Msys2 if the command is a MSYS2-compiled executable, and `Tainted of [ `Msys2 | `Cygwin ] if the command links to a library which is itself Cygwin- or MSYS2-compiled, or `Native otherwise.

If supplied, ~search_in_first specifies a directory which should be searched for cygcheck prior to searching the current PATH.

If the command given is not an absolute path, it too is resolved in the current PATH.

If cygcheck cannot be resolved in PATH, or when running the Cygwin build of opam, the function returns `Native.

val get_cygwin_variant : ?search_in_first:string -> string -> [ `Native | `Cygwin | `CygLinked ]

Behaviour is largely as get_windows_executable_variant but where MSYS2 and Cygwin are seen as equivalent.

For native Windows builds, returns `Cygwin if the command is a Cygwin- or Msys2- compiled executable, and `CygLinked if the command links to a library which is itself Cygwin/Msys2-compiled, or `Native otherwise.

val is_cygwin_variant : ?search_in_first:string -> string -> bool

Returns true if get_cygwin_variant is `Cygwin

Exit handling

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

Like Stdlib.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. Unneeded if exiting normally

exception Exit of int

Indicates intention to exit the program with given exit code

exception Exec of string * string array * string array

Indicates intention to exec() the given command (parameters as per Unix.execvpe), after proper finalisations. It's the responsibility of the main function to catch this, call exec_at_exit, and Unix.execvpe.

Raises Exit i

type exit_reason = [
  1. | `Success
  2. | `False
  3. | `Bad_arguments
  4. | `Not_found
  5. | `Aborted
  6. | `Locked
  7. | `No_solution
  8. | `File_error
  9. | `Package_operation_error
  10. | `Sync_error
  11. | `Configuration_error
  12. | `Solver_failure
  13. | `Internal_error
  14. | `User_interrupt
]
val exit_codes : (exit_reason * int) list
val get_exit_code : exit_reason -> int
val exit_because : exit_reason -> 'a

Raises Exit, with the code associated to the exit reason

OCaml

Innovation. Community. Security.