Format function

16 views
Skip to first unread message

Bas van der Vlies

unread,
May 14, 2018, 10:16:02 AM5/14/18
to help-cfengine
I just want to use a function in format(), eg:
* "$(this.bundle): $(with)" with => format("bas %S", readdata("$(template_dir)/$(json_files)", "auto"));

I get all kind of errors:
{{{
error: format() didn't have enough parameters
}}}

The question is this an error or is it not allowed?




--
Bas van der Vlies
| Operations, Support & Development | SURFsara | Science Park 140 | 1098 XG Amsterdam
| T +31 (0) 20 800 1300 | bas.van...@surfsara.nl | www.surfsara.nl |




Vratislav Podzimek

unread,
May 14, 2018, 11:25:42 AM5/14/18
to help-c...@googlegroups.com
On Mon, 2018-05-14 at 16:15 +0200, Bas van der Vlies wrote:
> I just want to use a function in format(), eg:
> * "$(this.bundle): $(with)" with => format("bas %S", readdata("$(template_dir)/$(json_files)", "auto"));
>
> I get all kind of errors:
> {{{
> error: format() didn't have enough parameters
> }}}
>
> The question is this an error or is it not allowed?
Which version of CFEngine are you using?

--
Vratislav
signature.asc

Nick Anderson

unread,
May 14, 2018, 11:33:28 AM5/14/18
to Bas van der Vlies, help-cfengine

Bas van der Vlies <bas.van...@surfsara.nl> writes:

I just want to use a function in format(), eg:
* "$(this.bundle):

(template )/$(json )", "auto")); >

I get all kind of errors:
{{{
error: format() didn't have enough parameters
}}}

>

The question is this an error or is it not allowed?

{
   "Hello": "World"
}

Hi Bas,

It seems like the format() function doesn't accept functions as input yet. Can
you open an issue for this. I believe that the format() function needs
"collecting" behavior.

bundle agent main
{
   reports:
     "CFEngine $(sys.cf_version)";

     "$(this.bundle): $(with)"
        with => format("BAS %S", readdata( "/tmp/example.json", "auto" ));
}
   error: format() didn't have enough parameters
   error: format() didn't have enough parameters
R: CFEngine 3.11.0
   error: format() didn't have enough parameters
   error: format() didn't have enough parameters
R: main: $(with)
   error: format() didn't have enough parameters
   error: format() didn't have enough parameters
   error: format() didn't have enough parameters
   error: format() didn't have enough parameters

Here are some alternate patterns that work as expected with nested functions.

bundle agent main
{
   vars:

     "d" data => readdata( "/tmp/example.json", "auto" );

   reports:
     "CFEngine $(sys.cf_version)";

     "$(this.bundle): $(with)"
        with => format("BAS %S", d );

}
R: CFEngine 3.11.0
R: main: BAS {"Hello":"World"}

bundle agent main
{
   vars:

     "d" data => readdata( "/tmp/example.json", "auto" );

   reports:
     "CFEngine $(sys.cf_version)";

     "$(this.bundle): $(with)"
        with => string_mustache("BAS {{$-top-}}", d );

}
R: CFEngine 3.11.0
R: main: BAS {"Hello":"World"}

bundle agent main
{
   reports:
     "CFEngine $(sys.cf_version)";

     "$(this.bundle): $(with)"
        with => string_mustache("BAS {{$-top-}}", readdata( "/tmp/example.json", "auto" ) );

}
R: CFEngine 3.11.0
R: main: BAS {"Hello":"World"}


Nick Anderson
Doer of things, CFEngine

Bas van der Vlies

unread,
May 14, 2018, 2:43:10 PM5/14/18
to Nick Anderson, help-cfengine
Thanks I will open a issue

--
You received this message because you are subscribed to the Google Groups "help-cfengine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to help-cfengin...@googlegroups.com.
To post to this group, send email to help-c...@googlegroups.com.
Visit this group at https://groups.google.com/group/help-cfengine.
For more options, visit https://groups.google.com/d/optout.
<latex267401RO_6f10a91c2c7637b29ba0bca2d50ee29eb5722324.png>

Bas van der Vlies

unread,
May 14, 2018, 4:52:09 PM5/14/18
to Nick Anderson, help-cfengine
bundle agent main
{
   reports:
     "CFEngine $(sys.cf_version)";

     "$(this.bundle): $(with)"
        with => string_mustache("BAS {{$-top-}}", readdata( "/tmp/example.json", "auto" ) );

Thanks a lot Nick for this suggestion. Very useful the ‘string_mustache’ and easy ;-)

Nick Anderson

unread,
May 14, 2018, 5:20:55 PM5/14/18
to help-cfengine


On Monday, May 14, 2018 at 3:52:09 PM UTC-5, Bas van der Vlies wrote:
bundle agent main
{
   reports:
     "CFEngine $(sys.cf_version)";

     "$(this.bundle): $(with)"
        with => string_mustache("BAS {{$-top-}}", readdata( "/tmp/example.json", "auto" ) );

Thanks a lot Nick for this suggestion. Very useful the ‘string_mustache’ and easy ;-)


:-)
Yes, and don't forget about {{%-top-}} (multi-line JSON representation)

Reply all
Reply to author
Forward
0 new messages