summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@vyos.io>2025-09-18 11:54:51 +0100
committerGitHub <noreply@github.com>2025-09-18 11:54:51 +0100
commitff247fe83f4b24b5ed977ac9b04fb5fe19b196f0 (patch)
tree0f3566420c1f59a7ee85cb56bedd04b2b92b9243 /src
parentb53326dce7dd2dabad2677ad82de4fcd4ea85524 (diff)
parent0dfb238da1331c7d5d3152df4de0a17fe9562971 (diff)
downloadvyos1x-config-ff247fe83f4b24b5ed977ac9b04fb5fe19b196f0.tar.gz
vyos1x-config-ff247fe83f4b24b5ed977ac9b04fb5fe19b196f0.zip
Merge pull request #52 from jestabro/interstitial-set
T7737: add utils for analogue of configfs
Diffstat (limited to 'src')
-rw-r--r--src/config_tree.ml2
-rw-r--r--src/config_tree.mli2
-rw-r--r--src/vylist.ml14
-rw-r--r--src/vylist.mli2
4 files changed, 12 insertions, 8 deletions
diff --git a/src/config_tree.ml b/src/config_tree.ml
index 518034f..84cfe43 100644
--- a/src/config_tree.ml
+++ b/src/config_tree.ml
@@ -1,4 +1,4 @@
-type value_behaviour = AddValue | ReplaceValue
+type value_behaviour = AddValue | ReplaceValue [@@deriving yojson]
type command = Set | Delete
exception Duplicate_value
diff --git a/src/config_tree.mli b/src/config_tree.mli
index ef65d68..fe1085c 100644
--- a/src/config_tree.mli
+++ b/src/config_tree.mli
@@ -1,4 +1,4 @@
-type value_behaviour = AddValue | ReplaceValue
+type value_behaviour = AddValue | ReplaceValue [@@deriving yojson]
type command = Set | Delete
exception Duplicate_value
diff --git a/src/vylist.ml b/src/vylist.ml
index c64dd89..9c1085d 100644
--- a/src/vylist.ml
+++ b/src/vylist.ml
@@ -10,11 +10,15 @@ let rec remove p xs =
| y :: ys -> if (p y) then ys
else y :: (remove p ys)
-let rec replace p x xs =
- match xs with
- | [] -> raise Not_found
- | y :: ys -> if (p y) then x :: ys
- else y :: (replace p x ys)
+let rec replace ?(force=false) p x xs =
+ try
+ match xs with
+ | [] -> raise_notrace Not_found
+ | y :: ys -> if (p y) then x :: ys
+ else y :: (replace p x ys)
+ with Not_found ->
+ if force then (x :: xs)
+ else raise Not_found
let rec insert_before p x xs =
match xs with
diff --git a/src/vylist.mli b/src/vylist.mli
index b74a537..54c0806 100644
--- a/src/vylist.mli
+++ b/src/vylist.mli
@@ -1,6 +1,6 @@
val find : ('a -> bool) -> 'a list -> 'a option
val remove : ('a -> bool) -> 'a list -> 'a list
-val replace : ('a -> bool) -> 'a -> 'a list -> 'a list
+val replace : ?force:bool -> ('a -> bool) -> 'a -> 'a list -> 'a list
val insert_before : ('a -> bool) -> 'a -> 'a list -> 'a list
val insert_after : ('a -> bool) -> 'a -> 'a list -> 'a list
val insert_compare : ('a -> 'a -> int) -> 'a -> 'a list -> 'a list