Skip to content

Commit

Permalink
feat: improve jp docs
Browse files Browse the repository at this point in the history
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
  • Loading branch information
eddycharly committed Sep 26, 2024
1 parent 8b1ade5 commit a8fc6db
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 115 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/go-logr/logr v1.4.2
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
github.com/hashicorp/go-getter v1.7.6
github.com/jmespath-community/go-jmespath v1.1.2-0.20240627155901-bdbb290f571e
github.com/jmespath-community/go-jmespath v1.1.2-0.20240919193755-5e4e8ae73c8a
github.com/jstemmer/go-junit-report/v2 v2.1.0
github.com/kudobuilder/kuttl v0.19.0
github.com/kyverno/kyverno-json v0.0.4-0.20240730143747-aade3d42fc0e
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,8 @@ github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/jinzhu/copier v0.4.0 h1:w3ciUoD19shMCRargcpm0cm91ytaBhDvuRpz1ODO/U8=
github.com/jinzhu/copier v0.4.0/go.mod h1:DfbEm0FYsaqBcKcFuvmOZb218JkPGtvSHsKg8S8hyyg=
github.com/jmespath-community/go-jmespath v1.1.2-0.20240627155901-bdbb290f571e h1:e9zkuKm+DRAW1xGu90nokWkxOAWhOPYkMNojmTmtvPE=
github.com/jmespath-community/go-jmespath v1.1.2-0.20240627155901-bdbb290f571e/go.mod h1:YlGIjNhh2pH+qyifSpVtQQIbI8YUoVytgZyKBVAMVX4=
github.com/jmespath-community/go-jmespath v1.1.2-0.20240919193755-5e4e8ae73c8a h1:baQnVszUF+wENqBnqJDlgmSIBpJLMqQE0i+hICMZ9sI=
github.com/jmespath-community/go-jmespath v1.1.2-0.20240919193755-5e4e8ae73c8a/go.mod h1:VL6C6nwf/wRivvXAjziX9yFRVmvOC1qzERc8RTQ0tv4=
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
Expand Down
216 changes: 108 additions & 108 deletions website/docs/reference/jp/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,123 +8,123 @@

## built-in functions

| Name | Signature |
|---|---|
| abs | `abs(number)` |
| avg | `avg(array[number])` |
| ceil | `ceil(number)` |
| contains | `contains(array|string, any)` |
| ends_with | `ends_with(string, string)` |
| find_first | `find_first(string, string, number, number)` |
| find_last | `find_last(string, string, number, number)` |
| floor | `floor(number)` |
| from_items | `from_items(array[array])` |
| group_by | `group_by(array, expref)` |
| items | `items(object)` |
| join | `join(string, array[string])` |
| keys | `keys(object)` |
| length | `length(string|array|object)` |
| lower | `lower(string)` |
| map | `map(expref, array)` |
| max | `max(array[number]|array[string])` |
| max_by | `max_by(array, expref)` |
| merge | `merge(object)` |
| min | `min(array[number]|array[string])` |
| min_by | `min_by(array, expref)` |
| not_null | `not_null(any)` |
| pad_left | `pad_left(string, number, string)` |
| pad_right | `pad_right(string, number, string)` |
| replace | `replace(string, string, string, number)` |
| reverse | `reverse(array|string)` |
| sort | `sort(array[string]|array[number])` |
| sort_by | `sort_by(array, expref)` |
| split | `split(string, string, number)` |
| starts_with | `starts_with(string, string)` |
| sum | `sum(array[number])` |
| to_array | `to_array(any)` |
| to_number | `to_number(any)` |
| to_string | `to_string(any)` |
| trim | `trim(string, string)` |
| trim_left | `trim_left(string, string)` |
| trim_right | `trim_right(string, string)` |
| type | `type(any)` |
| upper | `upper(string)` |
| values | `values(object)` |
| zip | `zip(array, array)` |
| Name | Signature | Description |
|---|---|---|
| abs | `abs(number)` | Returns the absolute value of the provided argument. |
| avg | `avg(array[number])` | Returns the average of the elements in the provided array. An empty array will produce a return value of null. |
| ceil | `ceil(number)` | Returns the next highest integer value by rounding up if necessary. |
| contains | `contains(array\|string, any)` | Returns `true` if the given subject contains the provided search value. If the subject is an array, this function returns `true` if one of the elements in the array is equal to the provided search value. If the provided subject is a string, this function returns `true` if the string contains the provided search argument. |
| ends_with | `ends_with(string, string)` | Reports whether the given string ends with the provided suffix argument. |
| find_first | `find_first(string, string, number, number)` | |
| find_last | `find_last(string, string, number, number)` | |
| floor | `floor(number)` | Returns the next lowest integer value by rounding down if necessary. |
| from_items | `from_items(array[array])` | |
| group_by | `group_by(array, expref)` | |
| items | `items(object)` | Converts a given object into an array of key-value pairs. |
| join | `join(string, array[string])` | Returns all of the elements from the provided array joined together using the glue argument as a separator between each. |
| keys | `keys(object)` | Returns an array containing the keys of the provided object. |
| length | `length(string\|array\|object)` | Returns the length of the given argument. If the argument is a string this function returns the number of code points in the string. If the argument is an array this function returns the number of elements in the array. If the argument is an object this function returns the number of key-value pairs in the object. |
| lower | `lower(string)` | Returns the given string with all Unicode letters mapped to their lower case. |
| map | `map(expref, array)` | Transforms elements in a given array and returns the result. |
| max | `max(array[number]\|array[string])` | Returns the highest found element in the provided array argument. An empty array will produce a return value of null. |
| max_by | `max_by(array, expref)` | Returns the highest found element using a custom expression to compute the associated value for each element in the input array. |
| merge | `merge(object)` | Meges a list of objects together and returns the result. |
| min | `min(array[number]\|array[string])` | Returns the lowest found element in the provided array argument. |
| min_by | `min_by(array, expref)` | Returns the lowest found element using a custom expression to compute the associated value for each element in the input array. |
| not_null | `not_null(any)` | Returns the first non null element in the input array. |
| pad_left | `pad_left(string, number, string)` | |
| pad_right | `pad_right(string, number, string)` | |
| replace | `replace(string, string, string, number)` | Returns a copy of the input string with instances of old string argument replaced by new string argument. |
| reverse | `reverse(array\|string)` | Reverses the input string or array and returns the result. |
| sort | `sort(array[string]\|array[number])` | This function accepts an array argument and returns the sorted elements as an array. |
| sort_by | `sort_by(array, expref)` | This function accepts an array argument and returns the sorted elements as an array using a custom expression to compute the associated value for each element. |
| split | `split(string, string, number)` | Slices input string into substrings separated by a string argument and returns an array of the substrings between those separators. |
| starts_with | `starts_with(string, string)` | Reports whether the input string begins with the provided string prefix argument. |
| sum | `sum(array[number])` | Returns the sum of all numbers contained in the provided array. |
| to_array | `to_array(any)` | |
| to_number | `to_number(any)` | Returns the parsed number. |
| to_string | `to_string(any)` | The JSON encoded value of the given argument. |
| trim | `trim(string, string)` | |
| trim_left | `trim_left(string, string)` | |
| trim_right | `trim_right(string, string)` | |
| type | `type(any)` | Returns the JavaScript type of the given argument as a string value. |
| upper | `upper(string)` | Returns the given string with all Unicode letters mapped to their upper case. |
| values | `values(object)` | Returns the values of the provided object. |
| zip | `zip(array, array)` | |

