Uploaded image for project: 'CFEngine Community'
  1. CFEngine Community
  2. CFE-1924

list_ifelse or similar functionality

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Open
    • Priority: Medium
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Evaluation
    • Labels:
      None

      Description

      From original pull request: https://github.com/cfengine/core/pull/2165

      This is a new function that builds slists similarly to ifelse() but accepting multiple true conditions and splitting each value on \n. It's very convenient for cases where you want to say "build a list with elements x and y on Linux and element z everywhere".

      Empty strings are ignored.

      bundle agent main
      {
        vars:
            "build" slist => list_ifelse("linux",
                                        "abc
      def",
      
                                        "aix",
                                        "ignore",
      
                                        "darwin",
                                        "more
      mac os x
      arguments",
                                        "any",
                                        "any_argument_1",
      
                                        "any",
                                        "any_argument_2",
      
                                        "last
      arguments");
      
            "build_str" string => format("%S", build);
      
        reports:
            "$(this.bundle): built list $(build_str)";
      }
      

      Output on Mac OS X:

      R: main: built list { "more", "mac os x", "arguments", "any_argument_1", "any_argument_2", "last", "arguments" }
      

      However there are also other suggestions, like:

      I could make it an entirely new syntax. The fundamental issue is that the current way to set slists incrementally is not convergent. So we could try something else:

      • a new slist_append vars promise attribute
      • (my preferred way) a new inline syntax like
      "mylist" slist => { linux:: "item1", "item2", !linux:: "item3" };
      

      This ticket is open for discussion on the subject.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                a10040 Kristian Amlie
              • Votes:
                2 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:

                  Summary Panel