gelx_cli
A command-line interface for
gelxto generate fully typed Rust code from your Gel schema and query files.
Installation
The gelx_cli is distributed as part of the gelx workspace. To use it, you can build the workspace and then run the gelx binary from the target directory, or install it using cargo:
Alternatively, you can install it directly from the github repo:
The above two commands are the typical ways to install gelx_cli. However, if you use gel in multiple projects with multiple versions of the gelx crate, you should install it locally per project using cargo-run-bin.
First install cargo-run-bin:
Inside a single crate project add the following to the Cargo.toml file:
[]
= { = "0.7.0", = ["gelx"] }
Inside a workspace add the following to the Cargo.toml file:
[]
= { = "0.7.0", = ["gelx"] }
Then run the following command to access gelx:
Ensure your Gel instance is running and accessible, as the CLI needs to connect to it to introspect the schema and query types.
Run gelx help to see the available commands and options.
)
Global Options
--cwd <path>: Specifies a working directory to run the command from. If provided,gelxwill change to this directory before performing any operations. This is useful if you are invokinggelxfrom a directory different from your project's root.
Usage
The gelx CLI tool generates Rust code from .edgeql files located in your project. It reads configuration from your crate's Cargo.toml file, specifically under the [package.metadata.gelx] section.
Commands
gelx generate
This command generates Rust code based on your .edgeql query files and the Gel schema.
Or run the command with the --json flag to print the generated code to the terminal as JSON:
The CLI will:
- Read configuration from
[package.metadata.gelx]in yourCargo.toml. - Scan the directory specified by
queries(default:./queries) for.edgeqlfiles. - Connect to your Gel instance to get type information for each query.
- Generate corresponding Rust modules.
- If
--jsonis used, print the combined code to the terminal as JSON. - Otherwise, write the combined code to the folder specified by
output_path(default:./src/db).
gelx check
This command verifies if the currently generated code is up-to-date with your schema and query files. It's useful for CI pipelines to ensure that code generation has been run after any changes.
The CLI will:
- Perform the same generation process as
gelx generatein memory. - Compare the newly generated code with the content of the existing
output_file. - If they match, it will exit successfully (status code 0).
- If they differ, it will print an error message and exit with a non-zero status code, indicating that
gelx generateneeds to be run.
Configuration
The gelx CLI reads its configuration from the Cargo.toml file of the crate it is being run in. The configuration should be placed under the [package.metadata.gelx] table.
Refer to the main gelx crate readme.md for all the configuration options.
Contributing
This crate is part of the gelx workspace. Please refer to the main project's contributing guide for details on how to set up the development environment and contribute.
License
Unlicense, see the license file in the root of the workspace.