## kyverno-json functions

| Name | Signature |
|---|---|
| at | `at(array, any)` |
| concat | `concat(string, string)` |
| json_parse | `json_parse(string)` |
| wildcard | `wildcard(string, string)` |
| Name | Signature | Description |
|---|---|---|
| at | `at(array, any)` | |
| concat | `concat(string, string)` | |
| json_parse | `json_parse(string)` | |
| wildcard | `wildcard(string, string)` | |

## kyverno functions

| Name | Signature |
|---|---|
| compare | `compare(string, string)` |
| equal_fold | `equal_fold(string, string)` |
| replace | `replace(string, string, string, number)` |
| replace_all | `replace_all(string, string, string)` |
| to_upper | `to_upper(string)` |
| to_lower | `to_lower(string)` |
| trim | `trim(string, string)` |
| trim_prefix | `trim_prefix(string, string)` |
| split | `split(string, string)` |
| regex_replace_all | `regex_replace_all(string, string|number, string|number)` |
| regex_replace_all_literal | `regex_replace_all_literal(string, string|number, string|number)` |
| regex_match | `regex_match(string, string|number)` |
| pattern_match | `pattern_match(string, string|number)` |
| label_match | `label_match(object, object)` |
| to_boolean | `to_boolean(string)` |
| add | `add(any, any)` |
| sum | `sum(array)` |
| subtract | `subtract(any, any)` |
| multiply | `multiply(any, any)` |
| divide | `divide(any, any)` |
| modulo | `modulo(any, any)` |
| round | `round(number, number)` |
| base64_decode | `base64_decode(string)` |
| base64_encode | `base64_encode(string)` |
| time_since | `time_since(string, string, string)` |
| time_now | `time_now()` |
| time_now_utc | `time_now_utc()` |
| path_canonicalize | `path_canonicalize(string)` |
| truncate | `truncate(string, number)` |
| semver_compare | `semver_compare(string, string)` |
| parse_json | `parse_json(string)` |
| parse_yaml | `parse_yaml(string)` |
| lookup | `lookup(object|array, string|number)` |
| items | `items(object|array, string, string)` |
| object_from_lists | `object_from_lists(array, array)` |
| random | `random(string)` |
| x509_decode | `x509_decode(string)` |
| time_to_cron | `time_to_cron(string)` |
| time_add | `time_add(string, string)` |
| time_parse | `time_parse(string, string)` |
| time_utc | `time_utc(string)` |
| time_diff | `time_diff(string, string)` |
| time_before | `time_before(string, string)` |
| time_after | `time_after(string, string)` |
| time_between | `time_between(string, string, string)` |
| time_truncate | `time_truncate(string, string)` |
| Name | Signature | Description |
|---|---|---|
| compare | `compare(string, string)` | |
| equal_fold | `equal_fold(string, string)` | |
| replace | `replace(string, string, string, number)` | |
| replace_all | `replace_all(string, string, string)` | |
| to_upper | `to_upper(string)` | |
| to_lower | `to_lower(string)` | |
| trim | `trim(string, string)` | |
| trim_prefix | `trim_prefix(string, string)` | |
| split | `split(string, string)` | |
| regex_replace_all | `regex_replace_all(string, string\|number, string\|number)` | |
| regex_replace_all_literal | `regex_replace_all_literal(string, string\|number, string\|number)` | |
| regex_match | `regex_match(string, string\|number)` | |
| pattern_match | `pattern_match(string, string\|number)` | |
| label_match | `label_match(object, object)` | |
| to_boolean | `to_boolean(string)` | |
| add | `add(any, any)` | |
| sum | `sum(array)` | |
| subtract | `subtract(any, any)` | |
| multiply | `multiply(any, any)` | |
| divide | `divide(any, any)` | |
| modulo | `modulo(any, any)` | |
| round | `round(number, number)` | |
| base64_decode | `base64_decode(string)` | |
| base64_encode | `base64_encode(string)` | |
| time_since | `time_since(string, string, string)` | |
| time_now | `time_now()` | |
| time_now_utc | `time_now_utc()` | |
| path_canonicalize | `path_canonicalize(string)` | |
| truncate | `truncate(string, number)` | |
| semver_compare | `semver_compare(string, string)` | |
| parse_json | `parse_json(string)` | |
| parse_yaml | `parse_yaml(string)` | |
| lookup | `lookup(object\|array, string\|number)` | |
| items | `items(object\|array, string, string)` | |
| object_from_lists | `object_from_lists(array, array)` | |
| random | `random(string)` | |
| x509_decode | `x509_decode(string)` | |
| time_to_cron | `time_to_cron(string)` | |
| time_add | `time_add(string, string)` | |
| time_parse | `time_parse(string, string)` | |
| time_utc | `time_utc(string)` | |
| time_diff | `time_diff(string, string)` | |
| time_before | `time_before(string, string)` | |
| time_after | `time_after(string, string)` | |
| time_between | `time_between(string, string, string)` | |
| time_truncate | `time_truncate(string, string)` | |

