import{r as i,p as r,q as d,w as n,z as e,t as s,R as t}from"./vendor.3d5b4206.js";const h={class:"markdown-body"},u=e("blockquote",null,[e("p",null,"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.")],-1),p=e("p",null,[e("div",{class:"table-of-contents"},[e("ul",null,[e("li",null,[e("a",{href:"#server"},"Server")]),e("li",null,[e("a",{href:"#client"},"Client")])])])],-1),_=e("h2",{id:"server"},[t("Server "),e("a",{class:"header-anchor",href:"#server"},"#")],-1),m=e("p",null,[t("For server-side CLI, all functionality can be accessed by running "),e("code",null,"npx directus <command>"),t(" in your project folder.")],-1),f=e("h3",{id:"initialize-a-new-project"},[t("Initialize a New Project "),e("a",{class:"header-anchor",href:"#initialize-a-new-project"},"#")],-1),g=e("pre",null,[e("code",null,`npx directus init
`)],-1),y=e("p",null,[t("Will install the required database driver, and create a "),e("code",null,".env"),t(" file based on the inputted values.")],-1),w=e("h3",{id:"bootstrap-a-project"},[t("Bootstrap a Project "),e("a",{class:"header-anchor",href:"#bootstrap-a-project"},"#")],-1),b=e("pre",null,[e("code",null,`npx directus bootstrap
`)],-1),v=e("p",null,[t("Will use an existing "),e("code",null,".env"),t(" file (or existing environment variables) to either install the database (if it\u2019s empty) or migrate it to the latest version (if it already exists and has missing migrations).")],-1),x=t("This is very useful to use in environments where you\u2019re doing standalone automatic deployments, like a multi-container Kubernetes configuration, or a similar approach on "),T=t("DigitalOcean App Platform"),k=t(", "),I=t("Google Cloud Platform"),D=t(" or "),j=t("AWS Elastic Beanstalk"),C={class:"tip hint"},S=e("div",{class:"hint-title"},"First User",-1),A=t("You can use the "),L=e("code",null,"ADMIN_EMAIL",-1),q=t(" and "),Y=e("code",null,"ADMIN_PASSWORD",-1),M=t(" environment variables to automatically provision the first user on first creation using the "),N=e("code",null,"bootstrap",-1),B=t(" command. See "),U=t("Environment Variables"),O=t(" for more information."),W=e("div",{class:"tip hint"},[e("div",{class:"hint-title"},"Skip Admin User/Role"),e("p",null,[t("You can pass the "),e("code",null,"--skipAdminInit"),t(" option to "),e("code",null,"bootstrap"),t(", if you\u2019re creating your Admin role/user in another way (with a custom migration or an external service, for example).")])],-1),F=e("h3",{id:"install-the-database"},[t("Install the Database "),e("a",{class:"header-anchor",href:"#install-the-database"},"#")],-1),P=e("pre",null,[e("code",null,`npx directus database install
`)],-1),E=e("p",null,[t("Installs the initial Directus system tables on an empty database. Used internally by "),e("code",null,"bootstrap"),t(".")],-1),z=e("p",null,[t("It should be used only in specific cases, e.g. when you want to run something between "),e("code",null,"install"),t(" and "),e("code",null,"migrate"),t(". You probably should call "),e("code",null,"directus database migrate:latest"),t(" afterwards manually.")],-1),R=e("p",null,[t("You may want to use "),e("code",null,"directus bootstrap"),t(" instead.")],-1),V=e("h3",{id:"upgrade-the-database"},[t("Upgrade the Database "),e("a",{class:"header-anchor",href:"#upgrade-the-database"},"#")],-1),J=e("pre",null,[e("code",null,`npx directus database migrate:latest
npx directus database migrate:up
npx directus database migrate:down
`)],-1),K=e("p",null,[t("Migrate the database up/down to match the versions of Directus. Once you update Directus itself, make sure to run "),e("code",null,"npx directus database migrate:latest"),t(" (or "),e("code",null,"npx directus bootstrap"),t(") to update your database.")],-1),G=e("h3",{id:"migrate-schema-to-a-different-environment"},[t("Migrate Schema to a different Environment "),e("a",{class:"header-anchor",href:"#migrate-schema-to-a-different-environment"},"#")],-1),H=e("p",null,"To move your configured data model between Directus instances, you can use the schema \u201Csnapshot\u201D and \u201Capply\u201D commands.",-1),Q=e("h4",{id:"snapshot-the-data-model"},[t("Snapshot the Data Model "),e("a",{class:"header-anchor",href:"#snapshot-the-data-model"},"#")],-1),X=e("p",null,"Directus can automatically generate a snapshot of your current data model in YAML or JSON format. This includes all collections, fields, and relations, and their configuration. This snapshot can be checked in version control and shared with your team. To generate the snapshot, run",-1),Z=e("pre",null,[e("code",null,`npx directus schema snapshot ./snapshot.yaml
`)],-1),$=e("h4",{id:"applying-a-snapshot"},[t("Applying a Snapshot "),e("a",{class:"header-anchor",href:"#applying-a-snapshot"},"#")],-1),ee=e("p",null,"To make a different instance up to date with the latest changes in your data model, you can apply the snapshot. By applying the snapshot, Directus will auto-detect the changes required to make the current instance up to date with the proposed data model in the snapshot file, and will run the required migrations to the database to make it match the snapshot.",-1),te=e("p",null,"To apply the generated snapshot, run",-1),ne=e("pre",null,[e("code",null,`npx directus schema apply ./path/to/snapshot.yaml
`)],-1),oe=e("h3",{id:"creating-users"},[t("Creating Users "),e("a",{class:"header-anchor",href:"#creating-users"},"#")],-1),se=e("p",null,"To create a new user with a specific role, run",-1),ae=e("pre",null,[e("code",null,`npx directus users create --email <user-email> --password <password> --role <role-uuid>
`)],-1),ie=e("h4",{id:"updating-user-password"},[t("Updating User Password "),e("a",{class:"header-anchor",href:"#updating-user-password"},"#")],-1),le=e("p",null,"To update the password of an existing user, run",-1),ce=e("pre",null,[e("code",null,`npx directus users passwd --email <user-email> --password <new-password>
`)],-1),re=e("h3",{id:"creating-roles"},[t("Creating Roles "),e("a",{class:"header-anchor",href:"#creating-roles"},"#")],-1),de=e("p",null,"To create a new role, run",-1),he=e("pre",null,[e("code",null,`npx directus roles create --role <role-name>
`)],-1),ue=t("These roles are created with the "),pe=t("minimum permissions required"),_e=t(" to properly access the App by default."),me=e("p",null,[t("To create a new role with admin access, set the "),e("code",null,"--admin"),t(" flag to "),e("code",null,"true"),t(", such as")],-1),fe=e("pre",null,[e("code",null,`npx directus roles create --role <role-name> --admin true
`)],-1),ge=e("h3",{id:"count-items-in-a-collection"},[t("Count Items in a Collection "),e("a",{class:"header-anchor",href:"#count-items-in-a-collection"},"#")],-1),ye=e("p",null,"To count the amount of items in a given collection, run",-1),we=e("pre",null,[e("code",null,`npx directus count <collection-name>
`)],-1),be=e("hr",null,null,-1),ve=e("h2",{id:"client"},[t("Client "),e("a",{class:"header-anchor",href:"#client"},"#")],-1),xe=e("p",null,[t("For the client-side CLI, all functionality can be accessed by running "),e("code",null,"npx directusctl <command>"),t(". You can also install "),e("code",null,"@directus/cli"),t(" on your project dependencies or globally on your machine. Note that if you run "),e("code",null,"directusctl"),t(" (installed globally) in a folder containing a project that has a version of "),e("code",null,"@directus/cli"),t(" installed, the running global CLI will forward it\u2019s execution to the local installed version instead.")],-1),Te=e("h3",{id:"help-%26-documentation"},[t("Help & Documentation "),e("a",{class:"header-anchor",href:"#help-%26-documentation"},"#")],-1),ke=e("p",null,[t("The documentation for all commands can be accessed through the CLI itself. You can list all the available commands through "),e("code",null,"directusctl --help"),t(" command. If you want help for a specific command you can use "),e("code",null,"directusctl <command> --help"),t(" instead.")],-1),Ie=e("h3",{id:"instances"},[t("Instances "),e("a",{class:"header-anchor",href:"#instances"},"#")],-1),De=e("p",null,[t("Most client-side CLI commands needs a running Directus instance in order to work. To connect the CLI to an instance, you can use "),e("code",null,"directusctl instance connect"),t(" command. These instance\u2019s configs are going to be saved on "),e("code",null,"~/.directus"),t(" folder.")],-1),je=e("p",null,[t("To manage the connected instances, you can use "),e("code",null,"directusctl instance <command>"),t(" commands.")],-1),Ce=e("h4",{id:"selecting-instances"},[t("Selecting instances "),e("a",{class:"header-anchor",href:"#selecting-instances"},"#")],-1),Se=e("p",null,[t("By default, commands will try using an instance named "),e("code",null,"default"),t(" when executing commands.")],-1),Ae=e("p",null,[t("If you want to change which instance you want to use, either pass "),e("code",null,"--instance <name>"),t(" to the command, or configure "),e("code",null,"instance"),t(" variable on your project\u2019s Directus config file.")],-1),Le=e("p",null,"For example:",-1),qe=e("blockquote",null,[e("p",null,".directus.yml")],-1),Ye=e("pre",null,[e("code",{class:"language-yml"},[e("span",{class:"hljs-attr"},"instance:"),t(),e("span",{class:"hljs-string"},"my-project"),t(`
`)])],-1),Me=e("h3",{id:"i%2Fo"},[t("I/O "),e("a",{class:"header-anchor",href:"#i%2Fo"},"#")],-1),Ne=e("p",null,[t("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, "),e("code",null,"table"),t(" (the default one), "),e("code",null,"json"),t(" and "),e("code",null,"yaml"),t(".")],-1),Be=e("p",null,[t("This makes it easier to parse and use data from Directus with other tools like "),e("code",null,"jq"),t(", "),e("code",null,"yq"),t(", "),e("code",null,"grep"),t(" or any other tools that accepts data from "),e("code",null,"stdin")],-1),Ue=e("p",null,[t("It\u2019s also worth mentioning that everything is data. Try for example running "),e("code",null,"directusctl --help --format=json"),t(".")],-1),Oe=e("h4",{id:"table"},[t("Table "),e("a",{class:"header-anchor",href:"#table"},"#")],-1),We=e("p",null,"The default output format. This is the \u201Cpretty\u201D output, you\u2019ll most likely want to use this if you\u2019re not dealing with data in a way you need to pipe it to another command and/or store it for parsing.",-1),Fe=e("p",null,"This output will output colors and highlight content if it detects you\u2019re running in TTL.",-1),Pe=e("h4",{id:"json"},[t("JSON "),e("a",{class:"header-anchor",href:"#json"},"#")],-1),Ee=e("p",null,"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.",-1),ze=e("p",null,[t("Useful when you need to parse data using tools like "),e("code",null,"jq"),t(" for example.")],-1),Re=e("h4",{id:"yaml"},[t("YAML "),e("a",{class:"header-anchor",href:"#yaml"},"#")],-1),Ve=e("p",null,"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.",-1),Je=e("p",null,[t("Useful when you need to parse data using tools like "),e("code",null,"jq"),t(" for example.")],-1),Xe={setup(Ke,{expose:l}){const a={title:"Command Line Interface",modularExtension:!1};return l({frontmatter:a}),(Ge,He)=>{const o=i("router-link"),c=i("DocsWrapper");return r(),d(c,{frontmatter:a},{default:n(()=>[e("div",h,[u,p,_,m,f,g,y,w,b,v,e("p",null,[x,s(o,{to:"/docs/getting-started/installation/digitalocean-app-platform/"},{default:n(()=>[T]),_:1}),k,s(o,{to:"/docs/getting-started/installation/gcp"},{default:n(()=>[I]),_:1}),D,s(o,{to:"/docs/getting-started/installation/aws"},{default:n(()=>[j]),_:1})]),e("div",C,[S,e("p",null,[A,L,q,Y,M,N,B,s(o,{to:"/docs/configuration/config-options/#general"},{default:n(()=>[U]),_:1}),O])]),W,F,P,E,z,R,V,J,K,G,H,Q,X,Z,$,ee,te,ne,oe,se,ae,ie,le,ce,re,de,he,e("p",null,[ue,s(o,{to:"/docs/configuration/users-roles-permissions/#configuring-system-permissions"},{default:n(()=>[pe]),_:1}),_e]),me,fe,ge,ye,we,be,ve,xe,Te,ke,Ie,De,je,Ce,Se,Ae,Le,qe,Ye,Me,Ne,Be,Ue,Oe,We,Fe,Pe,Ee,ze,Re,Ve,Je])]),_:1})}}};export{Xe as default};
