CSV

kind: csv

sourceconditiontarget

Description

source

The CSV "source" retrieves an information from a CSV file.

condition

The CSV "condition" tests that an information exist in a CSV file.

target

The CSV "target" ensures that a CSV file content a specific value at specific location.

Parameters

NameTypeDescriptionRequired
commainteger[s][c][t] Comma specifies the csv separator character, default “,”
commentinteger[s][c][t] Comma specifies the csv comment character, default “#”
filestring[s][c][t] File specifies the csv file
filesarray[c][t] Files specifies a list of Json file to manipulate
keystring[s][c][t] Key specifies the csv query
querystring[s][c][t] Query allows to used advanced query. Override the parameter key
valuestring[s][c][t] Key specifies the csv value, default to source output
versionfilterobject[s]VersionFilter provides parameters to specify version pattern and its type like regex, semver, or just latest.
    kindstringspecifies the version kind such as semver, regex, or latest
    patternstringspecifies the version pattern according the version kind
    strictbooleanstrict enforce strict versioning rule. Only used for semantic versioning at this time

Query

The csv resource benefits from the Dasel library https://daseldocs.tomwright.me/

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

Important

The library used to manipulate CSV files, drops comments. More information is available on tomwright/dasel#178. Until we find a solution, a potential workaround is to use the resource file like in the following example:

Top