## chainsaw functions

| Name | Signature |
|---|---|
| env | `env(string)` |
| x_k8s_get | `x_k8s_get(any, string, string, string, string)` |
| x_k8s_list | `x_k8s_list(any, string, string, string)` |
| x_k8s_exists | `x_k8s_exists(any, string, string, string, string)` |
| x_k8s_resource_exists | `x_k8s_resource_exists(any, string, string)` |
| x_k8s_server_version | `x_k8s_server_version(any)` |
| x_metrics_decode | `x_metrics_decode(string)` |
| trim_space | `trim_space(string)` |
| as_string | `as_string(any)` |
| Name | Signature | Description |
|---|---|---|
| env | `env(string)` | |
| x_k8s_get | `x_k8s_get(any, string, string, string, string)` | |
| x_k8s_list | `x_k8s_list(any, string, string, string)` | |
| x_k8s_exists | `x_k8s_exists(any, string, string, string, string)` | |
| x_k8s_resource_exists | `x_k8s_resource_exists(any, string, string)` | |
| x_k8s_server_version | `x_k8s_server_version(any)` | |
| x_metrics_decode | `x_metrics_decode(string)` | |
| trim_space | `trim_space(string)` | |
| as_string | `as_string(any)` | |

## examples

Expand Down
8 changes: 4 additions & 4 deletions website/jp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ func main() {
}

func printFunctions(funcs ...jpfunctions.FunctionEntry) {
fmt.Println("| Name | Signature |")
fmt.Println("|---|---|")
fmt.Println("| Name | Signature | Description |")
fmt.Println("|---|---|---|")
for _, function := range funcs {
fmt.Println("|", function.Name, "|", "`"+functionString(function)+"`", "|")
fmt.Println("|", function.Name, "|", "`"+functionString(function)+"`", "|", function.Description, "|")
}
}

Expand All @@ -59,7 +59,7 @@ func functionString(f jpfunctions.FunctionEntry) string {
for _, t := range a.Types {
aTypes = append(aTypes, string(t))
}
args = append(args, strings.Join(aTypes, "|"))
args = append(args, strings.Join(aTypes, "\\|"))
}
output := fmt.Sprintf("%s(%s)", f.Name, strings.Join(args, ", "))
return output
Expand Down

0 comments on commit a8fc6db

Please sign in to comment.