327dc022830681eb5227e989e3a3a012dfbb5d19
[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 type flag =
25   | AugSaveBackup                       (** Rename original with .augsave *)
26   | AugSaveNewFile                      (** Save changes to .augnew *)
27   | AugTypeCheck                        (** Type-check lenses *)
28   | AugNoStdinc
29   | AugSaveNoop
30   | AugNoLoad
31   (** Flags passed to the {!create} function. *)
32
33 type error_code =
34   | AugErrInternal              (** Internal error (bug) *)
35   | AugErrPathX                 (** Invalid path expression *)
36   | AugErrNoMatch               (** No match for path expression *)
37   | AugErrMMatch                (** Too many matches for path expression *)
38   | AugErrSyntax                (** Syntax error in lens file *)
39   | AugErrNoLens                (** Lens lookup failed *)
40   | AugErrMXfm                  (** Multiple transforms *)
41   | AugErrNoSpan                (** No span for this node *)
42   | AugErrMvDesc                (** Cannot move node into its descendant *)
43   | AugErrCmdRun                (** Failed to execute command *)
44   | AugErrBadArg                (** Invalid argument in funcion call *)
45   | AugErrLabel                 (** Invalid label *)
46   | AugErrCpDesc                (** Cannot copy node into its descendant *)
47   | AugErrUnknown of int
48   (** Possible error codes. *)
49
50 type transform_mode =
51   | Include
52   | Exclude
53   (** The operation mode for the {!transform} function. *)
54
55 exception Error of error_code * string * string * string
56   (** This exception is thrown when the underlying Augeas library
57       returns an error.  The tuple represents:
58       - the Augeas error code
59       - the ocaml-augeas error string
60       - the human-readable explanation of the Augeas error, if available
61       - a string with details of the Augeas error
62    *)
63
64 type path = string
65   (** A path expression.
66
67       Note in future we may replace this with a type-safe path constructor. *)
68
69 type value = string
70   (** A value. *)
71
72 val create : string -> string option -> flag list -> t
73   (** [create root loadpath flags] creates an Augeas handle.
74
75       [root] is a file system path describing the location
76       of the configuration files.
77
78       [loadpath] is an optional colon-separated list of directories
79       which are searched for schema definitions.
80
81       [flags] is a list of flags. *)
82
83 val close : t -> unit
84   (** [close handle] closes the handle.
85
86       You don't need to close handles explicitly with this function:
87       they will be finalized eventually by the garbage collector.
88       However calling this function frees up any resources used by the
89       underlying Augeas library immediately.
90
91       Do not use the handle after closing it. *)
92
93 val get : t -> path -> value option
94   (** [get t path] returns the value at [path], or [None] if there
95       is no value. *)
96
97 val exists : t -> path -> bool
98   (** [exists t path] returns true iff there is a value at [path]. *)
99
100 val insert : t -> ?before:bool -> path -> string -> unit
101   (** [insert t ?before path label] inserts [label] as a sibling
102       of [path].  By default it is inserted after [path], unless
103       [~before:true] is specified. *)
104
105 val rm : t -> path -> int
106   (** [rm t path] removes all nodes matching [path].
107
108       Returns the number of nodes removed (which may be 0). *)
109
110 val matches : t -> path -> path list
111   (** [matches t path] returns a list of path expressions
112       of all nodes matching [path]. *)
113
114 val count_matches : t -> path -> int
115   (** [count_matches t path] counts the number of nodes matching
116       [path] but does not return them (see {!matches}). *)
117
118 val save : t -> unit
119   (** [save t] saves all pending changes to disk. *)
120
121 val load : t -> unit
122   (** [load t] loads files into the tree. *)
123
124 val set : t -> path -> value option -> unit
125   (** [set t path] sets [value] as new value at [path]. *)
126
127 val transform : t -> string -> string -> transform_mode -> unit
128   (** [transform t lens file mode] adds or removes (depending on
129       [mode]) the transformation of the specified [lens] for [file]. *)