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