Implement Augeas.load API.
[ocaml-augeas.git] / augeas.mli
1 (** Augeas OCaml bindings *)
2 (* Copyright (C) 2008 Red Hat Inc., Richard W.M. Jones
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  *
18  * $Id: augeas.mli,v 1.2 2008/05/06 10:48:20 rjones Exp $
19  *)
20
21 type t
22   (** Augeas library handle. *)
23
24 exception Error of string
25   (** This exception is thrown when the underlying Augeas library
26       returns an error. *)
27
28 type flag =
29   | AugSaveBackup                       (** Rename original with .augsave *)
30   | AugSaveNewFile                      (** Save changes to .augnew *)
31   | AugTypeCheck                        (** Type-check lenses *)
32   | AugNoStdinc
33   | AugSaveNoop
34   | AugNoLoad
35   (** Flags passed to the {!create} function. *)
36
37 type path = string
38   (** A path expression.
39
40       Note in future we may replace this with a type-safe path constructor. *)
41
42 type value = string
43   (** A value. *)
44
45 val create : string -> string option -> flag list -> t
46   (** [create root loadpath flags] creates an Augeas handle.
47
48       [root] is a file system path describing the location
49       of the configuration files.
50
51       [loadpath] is an optional colon-separated list of directories
52       which are searched for schema definitions.
53
54       [flags] is a list of flags. *)
55
56 val close : t -> unit
57   (** [close handle] closes the handle.
58
59       You don't need to close handles explicitly with this function:
60       they will be finalized eventually by the garbage collector.
61       However calling this function frees up any resources used by the
62       underlying Augeas library immediately.
63
64       Do not use the handle after closing it. *)
65
66 val get : t -> path -> value option
67   (** [get t path] returns the value at [path], or [None] if there
68       is no value. *)
69
70 val exists : t -> path -> bool
71   (** [exists t path] returns true iff there is a value at [path]. *)
72
73 val insert : t -> ?before:bool -> path -> string -> unit
74   (** [insert t ?before path label] inserts [label] as a sibling
75       of [path].  By default it is inserted after [path], unless
76       [~before:true] is specified. *)
77
78 val rm : t -> path -> int
79   (** [rm t path] removes all nodes matching [path].
80
81       Returns the number of nodes removed (which may be 0). *)
82
83 val matches : t -> path -> path list
84   (** [matches t path] returns a list of path expressions
85       of all nodes matching [path]. *)
86
87 val count_matches : t -> path -> int
88   (** [count_matches t path] counts the number of nodes matching
89       [path] but does not return them (see {!matches}). *)
90
91 val save : t -> unit
92   (** [save t] saves all pending changes to disk. *)
93
94 val load : t -> unit
95   (** [load t] loads files into the tree. *)