Added Augeas.count_matches
[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   (** Flags passed to the {!create} function. *)
33
34 type path = string
35   (** A path expression.
36
37       Note in future we may replace this with a type-safe path constructor. *)
38
39 type value = string
40   (** A value. *)
41
42 val create : string -> string option -> flag list -> t
43   (** [create root loadpath flags] creates an Augeas handle.
44
45       [root] is a file system path describing the location
46       of the configuration files.
47
48       [loadpath] is an optional colon-separated list of directories
49       which are searched for schema definitions.
50
51       [flags] is a list of flags. *)
52
53 val close : t -> unit
54   (** [close handle] closes the handle.
55
56       You don't need to close handles explicitly with this function:
57       they will be finalized eventually by the garbage collector.
58       However calling this function frees up any resources used by the
59       underlying Augeas library immediately.
60
61       Do not use the handle after closing it. *)
62
63 val get : t -> path -> value option
64   (** [get t path] returns the value at [path], or [None] if there
65       is no value. *)
66
67 val exists : t -> path -> bool
68   (** [exists t path] returns true iff there is a value at [path]. *)
69
70 val insert : t -> ?before:bool -> path -> string -> unit
71   (** [insert t ?before path label] inserts [label] as a sibling
72       of [path].  By default it is inserted after [path], unless
73       [~before:true] is specified. *)
74
75 val rm : t -> path -> int
76   (** [rm t path] removes all nodes matching [path].
77
78       Returns the number of nodes removed (which may be 0). *)
79
80 val matches : t -> path -> path list
81   (** [matches t path] returns a list of path expressions
82       of all nodes matching [path]. *)
83
84 val count_matches : t -> path -> int
85   (** [count_matches t path] counts the number of nodes matching
86       [path] but does not return them (see {!matches}). *)
87
88 val save : t -> unit
89   (** [save t] saves all pending changes to disk. *)