1# Copyright 2021 Northern.tech AS 2 3# This file is part of CFEngine 3 - written and maintained by Northern.tech AS. 4 5# This program is free software; you can redistribute it and/or modify it 6# under the terms of the GNU General Public License as published by the 7# Free Software Foundation; version 3. 8 9# This program 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 12# GNU General Public License for more details. 13 14# You should have received a copy of the GNU General Public License 15# along with this program; if not, write to the Free Software 16# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 17 18# To the extent this program is licensed as part of the Enterprise 19# versions of Cfengine, the applicable Commercial Open Source License 20# (COSL) may apply to this file if you as a licensee so wish it. See 21# included file COSL.txt. 22 23#+begin_src cfengine3 24bundle agent main 25{ 26 vars: 27 "todo" slist => { "a 1", "b 2", "c 3" }; 28 # Here, `with` is the canonified version of $(todo), letting us avoid an 29 # intermediate canonification array. 30 "$(with)" string => "$(todo)", with => canonify($(todo)); 31 32 "complex" data => ' 33{ 34 "x": 200, 35 "y": [ 1, 2, null, true, false ] 36} 37'; 38 39 reports: 40 "For iterable '$(todo)' we created variable '$(with)' and its value is '$(todo)'" 41 with => canonify($(todo)); 42 43 "We can print a data container compactly without creating a temporary variable: $(with)" 44 with => format("%S", complex); 45 46 "We can print a data container fully without creating a temporary variable: $(with)" 47 with => storejson(complex); 48} 49 50#+end_src 51############################################################################### 52#+begin_src example_output 53#@ ``` 54#@ R: For iterable 'a 1' we created variable 'a_1' and its value is 'a 1' 55#@ R: For iterable 'b 2' we created variable 'b_2' and its value is 'b 2' 56#@ R: For iterable 'c 3' we created variable 'c_3' and its value is 'c 3' 57#@ R: We can print a data container compactly without creating a temporary variable: {"x":200,"y":[1,2,null,true,false]} 58#@ R: We can print a data container fully without creating a temporary variable: { 59#@ "x": 200, 60#@ "y": [ 61#@ 1, 62#@ 2, 63#@ null, 64#@ true, 65#@ false 66#@ ] 67#@ } 68#@ ``` 69#+end_src 70