Enhance the Augeas.Error exception
[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 exception Error of error_code * string * string * string
51   (** This exception is thrown when the underlying Augeas library
52       returns an error.  The tuple represents:
53       - the Augeas error code
54       - the ocaml-augeas error string
55       - the human-readable explanation of the Augeas error, if available
56       - a string with details of the Augeas error
57    *)
58
59 type path = string
60   (** A path expression.
61
62       Note in future we may replace this with a type-safe path constructor. *)
63
64 type value = string
65   (** A value. *)
66
67 val create : string -> string option -> flag list -> t
68   (** [create root loadpath flags] creates an Augeas handle.
69
70       [root] is a file system path describing the location
71       of the configuration files.
72
73       [loadpath] is an optional colon-separated list of directories
74       which are searched for schema definitions.
75
76       [flags] is a list of flags. *)
77
78 val close : t -> unit
79   (** [close handle] closes the handle.
80
81       You don't need to close handles explicitly with this function:
82       they will be finalized eventually by the garbage collector.
83       However calling this function frees up any resources used by the
84       underlying Augeas library immediately.
85
86       Do not use the handle after closing it. *)
87
88 val get : t -> path -> value option
89   (** [get t path] returns the value at [path], or [None] if there
90       is no value. *)
91
92 val exists : t -> path -> bool
93   (** [exists t path] returns true iff there is a value at [path]. *)
94
95 val insert : t -> ?before:bool -> path -> string -> unit
96   (** [insert t ?before path label] inserts [label] as a sibling
97       of [path].  By default it is inserted after [path], unless
98       [~before:true] is specified. *)
99
100 val rm : t -> path -> int
101   (** [rm t path] removes all nodes matching [path].
102
103       Returns the number of nodes removed (which may be 0). *)
104
105 val matches : t -> path -> path list
106   (** [matches t path] returns a list of path expressions
107       of all nodes matching [path]. *)
108
109 val count_matches : t -> path -> int
110   (** [count_matches t path] counts the number of nodes matching
111       [path] but does not return them (see {!matches}). *)
112
113 val save : t -> unit
114   (** [save t] saves all pending changes to disk. *)
115
116 val load : t -> unit
117   (** [load t] loads files into the tree. *)