Pular para o conteúdo principal

Cognite Data Fusion CLI

Beta

The features described in this section are currently in beta testing and are subject to change.

Use the Cognite Data Fusion (CDF) CLI to manage data models from the command line.

Install the CDF CLI

Prerequisites

To install the CDF CLI, you must first install Node v16 or higher. For more information, see Node JS.

Follow the steps below to install the CDF CLI.

Install the CDF CLI globally

  1. To install the CDF CLI globally, run the following command from a terminal:
npm install --global @cognite/cdf-cli

Install the CDF CLI locally (JavaScript)

  1. To install the CLI locally, run the following command from a terminal:
npm install @cognite/cdf-cli
Installing the CLI globally

You can also install the CLI globally and skip the project setup below with npm install -g @cognite/cdf-cli or yarn global add @cognite/cdf-cli

Use the CDF CLI easily in a javascript project

If you need to use the CLI in your project, add it within the scripts section in your package.json file.

{
"name": "xxx",
...
"scripts":{
...
"cdf": "cdf"
...
}
}

This will allow you to run npm run cdf or yarn cdf within your project.

CDF CLI commands

Usage: cdf [command] [subcommand] [option]

To view available commands, enter cdf --help.

The tables below describe the available commands and options.

CommandAliasDescription
signin [project]loginSign in to Cognite Data Fusion.
data-models [command]dmManage data models to store and retrieve data.
signoutlogoutSign out current user.
statusCheck if current user is signed in.
OptionType, default valueDescription
-v, --verbose[boolean] [default:false]Show debug messages.
--interactive[boolean] [default:true]Request for interactive input if any required field is missing from options.
--version[boolean]Show the version number.
--help[boolean]Show help.

signin

Use the signin command to sign in to a CDF project.

Usage: cdf signin [project]

CommandDescription
signin [project], [p]Specifies the CDF project to sign in to (supports Microsoft Entra ID currently) through interactive login or a client ID and client secret for machines.
OptionType, default valueDescription
-v, --verbose[boolean] [default:false]Show debug messages.
--interactive[boolean] [default:true]Request for interactive input if any required field is missing from options.
--help[boolean]Show help.
--client-id[string]The client ID for the Microsoft Entra ID application.
--client-secret[string]The client secret for the Microsoft Entra ID application generated by the user. Secrets have a long expiry and are suitable for CI/CD.
--tenant[string]The Microsoft Entra ID tenant URI or ID.
--cluster[string] [default:api]The CDF cluster name.
--devicecode[boolean] [default:false]For interactive sign-in, shows a QR code to sign in. This is the recommended method for machines without a web browser.

data-models

Use that data-models command to create, publish, or delete a data model, retrieve data, and generate GraphQL code.

Usage: cdf data-models <command>

CommandAliasDescription
data-models createdm createCreate a data model.
data-models publishdm publishPublish a data model.
data-models generatedm generateGenerate a GraphQL client code for the schema you provide by fetching the introspection query from the server.
data-models deletedm deleteDelete a data model.
data-models listdm listList all data models.
OptionType, default valueDescription
-v, --verbose[boolean] [default:false]Show debug messages.
--interactive[boolean] [default:true]Request for interactive input if any required field is missing from options.
--version[boolean]Show the version number.
--help[boolean]Show help.

data-models create

Use the data-models create command to create a data model in a CDF project.

Usage: cdf data-models create <name>

CommandType, default valueDescription
data-models create [name][string] [required]The name of the data model.
OptionType, default valueDescription
-v, --verbose[boolean] [default:false]Show debug messages.
--interactive[boolean] [default:true]Request for interactive input if any required field is missing from options.
--help[boolean]Show help.
--external-id[string] [default:"name"]The external id of the data model.
--space[string] [default:"external-id"]The space that the data model belongs in. Will create the space if it does not already exist

data-models publish

Use the data-models publish command to update a data model with a new GraphQL definition. If there are any breaking changes, a new version of the data model is published. For non-breaking changes, the existing version of the data model is updated.

Usage: cdf data-models publish

CommandDescription
data-models publishUpdates a data model with a new GraphQL definition.
OptionType, default valueDescription
-v, --verbose[boolean] [default:false]Show debug messages.
--interactive[boolean] [default:true]Request for interactive input if any required field is missing from options.
--help[boolean]Show help.
--external-id[string]The external id of the data model.
--file[string]The file containing the new GraphQL definition.
--space[string] [default:"external-id"]The space that the data model belongs in.
--version[string]Data model version in.
--dry-run[boolean]Perform a dry run. Will only validate the data model without publishing.

data-models delete

Use the data-models delete command to delete the data model in CDF. The command will delete all unreferenced and unused data type within the data model.

Usage: cdf data-models delete

warning

This is an irreversible action!

CommandDescription
data-models deleteDeletes a data model.
OptionType, default valueDescription
-v, --verbose[boolean] [default:false]Show debug messages.
--interactive[boolean] [default:true]Request for interactive input if any required field is missing from options.
--help[boolean]Show help.
--external-id[string]The external id of the data model.
--space[string] [default:"external-id"]The space that the data model belongs in.

data-models list

Use the data-models list command to list all data models in a CDF project.

In the terminal of your choice, enter the command below:

Usage: cdf data-models list

CommandDescription
data-models listLists all data models.
OptionType, default valueDescription
-v, --verbose[boolean] [default:false]Show debug messages.
--interactive[boolean] [default:true]Request for interactive input if any required field is missing from options.
--help[boolean]Show help.

data-models generate

Use the data-models generate command to generate a GraphQL client code for the provided schema by fetching the introspection query from the server.

Usage: cdf data-models generate

CommandDescription
data-models deleteGenerates a GraphQL client code.
OptionType, default valueDescription
-v, --verbose[boolean] [default:false]Show debug messages.
--interactive[boolean] [default:true]Request for interactive input if any required field is missing from options.
--help[boolean]Show help.
--external-id[string]The external id of the data model.
--plugins[array] ["typescript", "typescript-operations", "typescript-resolvers", "typescript-react-apollo", "typescript-apollo-angular"]The code generation plugin. Separate multiple plugins with a space.
--operations-files[string][default:"src/operations.graphql"]The file path to scan for GraphQL code.
--output-file, -f[string] [default:"generated-types.ts"]The file name of the generated code.
--space[string] [default:"external-id"]The space that the data model belongs in.
--version[string]Data model version in.

signout

Use the signout command [alias:logout] to sign out the current user.

Usage: cdf signout

status

Use the status command to check if the current user is signed in.

Usage: cdf status

The output fails if the user isn't signed in.