Forum: CFEngine Help
Subject: Re: Testing variable types
Author: n...@cmdln.org
Link to topic: https://cfengine.com/forum/read.php?3,25321,25356#msg-25356

I think I wasn't very clear.

I see that in the copbl both  edit_line append_if_no_line(str)
and edit_line append_if_no_lines(list) are present and that they are 
functionally the same. 


bundle edit_line append_if_no_line(str)
{
insert_lines:

 "$(str)"

     comment => "Append a line to the file if it doesn't already exist";
}


bundle edit_line append_if_no_lines(list)
{
insert_lines:

 "$(list)"

   comment => "Append lines to the file if they don't already exist";
}


I think that append_if_no_lines is misleading, because you can pass it either a 
list or a string. Where list iteration is done depends how you are calling it. 
There are no comments indicating how it should be called, and there is nothing 
to encourage its expected usage (passing in a list) or prevent its unexpected 
usage (passing in a string).

Consider the following examples

body common control {

    bundlesequence  => {
                        "main",
                        };

    inputs          => {
                        "cfengine_stdlib.cf",
                        };
}

bundle agent main {

    vars:
        "list1" slist => { "L1i1", "L1i2", "L1i3" };
        "list2" slist => { "L2i1", "L2i2", "L2i3" };

    files:
        "/tmp/test1"
            create => "true",
            edit_line => append_if_no_lines("@(main.list1)");

        "/tmp/test2"
            create => "true",
            edit_line => append_if_no_line("$(list1)");
}


I was trying to figure out what the best approach to amending this in the copbl 
would be, just documentation about how to pass a list, or if there were some 
way to enforce passing a list.

_______________________________________________
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine

Reply via email to