Neon CLI commands — set-context
Use the Neon CLI to manage Neon directly from the terminal
Before you begin
- Before running the
set-context
command, ensure that you have installed the Neon CLI. - If you have not authenticated with the neon auth command, running a Neon CLI command automatically launches the Neon CLI browser authentication process. Alternatively, you can specify a Neon API key using the
--api-key
option when running a command. See Connect.
set-context
command
The This command sets a background context for your CLI sessions, letting you perform project or branch-specific actions without having to specify the project id in every command. Using the context-file
parameter, you can save the context to a file of your choice. If you don't specify a file, a default .neon
file is saved to the current directory. You can switch contexts by providing different files.
The context remains in place until you reset to a new context or remove the context-file
.
Usage
set-context (hidden file)
set-context to context-file
set-context during project creation
You can also set context for a new project during project creation.
Options
The set-context
command requires you set at least one of these options:
Option | Description | Type | Required |
---|---|---|---|
--project-id | Project ID | string | Sets the identified project as the context until you reset or remove context-file |
--context-file | path and file name | string | Creates a file that holds project-id and branch context |
Global options are also supported.
Examples of setting and using a context
Here are some examples of setting contexts to specific projects, then using them in an example command.
Using the default file
Set the context to the default .neon
file:
List all branches for this project using branches list
. You do not need to include --project-id
even though multiple projects exist for this account:
The results show details for all branches in the patient-frost-50125040
project:
context-file
Using a named Set the context to the context-file
of your choice:
List all branches using the branches list
command. No need to specify the project since the context file provides it.
The results show details for all branches in the plain-waterfall-84865553
project:
note
These two branches list
commands demonstrate the use of different contexts in the same account. The default .neon
context is set to patient-frost-50125040
while the named context-file
is set to plain-waterfall-84865553
. These contexts operate independently. You can set as many context-files
as you'd like, using unique names or in different directories, depending on your needs.
Setting context when creating a new project
Let's say you want to create a new project called MyLatest
. You can automatically set the project ID at the same time as you create the project.
This creates a hidden .neon
file by default with the following context:
You can now use any command that would normally require an additional --project-id
parameter and the command will default to this context.
note
Neon does not save any confidential information to the context file (for example, auth tokens). You can safely commit this file to your repository or share with others.
Last updated on