sourceconditiontarget

✔

✔

✔

Description

The csv resource reads and writes a single cell in a CSV file. Rows are addressed by index and columns by header name through a Dasel selector, so .[0].firstname is the firstname column of the first data row.

source

Reads one cell out of one file. Only a single file is accepted.

condition

Compares the cell to value, or to the source output when value is unset.

target

Writes the value into the cell. Files already holding it are reported as up to date and left untouched.

Parameters

NameTypeDescriptionRequired
commainteger

“comma” defines the csv separator character.

compatible:

  • source
  • condition
  • target

default: ,

commentinteger

“comment” defines the csv comment character.

compatible:

  • source
  • condition
  • target

default: #

enginestring

“engine” defines the engine used to manipulate the csv file.

compatible:

  • source
  • condition
  • target

default: dasel/v1

remark:

  • accepted values are “dasel/v1”, “dasel/v2”, “dasel/v3” and “dasel”.
  • “dasel” is the latest dasel engine, currently dasel v3.
  • “dasel/v1” and “dasel/v2” are deprecated in favor of “dasel/v3”.

example:

  • engine: dasel/v3
filestring

“file” defines the path of the csv file.

compatible:

  • source
  • condition
  • target

remark:

  • “file” and “files” are mutually exclusive.
  • a “file://” prefix is removed.
  • the schemes “https://” and “http://” are not supported in a target.
filesarray

“files” defines the list of csv file paths.

compatible:

  • condition
  • target

remark:

  • “file” and “files” are mutually exclusive.
keystring

“key” defines the csv query.

compatible:

  • source
  • condition
  • target

remark:

  • “key” or “query” is required.
  • the engines “dasel/v2” and “dasel/v3” require “key” instead of “query”.
querystring

“query” defines an advanced csv query, returning several results.

compatible:

  • source
  • condition
  • target

remark:

  • it overrides “key”.
  • only supported by the engine “dasel/v1”.
  • with the engine “dasel/v1”, “query” and “versionfilter” must be used together in a source.
valuestring

“value” defines the csv value.

compatible:

  • condition
  • target

default: the output of the associated source.

versionfilterobject

“versionfilter” defines the version pattern and its kind, such as regex, semver or latest.

compatible:

  • source

default: kind: latest

remark:

  • with the engine “dasel/v1”, “query” and “versionfilter” must be used together.
    kindstring

“kind” defines the versioning scheme used to select a version.

default: latest

remark:

  • accepted values are “latest”, “semver”, “regex”, “regex/semver”, “time”, “regex/time”, “lex” and “pep440”.
  • “latest” returns the last version of the list.
  • “lex” sorts the versions lexicographically and returns the last one.
  • “pep440” follows https://peps.python.org/pep-0440/

example:

  • kind: semver
    patternstring

“pattern” defines the version pattern, according to “kind”.

default:

  • latest: “latest”
  • semver and pep440: “*”
  • regex: “.*”
  • time and regex/time: “2006-01-02”

remark:

  • for “latest”, “latest” returns the last version, any other value must match a version exactly.
  • for “semver” and “regex/semver”, it is a semantic versioning constraint.
  • for “pep440”, it is a pep440 version specifier.
  • for “regex”, it is a regular expression.
  • for “time” and “regex/time”, it is a Go date layout.
  • ignored by “lex”.

example:

  • pattern: ~1.2
  • pattern: “>=1.0.0 <2.0.0”
  • pattern: ^v\d+.\d+.\d+$
    regexstring

“regex” defines the regular expression extracting the version from each entry.

remark:

  • only used by the kinds “regex/semver” and “regex/time”.
  • the value of the first capture group is used as the version.

example:

  • regex: ^v(\d+.\d+.\d+)$
    replaceallobject

“replaceall” applies a regular expression replacement to each version before filtering.

remark:

  • only used by the kinds “regex”, “regex/semver” and “regex/time”.
  • the replacement runs before “pattern” or “regex” is evaluated.

example:

replaceall:
  pattern: "_"
  replacement: "."

turns “curl-8_15_0” into “curl-8.15.0”.

    strictboolean

“strict” enforces strict semantic versioning rules when parsing versions.

default: false

remark:

  • only used by the kinds “semver” and “regex/semver”.

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.

Note
multiple is deprecated and hidden from the table above. Use a selector returning several values instead.

Separator and comment characters

comma and comment are Go runes, not strings. They must be given as the decimal code point of the character, so a semicolon-separated file is comma: 59, not comma: ";":

spec:
  file: data.csv
  key: .[0].version
  comma: 59      # ";" - 44 is "," (the default), 9 is a tab

Passing the character itself aborts the run before the pipeline starts:

error while cleaning config: failed to create resource csv: decoding failed due to the following error(s):
'Comma' expected type 'int32', got unconvertible type 'string'

comment works the same way and defaults to #, which is code point 35.

Engines

engine selects which version of Dasel parses the file, and the selector syntax is not portable between versions.

ValueBehaviour

dasel/v1

Default when engine is unset. Deprecated - every run logs a warning.

dasel/v2

Deprecated - every run logs a warning.

dasel/v3

Current engine. Rejects the leading dot: use [0].firstname, not .[0].firstname.

dasel

Alias resolving to the latest engine, currently dasel/v3.

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:

URL scheme is not supported for CSV target: "https://example.com/data.csv"

Limitations

Dasel rewrites the file from its parsed representation, so comments are dropped on any target that changes something - see tomwright/dasel#178. Formatting details such as quoting style are normalised the same way.

When that matters, drive the edit with the "File" resource and a matchpattern/replacepattern pair instead, which rewrites only the bytes that changed.

Example

# updatecli.yaml
name: CSV manipulation examples

sources:
  default:
    name: Basic get query
    kind: csv
    spec:
      file: pkg/plugins/resources/csv/testdata/data.csv
      key: .[0].firstname

conditions:
  single:
    name: Basic condition query
    kind: csv
    disablesourceinput: true
    spec:
      file: pkg/plugins/resources/csv/testdata/data.csv
      key: .[0].firstname
      value: John

targets:
  single:
    name: Basic target update
    kind: csv
    spec:
      file: pkg/plugins/resources/csv/testdata/data.csv
      key: .[1].firstname
      value: John

  multiple:
    name: Multiple target update
    kind: csv
    spec:
      files:
        - pkg/plugins/resources/csv/testdata/data1.csv
        - pkg/plugins/resources/csv/testdata/data2.csv
      query: .[*].firstname