From 403aefe1a4917ef17567e49a0fa850b7dc17f8c8 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Mon, 11 Aug 2025 10:42:47 +0200 Subject: [PATCH 1/2] Reapply "CFE-4562: classfilterdata(): added docs for object of arrays/objects" This commit broke docs because it depends on https://github.com/cfengine/core/pull/5850. Once the dependency is merged, it should be safe to reapply this commit. This reverts commit 3bc63486302c70af5ebb2705a19a06b05cb07707. Ticket: CFE-4562 Signed-off-by: Lars Erik Wik --- .../functions/classfilterdata.markdown | 52 ++++++++++++++++++- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/content/reference/functions/classfilterdata.markdown b/content/reference/functions/classfilterdata.markdown index a1344cf19..b188a5320 100644 --- a/content/reference/functions/classfilterdata.markdown +++ b/content/reference/functions/classfilterdata.markdown @@ -16,10 +16,18 @@ If the `data_structure` argument is specified to be: - `"array_of_arrays"`, the `data_container` argument is interpreted as an array of arrays, and the `key_or_index` argument is interpreted as an index within - the children arrays. + the children arrays. The `key_or_index` argument is required. - `"array_of_objects"`, the `data_container` argument is interpreted as an array of objects, and the `key_or_index` argument is interpreted as a key within the - children objects. + children objects. The `key_or_index` argument is required. +- `"object_of_arrays"`, the `data_container` argument is interpreted as an object + of arrays, and the `key_or_index` argument is interpreted as an index within + the children arrays (if specified). If the `key_or_index` argument is omitted, + the key of the child array itself is used as a class expression. +- `"object_of_objects"`, the `data_container` argument is interpreted as an object + if objects, and the `key_or_index` argument is interpreted as a key within the + children objects (if specified). If the `key_or_index` argument is omitted, the + key of the child object itself is used as a class expression. - `"auto"`, the interpretation is automatically detected based on the data structure. @@ -45,6 +53,46 @@ If the `data_structure` argument is specified to be: {{< CFEngine_include_snippet(classfilterdata_array_of_objects.cf, #\+begin_src\s+example_output\s*, .*end_src) >}} +**Example (with object of arrays):** + +**Policy:** + +{{< CFEngine_include_snippet(classfilterdata_object_of_arrays.cf, #\+begin_src cfengine3, .*end_src) >}} + +**Output:** + +{{< CFEngine_include_snippet(classfilterdata_object_of_arrays.cf, #\+begin_src\s+example_output\s*, .*end_src) >}} + +**Example (with object of objects):** + +**Policy:** + +{{< CFEngine_include_snippet(classfilterdata_object_of_objects.cf, #\+begin_src cfengine3, .*end_src) >}} + +**Output:** + +{{< CFEngine_include_snippet(classfilterdata_object_of_objects.cf, #\+begin_src\s+example_output\s*, .*end_src) >}} + +**Example (with object of arrays using exogenous key):** + +**Policy:** + +{{< CFEngine_include_snippet(classfilterdata_object_of_arrays_exogenous_key.cf, #\+begin_src cfengine3, .*end_src) >}} + +**Output:** + +{{< CFEngine_include_snippet(classfilterdata_object_of_arrays_exogenous_key.cf, #\+begin_src\s+example_output\s*, .*end_src) >}} + +**Example (with object of objects using exogenous key):** + +**Policy:** + +{{< CFEngine_include_snippet(classfilterdata_object_of_objects_exogenous_key.cf, #\+begin_src cfengine3, .*end_src) >}} + +**Output:** + +{{< CFEngine_include_snippet(classfilterdata_object_of_objects_exogenous_key.cf, #\+begin_src\s+example_output\s*, .*end_src) >}} + **Notes:** This function can accept many types of data parameters _(See [collecting function][Functions#collecting functions])_. From dec61c4e57a1237f169c9a4d81c3b15f76349e8e Mon Sep 17 00:00:00 2001 From: Lars Erik Wik <53906608+larsewi@users.noreply.github.com> Date: Tue, 19 Aug 2025 15:52:57 +0200 Subject: [PATCH 2/2] Updated filenames from examples to correspond with changes in core --- .../reference/functions/classfilterdata.markdown | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/content/reference/functions/classfilterdata.markdown b/content/reference/functions/classfilterdata.markdown index b188a5320..4e5da991f 100644 --- a/content/reference/functions/classfilterdata.markdown +++ b/content/reference/functions/classfilterdata.markdown @@ -63,7 +63,7 @@ If the `data_structure` argument is specified to be: {{< CFEngine_include_snippet(classfilterdata_object_of_arrays.cf, #\+begin_src\s+example_output\s*, .*end_src) >}} -**Example (with object of objects):** +**Example (with object of objects using key inside the object):** **Policy:** @@ -73,25 +73,25 @@ If the `data_structure` argument is specified to be: {{< CFEngine_include_snippet(classfilterdata_object_of_objects.cf, #\+begin_src\s+example_output\s*, .*end_src) >}} -**Example (with object of arrays using exogenous key):** +**Example (with object of arrays using key to the object itself):** **Policy:** -{{< CFEngine_include_snippet(classfilterdata_object_of_arrays_exogenous_key.cf, #\+begin_src cfengine3, .*end_src) >}} +{{< CFEngine_include_snippet(classfilterdata_object_of_arrays_key_to_obj.cf, #\+begin_src cfengine3, .*end_src) >}} **Output:** -{{< CFEngine_include_snippet(classfilterdata_object_of_arrays_exogenous_key.cf, #\+begin_src\s+example_output\s*, .*end_src) >}} +{{< CFEngine_include_snippet(classfilterdata_object_of_arrays_key_to_obj.cf, #\+begin_src\s+example_output\s*, .*end_src) >}} -**Example (with object of objects using exogenous key):** +**Example (with object of objects using key to the object itself):** **Policy:** -{{< CFEngine_include_snippet(classfilterdata_object_of_objects_exogenous_key.cf, #\+begin_src cfengine3, .*end_src) >}} +{{< CFEngine_include_snippet(classfilterdata_object_of_objects_key_to_obj.cf, #\+begin_src cfengine3, .*end_src) >}} **Output:** -{{< CFEngine_include_snippet(classfilterdata_object_of_objects_exogenous_key.cf, #\+begin_src\s+example_output\s*, .*end_src) >}} +{{< CFEngine_include_snippet(classfilterdata_object_of_objects_key_to_obj.cf, #\+begin_src\s+example_output\s*, .*end_src) >}} **Notes:**