argo-expr

command module
v1.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 5, 2023 License: MIT Imports: 8 Imported by: 0

README

Argo workflows expression tester

Argo has a complex expression language to modify parameters in its workflows

It is difficult for a go novices to figure out how these work and what functions can be used.

This CLI provides a way to test the expressions before submitting the workflow to argo, it dumps failure information

Installation

go install github.com/blacha/argo-expr@latest

Usage

Add 1 to a number
$ argo-expr "{{=asInt(inputs.parameters.name) + 1}}" --value inputs.parameters.name="1"
2
Create a sha256sum
$ argo-expr '{{=sprig.sha256sum("hello world")}}'
b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9

$ argo-expr '{{=sprig.sha256sum(inputs.parameters.value)}}' --value inputs.parameters.value="hello world"
b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9
load from file

Read a JSON input file and compute the output

{
  "template": "hello world 1+1:{{= 1+1 }} i:{{= inputs.parameters.number }}",
  "values": {
    "inputs.parameters.number": "4"
  }
}
$ argo-expr --from-file ./input.json
hello world 1+1:2 i:4

Both values and the expression from the file can be overridden with --value or expression.

$ argo-expr --from-file ./input.json --value inputs.parameters.number=1
hello world 1+1:2 i:2

Override input expression

$ argo-expr --from-file ./input.json "i:{{=asInt(inputs.parameters.number)+3}}"
i:7
Error logs

When a template fails to run a somewhat helpful error message is displayed

$ argo-expr "{{=asInt('hello')}}"

failed to evaluate expression: strconv.ParseInt: parsing "hello": invalid syntax (1:1)
 | asInt('hello')
 | ^

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL