diff --git a/examples/lang/class-include.mcl b/examples/lang/class-include.mcl new file mode 100644 index 00000000..60443a80 --- /dev/null +++ b/examples/lang/class-include.mcl @@ -0,0 +1,22 @@ +import "fmt" +class foo { + print "foo1" { + msg => "inside foo", + + Meta:autogroup => false, + } +} + +class bar($a, $b) { # a parameterized class + print "bar-"+ $a { + msg => fmt.printf("inside bar: %s", $b), + + Meta:autogroup => false, + } +} + +include foo +include foo # duplicate +include bar("b1", "hello") +include bar("b2", "world") +include bar("b2", "world") # duplicate diff --git a/examples/lang/cron0.mcl b/examples/lang/cron0.mcl index 8e587892..65bd18a7 100644 --- a/examples/lang/cron0.mcl +++ b/examples/lang/cron0.mcl @@ -1,9 +1,9 @@ cron "purpleidea-oneshot" { - session => true, - trigger => "OnBootSec", - time => "60", + session => true, + trigger => "OnBootSec", + time => "60", } svc "purpleidea-oneshot" { - session => true, + session => true, } diff --git a/examples/lang/cron1.mcl b/examples/lang/cron1.mcl index 92f52c92..8da30e3c 100644 --- a/examples/lang/cron1.mcl +++ b/examples/lang/cron1.mcl @@ -1,3 +1,3 @@ cron "purpleidea-oneshot" { - state => "absent", + state => "absent", } diff --git a/examples/lang/cron2.mcl b/examples/lang/cron2.mcl index 1c5a13e0..980a27c1 100644 --- a/examples/lang/cron2.mcl +++ b/examples/lang/cron2.mcl @@ -1,6 +1,6 @@ cron "purpleidea-oneshot" { - trigger => "OnUnitActiveSec", - time => "2minutes", + trigger => "OnUnitActiveSec", + time => "2minutes", } svc "purpleidea-oneshot" {} diff --git a/examples/lang/cron3.mcl b/examples/lang/cron3.mcl index 658a5b8b..978cf700 100644 --- a/examples/lang/cron3.mcl +++ b/examples/lang/cron3.mcl @@ -1,13 +1,13 @@ $home = getenv("HOME") cron "purpleidea-oneshot" { - session => true, - trigger => "OnCalendar", - time => "*:*:0", + session => true, + trigger => "OnCalendar", + time => "*:*:0", } svc "purpleidea-oneshot" { - session => true, + session => true, } file printf("%s/.config/systemd/user/purpleidea-oneshot.service", $home) {} diff --git a/examples/lang/cron4.mcl b/examples/lang/cron4.mcl index 86ebf2a8..5a6357dc 100644 --- a/examples/lang/cron4.mcl +++ b/examples/lang/cron4.mcl @@ -1,17 +1,17 @@ $home = getenv("HOME") cron "purpleidea-oneshot" { - state => "absent", - session => true, - trigger => "OnCalendar", - time => "*:*:0", + state => "absent", + session => true, + trigger => "OnCalendar", + time => "*:*:0", } svc "purpleidea-oneshot" { - state => "stopped", - session => true, + state => "stopped", + session => true, } file printf("%s/.config/systemd/user/purpleidea-oneshot.service", $home) { - state => "absent", + state => "absent", } diff --git a/examples/lang/docker_container0.mcl b/examples/lang/docker_container0.mcl index b5f3f01a..93eed38f 100644 --- a/examples/lang/docker_container0.mcl +++ b/examples/lang/docker_container0.mcl @@ -1,6 +1,6 @@ docker:container "mgmt-nginx" { - state => "running", - image => "nginx", - cmd => ["nginx", "-g", "daemon off;",], - ports => {"tcp" => {80 => 8080,},}, + state => "running", + image => "nginx", + cmd => ["nginx", "-g", "daemon off;",], + ports => {"tcp" => {80 => 8080,},}, } diff --git a/examples/lang/duplicate-error.mcl b/examples/lang/duplicate-error.mcl new file mode 100644 index 00000000..b2e7a610 --- /dev/null +++ b/examples/lang/duplicate-error.mcl @@ -0,0 +1,8 @@ +# this combination should error +pkg "cowsay" { + state => "uninstalled", +} + +pkg "cowsay" { + state => "installed", +} diff --git a/examples/lang/duplicate.mcl b/examples/lang/duplicate.mcl new file mode 100644 index 00000000..62f694de --- /dev/null +++ b/examples/lang/duplicate.mcl @@ -0,0 +1,7 @@ +pkg "cowsay" { + state => "newest", +} + +pkg "cowsay" { + state => "installed", +} diff --git a/examples/lang/env-bad.mcl b/examples/lang/env-bad.mcl new file mode 100644 index 00000000..e4a2b288 --- /dev/null +++ b/examples/lang/env-bad.mcl @@ -0,0 +1,8 @@ +import "fmt" +import "sys" + +$x = sys.getenv("TEST", "321") + +print "print1" { + msg => fmt.printf("TEST is: %s", $x), +} diff --git a/examples/lang/iteration1.mcl b/examples/lang/iteration1.mcl new file mode 100644 index 00000000..bcc51a5c --- /dev/null +++ b/examples/lang/iteration1.mcl @@ -0,0 +1,21 @@ +# single resource +print "name" {} + +# single resource, defined by list variable +$names = ["hey", "there",] +print $names { + Meta:autogroup => false, +} + +# multiples resources, defined by list +print ["hello", "world",] { + Meta:autogroup => false, + Depend => Print[$names], +} + +$morenames = ["wow", "cool", "amazing",] +print $morenames { + Meta:autogroup => false, +} + +Print[$names] -> Print[$morenames] diff --git a/examples/lang/nspawn1.mcl b/examples/lang/nspawn1.mcl new file mode 100644 index 00000000..f787c39c --- /dev/null +++ b/examples/lang/nspawn1.mcl @@ -0,0 +1,3 @@ +nspawn "sid-chroot" { + state => "running", +} diff --git a/examples/lang/nspawn2.mcl b/examples/lang/nspawn2.mcl new file mode 100644 index 00000000..422b510a --- /dev/null +++ b/examples/lang/nspawn2.mcl @@ -0,0 +1,3 @@ +nspawn "Fedora-Cloud-Base-27-1.6.x86_64" { + state => "running", +} diff --git a/examples/lang/readfile1.mcl b/examples/lang/readfile1.mcl index fb410281..1610de48 100644 --- a/examples/lang/readfile1.mcl +++ b/examples/lang/readfile1.mcl @@ -1,6 +1,6 @@ import "os" -# this copies the contents from /tmp/foo and puts them in /tmp/output +# this copies the contents from /tmp/input and puts them in /tmp/output file "/tmp/output" { - content => os.readfile("/tmp/foo"), + content => os.readfile("/tmp/input"), } diff --git a/examples/lang/virt2.mcl b/examples/lang/virt2.mcl index 1d3f8106..fc2beeb9 100644 --- a/examples/lang/virt2.mcl +++ b/examples/lang/virt2.mcl @@ -31,8 +31,8 @@ virt "mgmt4" { # can't add this part until we fix the unification bug #disk => [ # struct{ - # source => "~/.local/share/libvirt/images/fedora-23-scratch.qcow2", - # type => "qcow2", + # source => "~/.local/share/libvirt/images/fedora-23-scratch.qcow2", + # type => "qcow2", # }, #], # add the rest for unification bug