"Fossies" - the Fresh Open Source Software Archive

Member "cfengine-3.15.4/examples/inherit_from.cf" (7 Jun 2021, 1397 Bytes) of package /linux/misc/cfengine-3.15.4.tar.gz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "inherit_from.cf": 3.15.4_vs_3.18.0.

    1 # This example illustrates the use of inherit_from to inherit body attribute
    2 # values from another body.
    3 ###############################################################################
    4 #+begin_src cfengine3
    5 bundle agent __main__
    6 {
    7   files:
    8       "$(this.promise_filename).txt"
    9         create => "true",
   10         template_method => "inline_mustache",
   11         edit_template_string => string_mustache( "Hello World$(const.n)2$(const.n)3$(const.n)4$(const.n)half-way
   12 6$(const.n)7$(const.n)8$(const.n)9$(const.n)Byeeeeeee", '{}');
   13 
   14   reports:
   15       "The first 3 lines of this file are:"
   16         printfile => head_n( "$(this.promise_filename).txt", "3" );
   17 
   18       "The whole file contains:"
   19         printfile => cat( "$(this.promise_filename).txt" );
   20 }
   21 
   22 body printfile head_n(file, lines)
   23 {
   24       # Sets file_to_print the same as cat
   25         inherit_from => cat( $(file) );
   26 
   27       # Overrides number_of_lines from cat
   28         number_of_lines => "$(lines)";
   29 }
   30 body printfile cat(file)
   31 {
   32         file_to_print   => "$(file)";
   33         number_of_lines => "inf";
   34 }
   35 ###############################################################################
   36 #+begin_src example_output
   37 #@ ```
   38 #@ R: The first 3 lines of this file are:
   39 #@ R: Hello World
   40 #@ R: 2
   41 #@ R: 3
   42 #@ R: The whole file contains:
   43 #@ R: Hello World
   44 #@ R: 2
   45 #@ R: 3
   46 #@ R: 4
   47 #@ R: half-way
   48 #@ R: 6
   49 #@ R: 7
   50 #@ R: 8
   51 #@ R: 9
   52 #@ R: Byeeeeeee
   53 #@ ```
   54 #+end_src
   55 
   56