birchb1024 / goyamp Goto Github PK
View Code? Open in Web Editor NEWThe Macro-processor for YAML and JSON
Home Page: https://github.com/birchb1024/goyamp
License: GNU General Public License v3.0
The Macro-processor for YAML and JSON
Home Page: https://github.com/birchb1024/goyamp
License: GNU General Public License v3.0
Quote the Azdo documents:
Pipelines doesn't support all YAML features. Unsupported features include anchors, complex keys, and sets. Also, unlike standard YAML, Azure Pipelines depends on seeing stage, job, task, or a task shortcut like script as the first key in a mapping.
This currently leads to errors with pipelines generated by goyamp. e.g.
/azure-pipelines.yml (Line: 2, Col: 3): Unexpected value 'displayName'
Suggest adding an ordering directive to force order in sorts():
map-order:
- [stage, job, task, script]
- displayName
The higher up the list the earlier it's printed.
add --output lines option
Use heuristics - throw error if unable to handle structure.
Change builtin so that it returns an integer if possible.
Example:
$ echo '{panic: 44}' | goyamp ; echo $? Error: 44 0
Should be:
$ echo '{panic: 44}' | goyamp ; echo $? Error: 44 2
Instead of outputting a text file, add an interface to the API which allows the result of the expansions be returned to the caller as a struct, which they can use to access from inside their programs.
The main use case is using Goyamp as the config file loader. In particular, use this for the promus and shapi projects.
Kustomize has sed-like features which allow matching on a subtree (patch) or on maps with multiple keys, unlike Goyamp which currently matches on a single key. This enhancement would add rewrite logic in a similar way. Perhaps something like this:
define:
$some-input:
foo:
alpha: 23
bar:
quux:
---
defmultimacro:
where:
id: 23
name: someresource
args: [$this]
value:
$this.id
name: file-resource
---
$some-input
Outputs
foo:
id: 23
name: file-resource
It's a start.
Kustomize has sed-like features which allow matching on a subtree (patch) or on maps with multiple keys, unlike Goyamp which currently matches on a single key. This enhancement would add rewrite logic in a similar way. Perhaps something like this:
define:
$some-input:
foo:
alpha: 23
bar:
quux:
---
patch:
- $some-input
- foo:
bar: 42
Outputs
foo:
alpha: 23
bar: 42
Example:
foo:
a: 1
b: 2
---
repeat:
for: [$key, $value]
in: foo
body:
- key = {{ $key }}, value = {{ $value }}
Or with just the keys:
---
repeat:
for: $key
in: foo
body:
- key = {{ key }}, value = {{ foo.$key }}
We currently get
Error: Syntax error in repeat 'in' is not a seqeunce, got "foo" in { repeat : { body : [ key = {{ key }}, value = {{ foo.$key }} ] , for : $key , in : foo } }
Hi again, and thanks for pointing me here. The example in
yamp issue 13 works as advertised for me with goyamp. One more question though: Is it possible to do something like this instead?
#foo.yaml is same as before
- include [foo.yaml]
---
- defmacro:
name: bar
args: [arg1, arg2, newArg]
value:
"{{arg1}}_{{arg2}}":
- thisistoplevel: "OK"
- {foo: {fooarg1: "{{arg1}}", fooarg2: "{{arg2}}", fooarg3: nested}}
---
- { bar: {arg1: bogus, arg2: example, newArg: 1}}
When I try to do this, it doesn't recognize the 'include' statement, and in turn doesn't expand the foo...
item.
VAR=cn=a,ou=n=ou=c
is rendered as VAR: cn
when it should be VAR: cn=a,ou=n=ou=c
As a JavaScript programmer I would like to embed JavaScript in the macros so that I can write complex expansions or reductions in JavaScript. Example:
JavaScript:
args: $some-variables
script:
result = javascript_function(args)
Need to add metadata to the conversion to Lua and back to Golang in the gopherlua
builtin. This will allow programs such as deepmerge.lua
to be upgraded to return the correct type of empty table as either []
or {}
as required. Currently deepmerge.lua
defaults to {}
(mapy) when it converts an empty table to Golang.
Proposed: Add metatables in globals "seqy" and "mapy" and assign these to the Lua tables on input. Lua programs can call getmetatable(T) to get the original type. The metatables can be used in the usual Lua way for methods etc.
Update
deepmerge.lua
to preserve array/map types from the the inputs especially for empty collections.
Supposing we want to put the Goyamp output into a SQL database, or more likely, process it with Awk. There already standalone programs which do this, leverage their code. Prior art is https://github.com/tomnomnom/gron. Maybe add a note in the Goyamp documentation for this use case.
Example: A JSON response containing a long integer
{"issued_at" : 1619580789 }
is returned as a float64 ie
issued_at: 1.619580789E+09
Which is very annoying to say the least.
Consider this case:
define:
$data1:
atom1: 12
atom2: 13
$data2:
items:
atom2
---
$data1,$data2.items
We get an error
Error: Subvariable value { items : atom2 } for not string or int in $data1.$data2.items
because this is being interpreted as `$data1,($data2).items.atom2
The workaround is to declare an intermediate variable:
define:
$data1:
atom1: 12
atom2: 13
$data2:
items:
atom2
---
define:
$inter: $data2.items
---
$data1.$inter
This enhancement is to add sub-expressions to make the evaluation order explicit such as
$data1.[$data2.items]
Thereby eliminating the intermediate variable.
Given this
defmacro:
name: ifdef
args: $varname
body: 12
---
ifdef: {quote: Foob}
Fails with:
Error: runtime error: invalid memory address or nil pointer dereference
github.com/birchb1024/goyamp.(*Expander).ExpandStream.func1
/Users/bill.birch/wo/github.com/birchb1024/goyamp/api.go:68
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.