TOML
| source | condition | target |
|---|---|---|
✔ | ✔ | ✔ |
Description
The toml resource reads and writes a single value in a TOML document, addressed by a Dasel selector.
- source
Reads one value out of one file. Only a single file is accepted.
- condition
Compares the value to
value, or to the source output whenvalueis unset.- target
Writes the value at the given key. Files already holding it are reported as up to date and left untouched.
Parameters
| Name | Type | Description | Required |
|---|---|---|---|
| createmissingkey | boolean | “createmissingkey” creates the key when the toml file does not hold it yet. compatible:
default: false remark:
| |
| engine | string | “engine” defines the engine used to manipulate the toml file. compatible:
default: dasel/v1 remark:
example:
| |
| file | string | “file” defines the path of the toml file to use. compatible:
remark:
example:
| |
| files | array | “files” defines the list of toml file paths to use. compatible:
remark:
| |
| key | string | “key” defines the toml key path to use. compatible:
remark:
example:
| |
| query | string | “query” defines an advanced dasel v1 query returning several values. compatible:
remark:
| |
| value | string | “value” defines the value associated with the toml key. compatible:
default: the output of the associated source. | |
| versionfilter | object | “versionfilter” defines the version pattern and its kind, such as “regex”, “semver” or “latest”. compatible:
remark:
| |
| kind | string | “kind” defines the versioning scheme used to select a version. default: latest remark:
example:
| |
| pattern | string | “pattern” defines the version pattern, according to “kind”. default:
remark:
example:
| |
| regex | string | “regex” defines the regular expression extracting the version from each entry. remark:
example:
| |
| replaceall | object | “replaceall” applies a regular expression replacement to each version before filtering. remark:
example: turns “curl-8_15_0” into “curl-8.15.0”. | |
| strict | boolean | “strict” enforces strict semantic versioning rules when parsing versions. default: false remark:
|
file or files is mandatory, as is key or query; missing either aborts the run with wrong spec content. file and files are mutually exclusive.
createmissingkeyTarget only. Creates the key when it does not exist instead of failing. Only works together with
key, and not with thedasel/v3engine (that combination is rejected at validation time withengine "dasel/v3" does not support the parameter "createmissingkey", because the v3 API resolves the key before setting a value).
Note | multiple is deprecated and hidden from the table above. Use a selector returning several values instead. |
Engines
engine selects which version of Dasel parses the file, and the selector syntax is not portable between versions.
| Value | Behaviour |
|---|---|
| Default when |
| Deprecated - every run logs a warning. |
| Current engine. Rejects the leading dot: use |
| Alias resolving to the latest engine, currently |
Warning | query is a dasel/v1 parameter. On dasel/v2 and dasel/v3, a query without a key fails validation with engine "dasel/v3" requires the parameter "key" over "query". On dasel/v1, query is the multi-value form and must be paired with versionfilter in a source. |
Remote files
file accepts https://, http:// and file:// for a source and a condition. A target refuses a URL outright with URL scheme is not supported for TOML target.
Limitations
Dasel rewrites the file from its parsed representation, so comments are dropped on any target that changes something - see tomwright/dasel#178. This bites hardest on hand-maintained files such as netlify.toml or Cargo.toml.
The workaround is to drive the edit with the "File" resource, matching the line with a regular expression so only those bytes are rewritten:
# updatecli.yaml
name: Fallback example with TOML
sources:
hugo:
name: Get latest HUGO version
kind: githubrelease
transformers:
- trimprefix: v
spec:
owner: gohugoio
repository: hugo
token: '{{ requiredEnv "UPDATECLI_GITHUB_TOKEN" }}'
username: '{{ requiredEnv "UPDATECLI_GITHUB_ACTOR" }}'
targets:
netlify:
name: Update Hugo version used on Netlify
kind: file
spec:
file: netlify.toml
matchpattern: HUGO_VERSION = "(.*)"
replacepattern: HUGO_VERSION = "{{ source "hugo" }}"
scmid: default
sourceid: hugo
Example
# updatecli.yaml
name: Basic TOML Example
sources:
local:
name: Get value from toml
kind: toml
spec:
file: pkg/plugins/resources/toml/testdata/data.toml
key: .owner.firstName
conditions:
local:
name: Test value from toml
kind: toml
spec:
file: pkg/plugins/resources/toml/testdata/data.toml
key: .owner.firstName
targets:
local:
name: Ensure owner.firstName is set to John
kind: toml
spec:
file: pkg/plugins/resources/toml/testdata/data.toml
key: .owner.firstName
value: John