mirror of
https://github.com/directus/directus.git
synced 2026-01-23 02:18:00 -05:00
* merge components merge args, parser, docs, formatter, help and handlers * change directus command and add auto debug * output format fixes * adds back some reformatted and documented commands * better help output format * refactor all output flow * export cli types * more formatting fixes and param rework * fix table spacing * add yaml formatting and fix string colors * finished formatting docs * remove log * remove package-lock * update dependency versions * fix command description * workaround typescript loading * module loading fixes added command error rename human to table fix disconnect usage * add typescript loader redirect execution to local package if installed locally added command alias `directus-ctl` * fix module load directories * reimplement stdin pipe to work on linux * fix sdk server info type * info command * Fix stdin bug Disable community extensions to discourage use for now Added template to config files Added password stdin to connect to instances Fixed typescript command load * Added command suggestions and QOL features * Linter fixes * Add command hints * Separate positional options * Add back delete many, fix delete one location * Change score logic * Add whoami util command * Add short online docs * Fix typo * Fix typo * Update commands * Param consistency fix and docs update * Create commands * Update package.json version * Update package-lock * Fixed several linting problems * Update dependencies * Update lock * Remove locked dependencies * Stop conflicts when in home directory * Package lock update and npm audit fix * Fix formatting errors * Comment out extending cli section until we figure out cli ext * Update readme * Tweak dev/build/prebuild script naming * Use up to date deps * Fix dependency version in lock (fix build) Co-authored-by: rijkvanzanten <rijkvanzanten@me.com>
135 lines
4.9 KiB
Markdown
135 lines
4.9 KiB
Markdown
# Command Line Interface
|
|
|
|
> Directus has two command line interfaces (CLI) that you can use for various actions. One is used for server-side
|
|
> actions that relate to your on-prem instance, like migrating the database or resetting a user, while the other allows
|
|
> you to interact with a Directus instance as you would with an SDK.
|
|
|
|
[[toc]]
|
|
|
|
## Server
|
|
|
|
For server-side CLI, all functionality can be accessed by running `npx directus <command>` in your project folder.
|
|
|
|
### Initialize a New Project
|
|
|
|
```
|
|
npx directus init
|
|
```
|
|
|
|
Will install the required database driver, and create a `.env` file based on the inputted values.
|
|
|
|
### Bootstrap a Project
|
|
|
|
```
|
|
npx directus bootstrap
|
|
```
|
|
|
|
Will use an existing `.env` file (or existing environment variables) to either install the database (if it's empty) or
|
|
migrate it to the latest version (if it already exists and has missing migrations).
|
|
|
|
This is very useful to use in environments where you're doing standalone automatic deployments, like a multi-container
|
|
Kubernetes configuration, or a similar approach on
|
|
[DigitalOcean App Platform](/guides/installation/digitalocean-app-platform/) or
|
|
[AWS Elastic Beanstalk](/guides/installation/aws/)
|
|
|
|
::: tip First User
|
|
|
|
You can use the `ADMIN_EMAIL` and `ADMIN_PASSWORD` environment variables to automatically provision the first user on
|
|
first creation using the `bootstrap` command. See [Environment Variables](/reference/environment-variables/) for more
|
|
information.
|
|
|
|
:::
|
|
|
|
### Install the Database
|
|
|
|
```
|
|
npx directus database install
|
|
```
|
|
|
|
Installs the Directus system tables on an empty database. Used internally by `bootstrap`
|
|
|
|
### Upgrade the Database
|
|
|
|
```
|
|
npx directus database migrate:latest
|
|
npx directus database migrate:up
|
|
npx directus database migrate:down
|
|
```
|
|
|
|
Migrate the database up/down to match the versions of Directus. Once you update Directus itself, make sure to run
|
|
`npx directus database migrate:latest` (or `npx directus bootstrap`) to update your database.
|
|
|
|
---
|
|
|
|
## Client
|
|
|
|
For the client-side CLI, all functionality can be accessed by running `npx directusctl <command>`. You can also install
|
|
`@directus/cli` on your project dependencies or globally on your machine. Note that if you run `directusctl` (installed
|
|
globally) in a folder containing a project that has a version of `@directus/cli` installed, the running global CLI will
|
|
forward it's execution to the local installed version instead.
|
|
|
|
### Help & Documentation
|
|
|
|
The documentation for all commands can be accessed through the CLI itself. You can list all the available commands
|
|
through `directusctl --help` command. If you want help for a specific command you can use `directusctl <command> --help`
|
|
instead.
|
|
|
|
### Instances
|
|
|
|
Most client-side CLI commands needs a running Directus instance in order to work. To connect the CLI to an instance, you
|
|
can use `directusctl instance connect` command. These instance's configs are going to be saved on `~/.directus` folder.
|
|
|
|
To manage the connected instances, you can use `directusctl instance <command>` commands.
|
|
|
|
#### Selecting instances
|
|
|
|
By default, commands will try using an instance named `default` when executing commands.
|
|
|
|
If you want to change which instance you want to use, either pass `--instance <name>` to the command, or configure
|
|
`instance` variable on your project's Directus config file.
|
|
|
|
For example:
|
|
|
|
> .directus.yml
|
|
|
|
```yml
|
|
instance: my-project
|
|
```
|
|
|
|
### I/O
|
|
|
|
The CLI is designed with ease of use and automation in mind, this means that you can change the way the output is made
|
|
by setting how you want the data to be written to the terminal. We currently support three formats, `table` (the default
|
|
one), `json` and `yaml`.
|
|
|
|
This makes it easier to parse and use data from Directus with other tools like `jq`, `yq`, `grep` or any other tools
|
|
that accepts data from `stdin`
|
|
|
|
It's also worth mentioning that everything is data. Try for example running `directusctl --help --format=json`.
|
|
|
|
#### Table
|
|
|
|
The default output format. This is the "pretty" output, you'll most likely want to use this if you're not dealing with
|
|
data in a way you need to pipe it to another command and/or store it it for parsing.
|
|
|
|
This output will output colors and highlight content if it detects you're running in TTL.
|
|
|
|
#### JSON
|
|
|
|
This format will output JSON notation strings to your terminal. By default if TTY is detected, it will highlight (can be
|
|
turned off with special flags) and prettify the output to make it easier to read.
|
|
|
|
Useful when you need to parse data using tools like `jq` for example.
|
|
|
|
#### YAML
|
|
|
|
This format will output YAML strings to your terminal. By default if TTY is detected, it will highlight (can be turned
|
|
off with special flags) and prettify the output to make it easier to read.
|
|
|
|
Useful when you need to parse data using tools like `jq` for example.
|
|
|
|
<!-- ### Extending
|
|
|
|
To find how you can extend the CLI and write custom commands, check how we make Directus highly extensible on our
|
|
[extensions overview page](/concepts/extensions/). -->
|