Description¶
Dataverse command-line interface. It uses the Dataverse API and in some cases direct access to the Dataverse database. The commands are implemented using dans-dataverse-client-lib. Some of the more complex commands are documented below.
Common features of dv dataverse-create-dataset and dv dataset-edit-metadata¶
The commands dv dataverse-create-dataset and dv dataset-edit-metadata work in the same
way: they process one dataset specified on the command line, or a batch of datasets specified in a CSV input file (--input-file, -i), one row per dataset.
This section describes what they have in common; the sections on the individual commands describe their specific columns and options.
Input file and columns¶
The columns of the input file fall into several categories. Which of these apply depends on the command:
- Dataset identifier (
dv dataset-edit-metadataonly) - Preconditions (
dv dataset-edit-metadataonly) - Processing instructions
- Field values
Column names are case-insensitive.
Avoiding conflicts between special columns and fields
If a metadata field has the same name as one of the non-field columns of the command (e.g., pid), prefix the name of the non-field column with *, e.g.,
*pid. The prefix is optional otherwise. If both *pid and pid are present, the first is the special column and the second is a metadata field. Field
names must not start with *. The *result and *message columns in the report always have the * preempting any possible conflicts with
field names.
Field types¶
The names of the field value columns depend on the metadata blocks that are available.
- A primitive field or controlled vocabulary field is specified simply by the field identifier, e.g.,
myField. - If multiple values are to be added, the field identifier is indexed, e.g.,
myField[1].myField[2], etc. - A compound field is specified by the field identifier of the parent field, followed by a dot and the name of the child field, e.g.,
myField.myChildField. Note that in many cases the name of the child field refers to the parent field by convention, e.g.,authorName, but you still have to prefix it with the parent field identifier, e.g.,author.authorName. - If multiple values of a compound field are to be added, the parent field identifier is indexed, e.g.,
myField[1].myChildField,myField[2].myChildField, etc.
Default values¶
Values for the columns can also be given as command line options, which can be combined with --input-file. In that case they provide default values for
the corresponding columns:
- If the CSV file has no column of that name, the command line value is used for every row.
- If the column exists, the command line value is used for the rows where the cell is empty or blank. A non-blank cell always takes precedence.
- If neither a column value nor a command line option is given, the setting is not applied (unless the command defines a default for it).
Field values can have defaults too: <column name>=<value> arguments can be combined with --input-file. They work the same way: a column that is missing
from the CSV file gets the value for every row, and for an existing column the value is used for the rows where the cell is empty or blank. How blank cells in
field columns are interpreted otherwise is specific to the command. Note that you will need to enclose the whole argument in quotes if the value contains
spaces, or if the name has an
index, e.g., 'myField[1]=longer value with spaces'.
Running without CSV input file
Since you can provide defaults for all the columns, it is also possible to run the commands without a CSV input file. This can be useful when testing.
Other options¶
--timeout(for example30s,2m; seconds if no unit is given) is not a column; it applies to the wait for publication of each dataset.--wait-between-rows(same format as--timeout, default no wait; only allowed together with--input-file) is not a column either; it sets the time to wait after each processed row, except the last one, e.g., to throttle the load on the Dataverse instance.--reports-diroverrides the location of the report.
Report¶
When running with a CSV input file, a report will be written to a file in the directory configured in editMetadata.reportsDir in .dv.yml. The
--reports-dir option can be used to override this location. The report contains a copy of each line, with the column names exactly as in the input (so an
optional * is kept or absent as it was), plus the columns for default values that were not in the input file, so that the effective input is visible (blank
cells in the input are filled with the default value), plus the extra columns *result and *message, which always have the *. The columns are ordered as:
identifier (pid, databaseId or datasetId), *result, *message, the processing instruction columns (e.g., *expectedState), and finally the metadata
field columns. When running without a CSV input file, the report is written to the standard output.
The *result column contains one of:
OK: the row was processed successfullyFAILED: an error occurred while processing the rowSKIPPED: the row was skipped because a precondition was not met
dv dataverse-create-dataset¶
Creates one dataset, or a batch of datasets, in a collection. It uses the Create a dataset endpoint. The common features described above apply. Only the metadata blocks enabled for the target collection can be used, and the fields that Dataverse requires must be provided.
Columns¶
alias- the alias of the collection in which to create the dataset. Default: the value of--alias, orrootif that is not specified either. A non-blank cell takes precedence over the command line option.publish- whether to publish the dataset after creation:yes, orno(synonym:leave-draft). Default: the value of--publish, orno. A newly created dataset is always published as version 1.0, so there is no choice of version type.- Any other column is a metadata field value (see Field types).
dv dataset-edit-metadata¶
For bulk changes on the metadata of multiple datasets in a Dataverse instance, you can use dv dataset-edit-metadata. This command uses the
Edit metadata endpoint, which allows you to add or replace metadata fields in a dataset. For typical usage, the command takes a CSV file as
input. The common features described
above apply.
Group rows for the same dataset together where possible, for example to replace and then add values. For consecutive rows, the publication safeguard uses the
state immediately before the first attempted edit since the last confirmed publication. Preconditions are still checked against each row's current state.
Rows may be in any order, but returning to a dataset after another dataset or an unresolvable row starts a new group. If the dataset is then a draft, a requested
publication may be skipped even though the edit succeeds, unless a matching expectedState is explicitly supplied. Check the report for publication-skipped
messages.
This tracking uses constant memory regardless of the number of datasets; input processing, reporting and runtime still depend on batch size and the environment. It assumes stable canonical dataset IDs and does not protect against concurrent writers or ambiguous remote failures.
Columns¶
-
Dataset identifier
datasetId- the database ID or PID of the dataset, a PID must contain the protocol, e.g.,doi:10.5072/FK2/123456pid- the persistent identifier of the dataset, which must start with a protocol label, e.g.,doi:10.5072/FK2/123456databaseId- the database ID of the dataset, consisting of digits only
The input file must contain exactly one of these three columns; they are mutually exclusive. Each row must have a value in that column; there is no default identifier (the
--datasetId,--pidand--databaseIdoptions cannot be used together with an input file). UsepidordatabaseIdinstead ofdatasetIdif you want the identifier to be validated against its expected format. When no input file is used, exactly one of the three options is required. -
Preconditions
expectedState- the expected state of the dataset version to be edited, one ofdraft,released,deacessionedor a negation of one of those, e.g.,not released. The default precondition isnot deaccessioned.expectInReview- whether the dataset is expected to be in review:yesorno. The default is no expectation.=<fieldId>- the expected current value of the field with identifier<fieldId>, e.g.,=title,=subject[2]or=author[1].authorName. Before making any changes, the command checks that the field in the latest version has exactly this value (case-sensitive, surrounding whitespace in the cell ignored). If not, the row is skipped. An empty cell means the field is expected to have no value. For a multivalued field without index, the first value is checked. On the command line, use e.g.=title=Old title.
- Processing instructions
publishVersion- whether to publish the dataset after editing, one ofminor,majororleave-draft(no publication action is attempted) orno(a synonym forleave-draft). N.B. If the dataset was a draft before the first edit attempt in the current group, publication is only attempted ifexpectedStateis explicitly supplied and matches the current state.versionNote- a note to set on the draft version before publication. This involves a separate API call and requires the version note to be enabled in Dataverse. (See Enabling version notes.)replace- whether to replace existing values or add to them:yesorno
- Field values
- An empty cell leaves the field unchanged if
replaceisno, and removes the field's value(s) ifreplaceisyes. - To leave a field unchanged while
replaceisyes, put!skipin the cell. If the value!skipmust literally be stored in a field, choose another skip code with the--skip-codeoption (default!skip).
- An empty cell leaves the field unchanged if